001 /**
002 *
003 * Copyright 2003-2006 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package javax.mail.search;
019
020 import java.util.Date;
021
022 /**
023 * @version $Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $
024 */
025 public abstract class DateTerm extends ComparisonTerm {
026 protected Date date;
027
028 protected DateTerm(int comparison, Date date) {
029 super();
030 this.comparison = comparison;
031 this.date = date;
032 }
033
034 public Date getDate() {
035 return date;
036 }
037
038 public int getComparison() {
039 return comparison;
040 }
041
042 protected boolean match(Date match) {
043 long matchTime = match.getTime();
044 long mytime = date.getTime();
045 switch (comparison) {
046 case EQ:
047 return matchTime == mytime;
048 case NE:
049 return matchTime != mytime;
050 case LE:
051 return matchTime <= mytime;
052 case LT:
053 return matchTime < mytime;
054 case GT:
055 return matchTime > mytime;
056 case GE:
057 return matchTime >= mytime;
058 default:
059 return false;
060 }
061 }
062
063 public boolean equals(Object other) {
064 if (other == this) return true;
065 if (other instanceof DateTerm == false) return false;
066 final DateTerm term = (DateTerm) other;
067 return this.comparison == term.comparison && this.date.equals(term.date);
068 }
069
070 public int hashCode() {
071 return date.hashCode();
072 }
073 }