Line data Source code
1 : // Copyright (C) 2021 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.query.approval; 16 : 17 : import com.google.gerrit.extensions.client.ChangeKind; 18 : import com.google.gerrit.index.query.Predicate; 19 : import java.util.Collection; 20 : import java.util.Objects; 21 : 22 : /** 23 : * Predicate that matches patch set approvals we want to copy if the diff between the old and new 24 : * patch set is of a certain kind. 25 : */ 26 : public class ChangeKindPredicate extends ApprovalPredicate { 27 : private final ChangeKind changeKind; 28 : 29 12 : ChangeKindPredicate(ChangeKind changeKind) { 30 12 : this.changeKind = changeKind; 31 12 : } 32 : 33 : @Override 34 : public boolean match(ApprovalContext ctx) { 35 12 : return ctx.changeKind().matches(changeKind, ctx.isMerge()); 36 : } 37 : 38 : @Override 39 : public Predicate<ApprovalContext> copy( 40 : Collection<? extends Predicate<ApprovalContext>> children) { 41 0 : return new ChangeKindPredicate(changeKind); 42 : } 43 : 44 : @Override 45 : public int hashCode() { 46 0 : return Objects.hash(changeKind); 47 : } 48 : 49 : @Override 50 : public boolean equals(Object other) { 51 0 : if (!(other instanceof ChangeKindPredicate)) { 52 0 : return false; 53 : } 54 0 : return ((ChangeKindPredicate) other).changeKind.equals(changeKind); 55 : } 56 : }