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

          Line data    Source code
       1             : // Copyright (C) 2014 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.index.query;
      16             : 
      17             : import com.google.gerrit.common.Nullable;
      18             : 
      19             : public class LimitPredicate<T> extends IntPredicate<T> implements Matchable<T> {
      20             :   @SuppressWarnings("unchecked")
      21             :   @Nullable
      22             :   public static Integer getLimit(String fieldName, Predicate<?> p) {
      23         151 :     IntPredicate<?> ip = QueryBuilder.find(p, IntPredicate.class, fieldName);
      24         151 :     return ip != null ? ip.intValue() : null;
      25             :   }
      26             : 
      27             :   public LimitPredicate(String fieldName, int limit) throws QueryParseException {
      28           6 :     super(fieldName, limit);
      29           6 :     if (limit <= 0) {
      30           0 :       throw new QueryParseException("limit must be positive: " + limit);
      31             :     }
      32           6 :   }
      33             : 
      34             :   @Override
      35             :   public boolean match(T object) {
      36           5 :     return true;
      37             :   }
      38             : 
      39             :   @Override
      40             :   public int getCost() {
      41           6 :     return 0;
      42             :   }
      43             : }

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