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: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 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, 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 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:•        for (int i = 0; i < t.length; i++)
59:          terms[i] = t[i];
60: }
61:
62: /**
63: * Return the search terms.
64: *
65: * @return        the search terms
66: */
67: public SearchTerm[] getTerms() {
68:         return terms.clone();
69: }
70:
71: /**
72: * The OR operation. <p>
73: *
74: * The terms specified in the constructor are applied to
75: * the given object and the OR operator is applied to their results.
76: *
77: * @param msg        The specified SearchTerms are applied to this Message
78: *                        and the OR operator is applied to their results.
79: * @return                true if the OR succeds, otherwise false
80: */
81:
82: @Override
83: public boolean match(Message msg) {
84:•        for (int i=0; i < terms.length; i++)
85:•         if (terms[i].match(msg))
86:                 return true;
87:         return false;
88: }
89:
90: /**
91: * Equality comparison.
92: */
93: @Override
94: public boolean equals(Object obj) {
95:•        if (!(obj instanceof OrTerm))
96:          return false;
97:         OrTerm ot = (OrTerm)obj;
98:•        if (ot.terms.length != terms.length)
99:          return false;
100:•        for (int i=0; i < terms.length; i++)
101:•         if (!terms[i].equals(ot.terms[i]))
102:                 return false;
103:         return true;
104: }
105:
106: /**
107: * Compute a hashCode for this object.
108: */
109: @Override
110: public int hashCode() {
111:         int hash = 0;
112:•        for (int i=0; i < terms.length; i++)
113:          hash += terms[i].hashCode();
114:         return hash;
115: }
116: }