LCOV - code coverage report
Current view: top level - server/query/change - AndChangeSource.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 7 14 50.0 %
Date: 2022-11-19 15:00:39 Functions: 3 5 60.0 %

          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 com.google.gerrit.index.IndexConfig;
      18             : import com.google.gerrit.index.query.AndSource;
      19             : import com.google.gerrit.index.query.IsVisibleToPredicate;
      20             : import com.google.gerrit.index.query.Predicate;
      21             : import java.util.Collection;
      22             : import java.util.List;
      23             : 
      24             : public class AndChangeSource extends AndSource<ChangeData> implements ChangeDataSource {
      25             : 
      26             :   public AndChangeSource(Collection<Predicate<ChangeData>> that, IndexConfig indexConfig) {
      27          10 :     super(that, indexConfig);
      28          10 :   }
      29             : 
      30             :   public AndChangeSource(
      31             :       Predicate<ChangeData> that,
      32             :       IsVisibleToPredicate<ChangeData> isVisibleToPredicate,
      33             :       int start,
      34             :       IndexConfig indexConfig) {
      35         103 :     super(that, isVisibleToPredicate, start, indexConfig);
      36         103 :   }
      37             : 
      38             :   @Override
      39             :   public boolean hasChange() {
      40           0 :     return source instanceof ChangeDataSource && ((ChangeDataSource) source).hasChange();
      41             :   }
      42             : 
      43             :   @Override
      44             :   protected List<ChangeData> transformBuffer(List<ChangeData> buffer) {
      45           0 :     if (!hasChange()) {
      46           0 :       ChangeData.ensureChangeLoaded(buffer);
      47             :     }
      48           0 :     return super.transformBuffer(buffer);
      49             :   }
      50             : 
      51             :   @Override
      52             :   public int compare(Predicate<ChangeData> a, Predicate<ChangeData> b) {
      53          10 :     int cmp = super.compare(a, b);
      54          10 :     if (cmp == 0 && a instanceof ChangeDataSource && b instanceof ChangeDataSource) {
      55           0 :       ChangeDataSource as = (ChangeDataSource) a;
      56           0 :       ChangeDataSource bs = (ChangeDataSource) b;
      57           0 :       cmp = (as.hasChange() ? 0 : 1) - (bs.hasChange() ? 0 : 1);
      58             :     }
      59          10 :     return cmp;
      60             :   }
      61             : }

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