1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.filter;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.LinkedHashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.eclipse.aether.graph.DependencyFilter;
28 import org.eclipse.aether.graph.DependencyNode;
29
30
31
32
33 public final class OrDependencyFilter implements DependencyFilter {
34
35 private final Set<DependencyFilter> filters = new LinkedHashSet<>();
36
37
38
39
40
41
42 public OrDependencyFilter(DependencyFilter... filters) {
43 if (filters != null) {
44 Collections.addAll(this.filters, filters);
45 }
46 }
47
48
49
50
51
52
53 public OrDependencyFilter(Collection<DependencyFilter> filters) {
54 if (filters != null) {
55 this.filters.addAll(filters);
56 }
57 }
58
59
60
61
62
63
64
65
66 public static DependencyFilter newInstance(DependencyFilter filter1, DependencyFilter filter2) {
67 if (filter1 == null) {
68 return filter2;
69 } else if (filter2 == null) {
70 return filter1;
71 }
72 return new OrDependencyFilter(filter1, filter2);
73 }
74
75 public boolean accept(DependencyNode node, List<DependencyNode> parents) {
76 for (DependencyFilter filter : filters) {
77 if (filter.accept(node, parents)) {
78 return true;
79 }
80 }
81 return false;
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) {
87 return true;
88 }
89
90 if (obj == null || !getClass().equals(obj.getClass())) {
91 return false;
92 }
93
94 OrDependencyFilter that = (OrDependencyFilter) obj;
95
96 return this.filters.equals(that.filters);
97 }
98
99 @Override
100 public int hashCode() {
101 int hash = getClass().hashCode();
102 hash = hash * 31 + filters.hashCode();
103 return hash;
104 }
105 }