Coverage Report - com.puppycrawl.tools.checkstyle.filters.IntRangeFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
IntRangeFilter
90%
10/11
100%
10/10
1.8
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2014  Oliver Burn
 4  
 //
 5  
 // This library is free software; you can redistribute it and/or
 6  
 // modify it under the terms of the GNU Lesser General Public
 7  
 // License as published by the Free Software Foundation; either
 8  
 // version 2.1 of the License, or (at your option) any later version.
 9  
 //
 10  
 // This library is distributed in the hope that it will be useful,
 11  
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 // Lesser General Public License for more details.
 14  
 //
 15  
 // You should have received a copy of the GNU Lesser General Public
 16  
 // License along with this library; if not, write to the Free Software
 17  
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 ////////////////////////////////////////////////////////////////////////////////
 19  
 package com.puppycrawl.tools.checkstyle.filters;
 20  
 
 21  
 /**
 22  
  * This filter accepts an Integer in a range.
 23  
  * @author Rick Giles
 24  
  */
 25  
 class IntRangeFilter implements IntFilter
 26  
 {
 27  
     /** hash function multiplicand */
 28  
     private static final int HASH_MULT = 29;
 29  
 
 30  
     /** lower bound of the range */
 31  
     private final Integer mLowerBound;
 32  
 
 33  
     /** upper bound of the range */
 34  
     private final Integer mUpperBound;
 35  
 
 36  
     /**
 37  
      * Constructs a <code>IntRangeFilter</code> with a
 38  
      * lower bound and an upper bound for the range.
 39  
      * @param aLowerBound the lower bound of the range.
 40  
      * @param aUpperBound the upper bound of the range.
 41  
      */
 42  
     public IntRangeFilter(int aLowerBound, int aUpperBound)
 43  28
     {
 44  28
         mLowerBound = aLowerBound;
 45  28
         mUpperBound = aUpperBound;
 46  28
     }
 47  
 
 48  
     /** {@inheritDoc} */
 49  
     public boolean accept(int aInt)
 50  
     {
 51  34
         return ((mLowerBound.compareTo(aInt) <= 0)
 52  
             && (mUpperBound.compareTo(aInt) >= 0));
 53  
     }
 54  
 
 55  
     @Override
 56  
     public int hashCode()
 57  
     {
 58  27
         return HASH_MULT * mLowerBound.intValue() + mUpperBound.intValue();
 59  
     }
 60  
 
 61  
     @Override
 62  
     public boolean equals(Object aObject)
 63  
     {
 64  11
         if (aObject instanceof IntRangeFilter) {
 65  9
             final IntRangeFilter other = (IntRangeFilter) aObject;
 66  9
             return (this.mLowerBound.equals(other.mLowerBound)
 67  
                 && this.mUpperBound.equals(other.mUpperBound));
 68  
         }
 69  2
         return false;
 70  
     }
 71  
 
 72  
     @Override
 73  
     public String toString()
 74  
     {
 75  0
         return "IntRangeFilter[" + mLowerBound + "," + mUpperBound + "]";
 76  
     }
 77  
 
 78  
 }