001 package org.apache.maven.artifact.resolver.filter;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.Collection;
023 import java.util.LinkedHashSet;
024 import java.util.Set;
025
026 import org.apache.maven.artifact.Artifact;
027
028 /**
029 * Apply multiple filters, accepting an artifact if at least one of the filters accepts it.
030 *
031 * @author Benjamin Bentmann
032 */
033 public class OrArtifactFilter
034 implements ArtifactFilter
035 {
036
037 private Set<ArtifactFilter> filters;
038
039 public OrArtifactFilter()
040 {
041 this.filters = new LinkedHashSet<ArtifactFilter>();
042 }
043
044 public OrArtifactFilter( Collection<ArtifactFilter> filters )
045 {
046 this.filters = new LinkedHashSet<ArtifactFilter>( filters );
047 }
048
049 public boolean include( Artifact artifact )
050 {
051 for ( ArtifactFilter filter : filters )
052 {
053 if ( filter.include( artifact ) )
054 {
055 return true;
056 }
057 }
058
059 return false;
060 }
061
062 public void add( ArtifactFilter artifactFilter )
063 {
064 filters.add( artifactFilter );
065 }
066
067 @Override
068 public int hashCode()
069 {
070 int hash = 17;
071 hash = hash * 31 + filters.hashCode();
072 return hash;
073 }
074
075 @Override
076 public boolean equals( Object obj )
077 {
078 if ( this == obj )
079 {
080 return true;
081 }
082
083 if ( !( obj instanceof OrArtifactFilter ) )
084 {
085 return false;
086 }
087
088 OrArtifactFilter other = (OrArtifactFilter) obj;
089
090 return filters.equals( other.filters );
091 }
092
093 }