1 /** 2 * 3 * Copyright 2003-2004 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package javax.mail.search; 19 20 /** 21 * A Term that provides comparisons for integers. 22 * 23 * @version $Rev: 126550 $ $Date: 2005-01-26 14:27:45 -0800 (Wed, 26 Jan 2005) $ 24 */ 25 public abstract class IntegerComparisonTerm extends ComparisonTerm { 26 protected int number; 27 28 protected IntegerComparisonTerm(int comparison, int number) { 29 super(); 30 this.comparison = comparison; 31 this.number = number; 32 } 33 34 public int getNumber() { 35 return number; 36 } 37 38 public int getComparison() { 39 return comparison; 40 } 41 42 protected boolean match(int match) { 43 switch (comparison) { 44 case EQ: 45 return match == number; 46 case NE: 47 return match != number; 48 case GT: 49 return match > number; 50 case GE: 51 return match >= number; 52 case LT: 53 return match < number; 54 case LE: 55 return match <= number; 56 default: 57 return false; 58 } 59 } 60 61 public boolean equals(Object other) { 62 if (other == this) return true; 63 if (other instanceof IntegerComparisonTerm == false) return false; 64 final IntegerComparisonTerm term = (IntegerComparisonTerm) other; 65 return this.comparison == term.comparison && this.number == term.number; 66 } 67 68 public int hashCode() { 69 return number; 70 } 71 }