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, 2023 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: *
40: * @param comparison the comparison type
41: * @param date The Date to be compared against
42: */
43: protected DateTerm(int comparison, Date date) {
44: this.comparison = comparison;
45: this.date = date;
46: }
47:
48: /**
49: * Return the Date to compare with.
50: *
51: * @return the date
52: */
53: public Date getDate() {
54: return new Date(date.getTime());
55: }
56:
57: /**
58: * Return the type of comparison.
59: *
60: * @return the comparison type
61: */
62: public int getComparison() {
63: return comparison;
64: }
65:
66: /**
67: * The date comparison method.
68: *
69: * @param d the date in the constructor is compared with this date
70: * @return true if the dates match, otherwise false
71: */
72: protected boolean match(Date d) {
73:• switch (comparison) {
74: case LE:
75:• return d.before(date) || d.equals(date);
76: case LT:
77: return d.before(date);
78: case EQ:
79: return d.equals(date);
80: case NE:
81:• return !d.equals(date);
82: case GT:
83: return d.after(date);
84: case GE:
85:• return d.after(date) || d.equals(date);
86: default:
87: return false;
88: }
89: }
90:
91: /**
92: * Equality comparison.
93: */
94: @Override
95: public boolean equals(Object obj) {
96:• if (!(obj instanceof DateTerm))
97: return false;
98: DateTerm dt = (DateTerm) obj;
99:• return dt.date.equals(this.date) && super.equals(obj);
100: }
101:
102: /**
103: * Compute a hashCode for this object.
104: */
105: @Override
106: public int hashCode() {
107: return date.hashCode() + super.hashCode();
108: }
109: }