Skip to content

Package: OrTerm

OrTerm

nameinstructionbranchcomplexitylinemethod
OrTerm(SearchTerm, SearchTerm)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
OrTerm(SearchTerm[])
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 6 C: 34
85%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 3 C: 6
67%
M: 0 C: 1
100%
getTerms()
M: 5 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: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
match(Message)
M: 20 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 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 jakarta.mail.Message;
20:
21: /**
22: * This class implements the logical OR operator on individual SearchTerms.
23: *
24: * @author Bill Shannon
25: * @author John Mani
26: */
27: public final class OrTerm extends SearchTerm {
28:
29: /**
30: * The array of terms on which the OR operator should
31: * be applied.
32: *
33: * @serial
34: */
35: private SearchTerm[] terms;
36:
37: private static final long serialVersionUID = 5380534067523646936L;
38:
39: /**
40: * Constructor that takes two operands.
41: *
42: * @param t1 first term
43: * @param t2 second term
44: */
45: public OrTerm(SearchTerm t1, SearchTerm t2) {
46: terms = new SearchTerm[2];
47: terms[0] = t1;
48: terms[1] = t2;
49: }
50:
51: /**
52: * Constructor that takes an array of SearchTerms.
53: *
54: * @param t array of search terms
55: */
56: public OrTerm(SearchTerm[] t) {
57: terms = new SearchTerm[t.length];
58: System.arraycopy(t, 0, terms, 0, t.length);
59: }
60:
61: /**
62: * Return the search terms.
63: *
64: * @return the search terms
65: */
66: public SearchTerm[] getTerms() {
67: return terms.clone();
68: }
69:
70: /**
71: * The OR operation. <p>
72: *
73: * The terms specified in the constructor are applied to
74: * the given object and the OR operator is applied to their results.
75: *
76: * @param msg The specified SearchTerms are applied to this Message
77: * and the OR operator is applied to their results.
78: * @return true if the OR succeds, otherwise false
79: */
80:
81: @Override
82: public boolean match(Message msg) {
83:• for (int i = 0; i < terms.length; i++)
84:• if (terms[i].match(msg))
85: return true;
86: return false;
87: }
88:
89: /**
90: * Equality comparison.
91: */
92: @Override
93: public boolean equals(Object obj) {
94:• if (!(obj instanceof OrTerm))
95: return false;
96: OrTerm ot = (OrTerm) obj;
97:• if (ot.terms.length != terms.length)
98: return false;
99:• for (int i = 0; i < terms.length; i++)
100:• if (!terms[i].equals(ot.terms[i]))
101: return false;
102: return true;
103: }
104:
105: /**
106: * Compute a hashCode for this object.
107: */
108: @Override
109: public int hashCode() {
110: int hash = 0;
111:• for (int i = 0; i < terms.length; i++)
112: hash += terms[i].hashCode();
113: return hash;
114: }
115: }