1 package org.apache.maven.artifact.resolver.filter;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.Collection;
23 import java.util.LinkedHashSet;
24 import java.util.Set;
25
26 import org.apache.maven.artifact.Artifact;
27
28 /**
29 * Apply multiple filters, accepting an artifact if at least one of the filters accepts it.
30 *
31 * @author Benjamin Bentmann
32 */
33 public class OrArtifactFilter
34 implements ArtifactFilter
35 {
36
37 private Set<ArtifactFilter> filters;
38
39 public OrArtifactFilter()
40 {
41 this.filters = new LinkedHashSet<ArtifactFilter>();
42 }
43
44 public OrArtifactFilter( Collection<ArtifactFilter> filters )
45 {
46 this.filters = new LinkedHashSet<ArtifactFilter>( filters );
47 }
48
49 public boolean include( Artifact artifact )
50 {
51 for ( ArtifactFilter filter : filters )
52 {
53 if ( filter.include( artifact ) )
54 {
55 return true;
56 }
57 }
58
59 return false;
60 }
61
62 public void add( ArtifactFilter artifactFilter )
63 {
64 filters.add( artifactFilter );
65 }
66
67 @Override
68 public int hashCode()
69 {
70 int hash = 17;
71 hash = hash * 31 + filters.hashCode();
72 return hash;
73 }
74
75 @Override
76 public boolean equals( Object obj )
77 {
78 if ( this == obj )
79 {
80 return true;
81 }
82
83 if ( !( obj instanceof OrArtifactFilter ) )
84 {
85 return false;
86 }
87
88 OrArtifactFilter other = (OrArtifactFilter) obj;
89
90 return filters.equals( other.filters );
91 }
92
93 }