Line data Source code
1 : // Copyright (C) 2017 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.change; 16 : 17 : import static com.google.common.base.Preconditions.checkArgument; 18 : 19 : import com.google.gerrit.entities.Address; 20 : import com.google.gerrit.index.query.Predicate; 21 : import com.google.gerrit.server.index.change.ChangeField; 22 : import com.google.gerrit.server.notedb.ReviewerStateInternal; 23 : 24 : class ReviewerByEmailPredicate extends ChangeIndexPredicate { 25 : 26 : static Predicate<ChangeData> forState(Address adr, ReviewerStateInternal state) { 27 6 : checkArgument(state != ReviewerStateInternal.REMOVED, "can't query by removed reviewer"); 28 6 : return new ReviewerByEmailPredicate(state, adr); 29 : } 30 : 31 : private final ReviewerStateInternal state; 32 : private final Address adr; 33 : 34 : private ReviewerByEmailPredicate(ReviewerStateInternal state, Address adr) { 35 6 : super(ChangeField.REVIEWER_BY_EMAIL, ChangeField.getReviewerByEmailFieldValue(state, adr)); 36 6 : this.state = state; 37 6 : this.adr = adr; 38 6 : } 39 : 40 : Address getAddress() { 41 0 : return adr; 42 : } 43 : 44 : @Override 45 : public boolean match(ChangeData cd) { 46 3 : return cd.reviewersByEmail().asTable().get(state, adr) != null; 47 : } 48 : }