KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > filters > IntRangeFilter


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 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 Integer JavaDoc mLowerBound;
32
33     /** upper bound of the range */
34     private Integer JavaDoc 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     {
44         mLowerBound = new Integer JavaDoc(aLowerBound);
45         mUpperBound = new Integer JavaDoc(aUpperBound);
46     }
47
48     /** {@inheritDoc} */
49     public boolean accept(Integer JavaDoc aInt)
50     {
51         return ((mLowerBound.compareTo(aInt) <= 0)
52             && (mUpperBound.compareTo(aInt) >= 0));
53     }
54
55     /** {@inheritDoc} */
56     public int hashCode()
57     {
58         return HASH_MULT * mLowerBound.intValue() + mUpperBound.intValue();
59     }
60
61     /** {@inheritDoc} */
62     public boolean equals(Object JavaDoc aObject)
63     {
64         if (aObject instanceof IntRangeFilter) {
65             final IntRangeFilter other = (IntRangeFilter) aObject;
66             return (this.mLowerBound.equals(other.mLowerBound)
67                 && this.mUpperBound.equals(other.mUpperBound));
68         }
69         return false;
70     }
71     /** {@inheritDoc} */
72     public String JavaDoc toString()
73     {
74         return "IntRangeFilter[" + mLowerBound + "," + mUpperBound + "]";
75     }
76
77 }
78
Popular Tags