1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.artifact.resolver.filter;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.LinkedHashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.apache.maven.artifact.Artifact;
28
29
30
31
32
33 public class AndArtifactFilter implements ArtifactFilter {
34 private Set<ArtifactFilter> filters;
35
36 public AndArtifactFilter() {
37 this.filters = new LinkedHashSet<>();
38 }
39
40 public AndArtifactFilter(List<ArtifactFilter> filters) {
41 this.filters = new LinkedHashSet<>(filters);
42 }
43
44 public boolean include(Artifact artifact) {
45 boolean include = true;
46 for (Iterator<ArtifactFilter> i = filters.iterator(); i.hasNext() && include; ) {
47 ArtifactFilter filter = i.next();
48 if (!filter.include(artifact)) {
49 include = false;
50 }
51 }
52 return include;
53 }
54
55 public void add(ArtifactFilter artifactFilter) {
56 filters.add(artifactFilter);
57 }
58
59 public List<ArtifactFilter> getFilters() {
60 return new ArrayList<>(filters);
61 }
62
63 @Override
64 public int hashCode() {
65 int hash = 17;
66 hash = hash * 31 + filters.hashCode();
67 return hash;
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (this == obj) {
73 return true;
74 }
75
76 if (!(obj instanceof AndArtifactFilter)) {
77 return false;
78 }
79
80 AndArtifactFilter other = (AndArtifactFilter) obj;
81
82 return filters.equals(other.filters);
83 }
84 }