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.ArrayList;
23 import java.util.Iterator;
24 import java.util.LinkedHashSet;
25 import java.util.List;
26 import java.util.Set;
27
28 import org.apache.maven.artifact.Artifact;
29
30 /**
31 * Filter to include from a list of artifact patterns.
32 *
33 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
34 * @version $Id: IncludesArtifactFilter.java 829934 2009-10-26 20:16:00Z bentmann $
35 */
36 public class IncludesArtifactFilter
37 implements ArtifactFilter
38 {
39 private final Set<String> patterns;
40
41 public IncludesArtifactFilter( List<String> patterns )
42 {
43 this.patterns = new LinkedHashSet<String>( patterns );
44 }
45
46 public boolean include( Artifact artifact )
47 {
48 String id = artifact.getGroupId() + ":" + artifact.getArtifactId();
49
50 boolean matched = false;
51 for ( Iterator<String> i = patterns.iterator(); i.hasNext() & !matched; )
52 {
53 // TODO: what about wildcards? Just specifying groups? versions?
54 if ( id.equals( i.next() ) )
55 {
56 matched = true;
57 }
58 }
59 return matched;
60 }
61
62 public List<String> getPatterns()
63 {
64 return new ArrayList<String>( patterns );
65 }
66
67 @Override
68 public int hashCode()
69 {
70 int hash = 17;
71 hash = hash * 31 + patterns.hashCode();
72
73 return hash;
74 }
75
76 @Override
77 public boolean equals( Object obj )
78 {
79 if ( this == obj )
80 {
81 return true;
82 }
83
84 // make sure IncludesArtifactFilter is not equal ExcludesArtifactFilter!
85 if ( obj == null || getClass() != obj.getClass() )
86 {
87 return false;
88 }
89
90 IncludesArtifactFilter other = (IncludesArtifactFilter) obj;
91
92 return patterns.equals( other.patterns );
93 }
94 }