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 import static java.util.Objects.requireNonNull;
31
32
33
34
35
36 public final class AndDependencyFilter implements DependencyFilter {
37
38 private final Set<DependencyFilter> filters = new LinkedHashSet<>();
39
40
41
42
43
44
45
46 public AndDependencyFilter(DependencyFilter... filters) {
47 if (filters != null) {
48 Collections.addAll(this.filters, filters);
49 }
50 }
51
52
53
54
55
56
57 public AndDependencyFilter(Collection<DependencyFilter> filters) {
58 if (filters != null) {
59 this.filters.addAll(filters);
60 }
61 }
62
63
64
65
66
67
68
69
70 public static DependencyFilter newInstance(DependencyFilter filter1, DependencyFilter filter2) {
71 if (filter1 == null) {
72 return filter2;
73 } else if (filter2 == null) {
74 return filter1;
75 }
76 return new AndDependencyFilter(filter1, filter2);
77 }
78
79 public boolean accept(DependencyNode node, List<DependencyNode> parents) {
80 requireNonNull(node, "node cannot be null");
81 requireNonNull(parents, "parents cannot be null");
82 for (DependencyFilter filter : filters) {
83 if (!filter.accept(node, parents)) {
84 return false;
85 }
86 }
87 return true;
88 }
89
90 @Override
91 public boolean equals(Object obj) {
92 if (this == obj) {
93 return true;
94 }
95
96 if (obj == null || !getClass().equals(obj.getClass())) {
97 return false;
98 }
99
100 AndDependencyFilter that = (AndDependencyFilter) obj;
101
102 return this.filters.equals(that.filters);
103 }
104
105 @Override
106 public int hashCode() {
107 int hash = getClass().hashCode();
108 hash = hash * 31 + filters.hashCode();
109 return hash;
110 }
111 }