LCOV - code coverage report
Current view: top level - server/query/change - ReviewerPredicate.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 10 11 90.9 %
Date: 2022-11-19 15:00:39 Functions: 6 7 85.7 %

          Line data    Source code
       1             : // Copyright (C) 2010 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.Account;
      20             : import com.google.gerrit.index.query.HasCardinality;
      21             : import com.google.gerrit.index.query.Predicate;
      22             : import com.google.gerrit.server.index.change.ChangeField;
      23             : import com.google.gerrit.server.notedb.ReviewerStateInternal;
      24             : 
      25             : public class ReviewerPredicate extends ChangeIndexPredicate implements HasCardinality {
      26             :   protected static Predicate<ChangeData> forState(Account.Id id, ReviewerStateInternal state) {
      27           6 :     checkArgument(state != ReviewerStateInternal.REMOVED, "can't query by removed reviewer");
      28           6 :     return new ReviewerPredicate(state, id);
      29             :   }
      30             : 
      31             :   protected static Predicate<ChangeData> reviewer(Account.Id id) {
      32           4 :     return new ReviewerPredicate(ReviewerStateInternal.REVIEWER, id);
      33             :   }
      34             : 
      35             :   protected static Predicate<ChangeData> cc(Account.Id id) {
      36           4 :     return new ReviewerPredicate(ReviewerStateInternal.CC, id);
      37             :   }
      38             : 
      39             :   protected final ReviewerStateInternal state;
      40             :   protected final Account.Id id;
      41             : 
      42             :   private ReviewerPredicate(ReviewerStateInternal state, Account.Id id) {
      43           6 :     super(ChangeField.REVIEWER_SPEC, ChangeField.getReviewerFieldValue(state, id));
      44           6 :     this.state = state;
      45           6 :     this.id = id;
      46           6 :   }
      47             : 
      48             :   protected Account.Id getAccountId() {
      49           0 :     return id;
      50             :   }
      51             : 
      52             :   @Override
      53             :   public boolean match(ChangeData cd) {
      54           3 :     return cd.reviewers().asTable().get(state, id) != null;
      55             :   }
      56             : 
      57             :   @Override
      58             :   public int getCardinality() {
      59           2 :     return 5000;
      60             :   }
      61             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750