Skip to content

Package: RecipientTerm

RecipientTerm

nameinstructionbranchcomplexitylinemethod
RecipientTerm(Message.RecipientType, Address)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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%
getRecipientType()
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: 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(Message)
M: 31 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 10 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: import jakarta.mail.Address;
21:
22: /**
23: * This class implements comparisons for the Recipient Address headers.
24: *
25: * @author Bill Shannon
26: * @author John Mani
27: */
28: public final class RecipientTerm extends AddressTerm {
29:
30: /**
31: * The recipient type.
32: *
33: * @serial
34: */
35: private Message.RecipientType type;
36:
37: private static final long serialVersionUID = 6548700653122680468L;
38:
39: /**
40: * Constructor.
41: *
42: * @param type        the recipient type
43: * @param address        the address to match for
44: */
45: public RecipientTerm(Message.RecipientType type, Address address) {
46:         super(address);
47:         this.type = type;
48: }
49:
50: /**
51: * Return the type of recipient to match with.
52: *
53: * @return        the recipient type
54: */
55: public Message.RecipientType getRecipientType() {
56:         return type;
57: }
58:
59: /**
60: * The match method.
61: *
62: * @param msg        The address match is applied to this Message's recepient
63: *                        address
64: * @return                true if the match succeeds, otherwise false
65: */
66: @Override
67: public boolean match(Message msg) {
68:         Address[] recipients;
69:
70:         try {
71:          recipients = msg.getRecipients(type);
72:         } catch (Exception e) {
73:          return false;
74:         }
75:
76:•        if (recipients == null)
77:          return false;
78:
79:•        for (int i=0; i < recipients.length; i++)
80:•         if (super.match(recipients[i]))
81:                 return true;
82:         return false;
83: }
84:
85: /**
86: * Equality comparison.
87: */
88: @Override
89: public boolean equals(Object obj) {
90:•        if (!(obj instanceof RecipientTerm))
91:          return false;
92:         RecipientTerm rt = (RecipientTerm)obj;
93:•        return rt.type.equals(this.type) && super.equals(obj);
94: }
95:
96: /**
97: * Compute a hashCode for this object.
98: */
99: @Override
100: public int hashCode() {
101:         return type.hashCode() + super.hashCode();
102: }
103: }