Skip to content

Package: YoungerTerm

YoungerTerm

nameinstructionbranchcomplexitylinemethod
YoungerTerm(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getInterval()
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%
hashCode()
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%
match(Message)
M: 26 C: 0
0%
M: 4 C: 0
0%
M: 3 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 org.eclipse.angus.mail.imap;
18:
19: import jakarta.mail.Message;
20: import jakarta.mail.search.SearchTerm;
21:
22: import java.util.Date;
23:
24: /**
25: * Find messages that are younger than a given interval (in seconds).
26: * Relies on the server implementing the WITHIN search extension
27: * (<A HREF="http://www.ietf.org/rfc/rfc5032.txt">RFC 5032</A>).
28: *
29: * @since JavaMail 1.5.1
30: * @author Bill Shannon
31: */
32: public final class YoungerTerm extends SearchTerm {
33:
34: private int interval;
35:
36: private static final long serialVersionUID = 1592714210688163496L;
37:
38: /**
39: * Constructor.
40: *
41: * @param interval number of seconds younger
42: */
43: public YoungerTerm(int interval) {
44: this.interval = interval;
45: }
46:
47: /**
48: * Return the interval.
49: *
50: * @return the interval
51: */
52: public int getInterval() {
53: return interval;
54: }
55:
56: /**
57: * The match method.
58: *
59: * @param msg the date comparator is applied to this Message's
60: * received date
61: * @return true if the comparison succeeds, otherwise false
62: */
63: @Override
64: public boolean match(Message msg) {
65: Date d;
66:
67: try {
68: d = msg.getReceivedDate();
69: } catch (Exception e) {
70: return false;
71: }
72:
73:• if (d == null)
74: return false;
75:
76: return d.getTime() >=
77:• System.currentTimeMillis() - ((long) interval * 1000);
78: }
79:
80: /**
81: * Equality comparison.
82: */
83: @Override
84: public boolean equals(Object obj) {
85:• if (!(obj instanceof YoungerTerm))
86: return false;
87:• return interval == ((YoungerTerm) obj).interval;
88: }
89:
90: /**
91: * Compute a hashCode for this object.
92: */
93: @Override
94: public int hashCode() {
95: return interval;
96: }
97: }