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

          Line data    Source code
       1             : // Copyright (C) 2016 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 java.util.stream.Collectors.toList;
      18             : 
      19             : import com.google.gerrit.entities.Account;
      20             : import com.google.gerrit.entities.SubmitRecord;
      21             : import com.google.gerrit.index.query.Predicate;
      22             : import com.google.gerrit.server.index.change.ChangeField;
      23             : import java.util.Set;
      24             : 
      25             : public class SubmitRecordPredicate extends ChangeIndexPredicate {
      26             :   public static Predicate<ChangeData> create(
      27             :       String label, SubmitRecord.Label.Status status, Set<Account.Id> accounts) {
      28           5 :     String lowerLabel = label.toLowerCase();
      29           5 :     if (accounts == null || accounts.isEmpty()) {
      30           5 :       return new SubmitRecordPredicate(status.name() + ',' + lowerLabel);
      31             :     }
      32           4 :     return Predicate.or(
      33           4 :         accounts.stream()
      34           4 :             .map(a -> new SubmitRecordPredicate(status.name() + ',' + lowerLabel + ',' + a.get()))
      35           4 :             .collect(toList()));
      36             :   }
      37             : 
      38             :   private SubmitRecordPredicate(String value) {
      39           5 :     super(ChangeField.SUBMIT_RECORD, value);
      40           5 :   }
      41             : 
      42             :   @Override
      43             :   public boolean match(ChangeData in) {
      44           3 :     return ChangeField.formatSubmitRecordValues(in).contains(getValue());
      45             :   }
      46             : }

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