KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > mail > search > IntegerComparisonTerm


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)IntegerComparisonTerm.java 1.8 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.mail.search;
29
30 /**
31  * This class implements comparisons for integers.
32  *
33  * @author Bill Shannon
34  * @author John Mani
35  */

36 public abstract class IntegerComparisonTerm extends ComparisonTerm JavaDoc {
37     /**
38      * The number.
39      *
40      * @serial
41      */

42     protected int number;
43
44     private static final long serialVersionUID = -6963571240154302484L;
45
46     protected IntegerComparisonTerm(int comparison, int number) {
47     this.comparison = comparison;
48     this.number = number;
49     }
50
51     /**
52      * Return the number to compare with.
53      */

54     public int getNumber() {
55     return number;
56     }
57
58     /**
59      * Return the type of comparison.
60      */

61     public int getComparison() {
62     return comparison;
63     }
64
65     protected boolean match(int i) {
66     switch (comparison) {
67         case LE:
68         return i <= number;
69         case LT:
70         return i < number;
71         case EQ:
72         return i == number;
73         case NE:
74         return i != number;
75         case GT:
76         return i > number;
77         case GE:
78         return i >= number;
79         default:
80         return false;
81     }
82     }
83
84     /**
85      * Equality comparison.
86      */

87     public boolean equals(Object JavaDoc obj) {
88     if (!(obj instanceof IntegerComparisonTerm JavaDoc))
89         return false;
90     IntegerComparisonTerm JavaDoc ict = (IntegerComparisonTerm JavaDoc)obj;
91     return ict.number == this.number && super.equals(obj);
92     }
93
94     /**
95      * Compute a hashCode for this object.
96      */

97     public int hashCode() {
98     return number + super.hashCode();
99     }
100 }
101
Popular Tags