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.Arrays;
023    import java.util.LinkedHashSet;
024    import java.util.Set;
025    
026    import org.apache.maven.artifact.Artifact;
027    
028    /**
029     * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
030     */
031    public class ExclusionSetFilter
032        implements ArtifactFilter
033    {
034        private Set<String> excludes;
035    
036        public ExclusionSetFilter( String[] excludes )
037        {
038            this.excludes = new LinkedHashSet<String>( Arrays.asList( excludes ) );
039        }
040    
041        public ExclusionSetFilter( Set<String> excludes )
042        {
043            this.excludes = excludes;
044        }
045    
046        public boolean include( Artifact artifact )
047        {
048            String id = artifact.getArtifactId();
049    
050            if ( excludes.contains( id ) )
051            {
052                return false;
053            }
054    
055            id = artifact.getGroupId() + ':' + id;
056    
057            return !excludes.contains( id );
058    
059        }
060    
061        @Override
062        public int hashCode()
063        {
064            int hash = 17;
065            hash = hash * 31 + excludes.hashCode();
066            return hash;
067        }
068    
069        @Override
070        public boolean equals( Object obj )
071        {
072            if ( this == obj )
073            {
074                return true;
075            }
076            
077            if ( !( obj instanceof ExclusionSetFilter ) )
078            {
079                return false;
080            }
081            
082            ExclusionSetFilter other = (ExclusionSetFilter) obj;
083            
084            return excludes.equals( other.excludes );
085        }
086    }