LCOV - code coverage report
Current view: top level - index/query - IntPredicate.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 9 15 60.0 %
Date: 2022-11-19 15:00:39 Functions: 4 6 66.7 %

          Line data    Source code
       1             : // Copyright (C) 2009 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             : /** Predicate to filter a field by matching integer value. */
      18             : public abstract class IntPredicate<T> extends OperatorPredicate<T> {
      19             :   private final int intValue;
      20             : 
      21             :   public IntPredicate(String name, String value) {
      22           0 :     super(name, value);
      23           0 :     this.intValue = Integer.parseInt(value);
      24           0 :   }
      25             : 
      26             :   public IntPredicate(String name, int intValue) {
      27           6 :     super(name, String.valueOf(intValue));
      28           6 :     this.intValue = intValue;
      29           6 :   }
      30             : 
      31             :   public int intValue() {
      32           6 :     return intValue;
      33             :   }
      34             : 
      35             :   @Override
      36             :   public int hashCode() {
      37           0 :     return getOperator().hashCode() * 31 + intValue;
      38             :   }
      39             : 
      40             :   // Suppress the EqualsGetClass warning as this is legacy code.
      41             :   @SuppressWarnings("EqualsGetClass")
      42             :   @Override
      43             :   public boolean equals(Object other) {
      44           1 :     if (other == null) {
      45           0 :       return false;
      46             :     }
      47           1 :     if (getClass() == other.getClass()) {
      48           1 :       final IntPredicate<?> p = (IntPredicate<?>) other;
      49           1 :       return getOperator().equals(p.getOperator()) && intValue() == p.intValue();
      50             :     }
      51           0 :     return false;
      52             :   }
      53             : 
      54             :   @Override
      55             :   public String toString() {
      56           4 :     return getOperator() + ":" + getValue();
      57             :   }
      58             : }

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