1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package javax.mail.search;
21
22 import java.util.Arrays;
23 import javax.mail.Message;
24
25
26
27
28 public final class OrTerm extends SearchTerm {
29 protected SearchTerm[] terms;
30
31 public OrTerm(SearchTerm a, SearchTerm b) {
32 terms = new SearchTerm[]{a, b};
33 }
34
35 public OrTerm(SearchTerm[] terms) {
36 this.terms = terms;
37 }
38
39 public SearchTerm[] getTerms() {
40 return terms;
41 }
42
43 public boolean match(Message message) {
44 for (int i = 0; i < terms.length; i++) {
45 SearchTerm term = terms[i];
46 if (term.match(message)) {
47 return true;
48 }
49 }
50 return false;
51 }
52
53 public boolean equals(Object other) {
54 if (other == this) return true;
55 if (other instanceof OrTerm == false) return false;
56 return Arrays.equals(terms, ((OrTerm) other).terms);
57 }
58
59 public int hashCode() {
60 int hash = 0;
61 for (int i = 0; i < terms.length; i++) {
62 hash = hash * 37 + terms[i].hashCode();
63 }
64 return hash;
65 }
66 }