1 /**
2 *
3 * Copyright 2003-2006 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 import java.util.Date;
21
22 /**
23 * @version $Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $
24 */
25 public abstract class DateTerm extends ComparisonTerm {
26 protected Date date;
27
28 protected DateTerm(int comparison, Date date) {
29 super();
30 this.comparison = comparison;
31 this.date = date;
32 }
33
34 public Date getDate() {
35 return date;
36 }
37
38 public int getComparison() {
39 return comparison;
40 }
41
42 protected boolean match(Date match) {
43 long matchTime = match.getTime();
44 long mytime = date.getTime();
45 switch (comparison) {
46 case EQ:
47 return matchTime == mytime;
48 case NE:
49 return matchTime != mytime;
50 case LE:
51 return matchTime <= mytime;
52 case LT:
53 return matchTime < mytime;
54 case GT:
55 return matchTime > mytime;
56 case GE:
57 return matchTime >= mytime;
58 default:
59 return false;
60 }
61 }
62
63 public boolean equals(Object other) {
64 if (other == this) return true;
65 if (other instanceof DateTerm == false) return false;
66 final DateTerm term = (DateTerm) other;
67 return this.comparison == term.comparison && this.date.equals(term.date);
68 }
69
70 public int hashCode() {
71 return date.hashCode();
72 }
73 }