Skip to content

Package: AndTerm

AndTerm

nameinstructionbranchcomplexitylinemethod
AndTerm(SearchTerm, SearchTerm)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
AndTerm(SearchTerm[])
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
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 AND operator on individual
23: * SearchTerms.
24: *
25: * @author Bill Shannon
26: * @author John Mani
27: */
28: public final class AndTerm extends SearchTerm {
29:
30: /**
31: * The array of terms on which the AND operator should be
32: * applied.
33: *
34: * @serial
35: */
36: private SearchTerm[] terms;
37:
38: private static final long serialVersionUID = -3583274505380989582L;
39:
40: /**
41: * Constructor that takes two terms.
42: *
43: * @param t1 first term
44: * @param t2 second term
45: */
46: public AndTerm(SearchTerm t1, SearchTerm t2) {
47:         terms = new SearchTerm[2];
48:         terms[0] = t1;
49:         terms[1] = t2;
50: }
51:
52: /**
53: * Constructor that takes an array of SearchTerms.
54: *
55: * @param t array of terms
56: */
57: public AndTerm(SearchTerm[] t) {
58:         terms = new SearchTerm[t.length]; // clone the array
59:•        for (int i = 0; i < t.length; i++)
60:          terms[i] = t[i];
61: }
62:
63: /**
64: * Return the search terms.
65: *
66: * @return        the search terms
67: */
68: public SearchTerm[] getTerms() {
69:         return terms.clone();
70: }
71:
72: /**
73: * The AND operation. <p>
74: *
75: * The terms specified in the constructor are applied to
76: * the given object and the AND operator is applied to their results.
77: *
78: * @param msg        The specified SearchTerms are applied to this Message
79: *                        and the AND operator is applied to their results.
80: * @return                true if the AND succeds, otherwise false
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 false;
87:         return true;
88: }
89:
90: /**
91: * Equality comparison.
92: */
93: @Override
94: public boolean equals(Object obj) {
95:•        if (!(obj instanceof AndTerm))
96:          return false;
97:         AndTerm at = (AndTerm)obj;
98:•        if (at.terms.length != terms.length)
99:          return false;
100:•        for (int i=0; i < terms.length; i++)
101:•         if (!terms[i].equals(at.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: }