Skip to content

Package: DateTerm

DateTerm

nameinstructionbranchcomplexitylinemethod
DateTerm(int, Date)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
equals(Object)
M: 3 C: 19
86%
M: 3 C: 3
50%
M: 3 C: 1
25%
M: 1 C: 3
75%
M: 0 C: 1
100%
getComparison()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDate()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
match(Date)
M: 57 C: 0
0%
M: 17 C: 0
0%
M: 12 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package jakarta.mail.search;
18:
19: import java.util.Date;
20:
21: /**
22: * This class implements comparisons for Dates
23: *
24: * @author Bill Shannon
25: * @author John Mani
26: */
27: public abstract class DateTerm extends ComparisonTerm {
28: /**
29: * The date.
30: *
31: * @serial
32: */
33: protected Date date;
34:
35: private static final long serialVersionUID = 4818873430063720043L;
36:
37: /**
38: * Constructor.
39: * @param comparison the comparison type
40: * @param date The Date to be compared against
41: */
42: protected DateTerm(int comparison, Date date) {
43:         this.comparison = comparison;
44:         this.date = date;
45: }
46:
47: /**
48: * Return the Date to compare with.
49: *
50: * @return        the date
51: */
52: public Date getDate() {
53:         return new Date(date.getTime());
54: }
55:
56: /**
57: * Return the type of comparison.
58: *
59: * @return        the comparison type
60: */
61: public int getComparison() {
62:         return comparison;
63: }
64:
65: /**
66: * The date comparison method.
67: *
68: * @param d        the date in the constructor is compared with this date
69: * @return true if the dates match, otherwise false
70: */
71: protected boolean match(Date d) {
72:•        switch (comparison) {
73:          case LE:
74:•                return d.before(date) || d.equals(date);
75:          case LT:
76:                 return d.before(date);
77:          case EQ:
78:                 return d.equals(date);
79:          case NE:
80:•                return !d.equals(date);
81:          case GT:
82:                 return d.after(date);
83:          case GE:
84:•                return d.after(date) || d.equals(date);
85:          default:
86:                 return false;
87:         }
88: }
89:
90: /**
91: * Equality comparison.
92: */
93: @Override
94: public boolean equals(Object obj) {
95:•        if (!(obj instanceof DateTerm))
96:          return false;
97:         DateTerm dt = (DateTerm)obj;
98:•        return dt.date.equals(this.date) && super.equals(obj);
99: }
100:
101: /**
102: * Compute a hashCode for this object.
103: */
104: @Override
105: public int hashCode() {
106:         return date.hashCode() + super.hashCode();
107: }
108: }