View Javadoc

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   * Apply multiple filters.
32   *
33   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
34   * @version $Id: AndArtifactFilter.java 829934 2009-10-26 20:16:00Z bentmann $
35   */
36  public class AndArtifactFilter
37      implements ArtifactFilter
38  {
39      private Set<ArtifactFilter> filters; 
40  
41      public AndArtifactFilter()
42      {
43          this.filters = new LinkedHashSet<ArtifactFilter>();
44      }
45  
46      public AndArtifactFilter( List<ArtifactFilter> filters )
47      {
48          this.filters = new LinkedHashSet<ArtifactFilter>( filters );
49      }
50      
51      public boolean include( Artifact artifact )
52      {
53          boolean include = true;
54          for ( Iterator<ArtifactFilter> i = filters.iterator(); i.hasNext() && include; )
55          {
56              ArtifactFilter filter = i.next();
57              if ( !filter.include( artifact ) )
58              {
59                  include = false;
60              }
61          }
62          return include;
63      }
64  
65      public void add( ArtifactFilter artifactFilter )
66      {
67          filters.add( artifactFilter );
68      }
69  
70      public List<ArtifactFilter> getFilters()
71      {
72          return new ArrayList<ArtifactFilter>( filters );
73      }
74  
75      @Override
76      public int hashCode()
77      {
78          int hash = 17;
79          hash = hash * 31 + filters.hashCode();
80          return hash;
81      }
82  
83      @Override
84      public boolean equals( Object obj )
85      {
86          if ( this == obj )
87          {
88              return true;
89          }
90          
91          if ( !( obj instanceof AndArtifactFilter ) )
92          {
93              return false;
94          }
95          
96          AndArtifactFilter other = (AndArtifactFilter) obj;
97          
98          return filters.equals( other.filters );
99      }
100 }