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.HashSet; 24 import java.util.Set; 25 26 /** 27 * Filter to only retain objects in the given scope or better. This implementation allows the accumulation of multiple 28 * scopes and their associated implied scopes, so that the user can filter apply a series of implication rules in a 29 * single step. This should be a more efficient implementation of multiple standard {@link ScopeArtifactFilter} 30 * instances ORed together. 31 * 32 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 33 * @author jdcasey 34 * @version $Id: CumulativeScopeArtifactFilter.java 1035671 2010-11-16 16:04:51Z bentmann $ 35 */ 36 public class CumulativeScopeArtifactFilter 37 extends AbstractScopeArtifactFilter 38 { 39 40 private Set<String> scopes; 41 42 /** 43 * Create a new filter with the specified scopes and their implied scopes enabled. 44 * 45 * @param scopes The scopes to enable, along with all implied scopes, may be {@code null}. 46 */ 47 public CumulativeScopeArtifactFilter( Collection<String> scopes ) 48 { 49 this.scopes = new HashSet<String>(); 50 51 addScopes( scopes ); 52 } 53 54 /** 55 * Creates a new filter that combines the specified filters. 56 * 57 * @param filters The filters to combine, may be {@code null}. 58 */ 59 public CumulativeScopeArtifactFilter( CumulativeScopeArtifactFilter... filters ) 60 { 61 this.scopes = new HashSet<String>(); 62 63 if ( filters != null ) 64 { 65 for ( CumulativeScopeArtifactFilter filter : filters ) 66 { 67 addScopes( filter.getScopes() ); 68 } 69 } 70 } 71 72 private void addScopes( Collection<String> scopes ) 73 { 74 if ( scopes != null ) 75 { 76 for ( String scope : scopes ) 77 { 78 addScope( scope ); 79 } 80 } 81 } 82 83 private void addScope( String scope ) 84 { 85 this.scopes.add( scope ); 86 87 addScopeInternal( scope ); 88 } 89 90 public Set<String> getScopes() 91 { 92 return scopes; 93 } 94 95 @Override 96 public int hashCode() 97 { 98 int hash = 17; 99 100 hash = hash * 31 + scopes.hashCode(); 101 102 return hash; 103 } 104 105 @Override 106 public boolean equals( Object obj ) 107 { 108 if ( this == obj ) 109 { 110 return true; 111 } 112 113 if ( !( obj instanceof CumulativeScopeArtifactFilter ) ) 114 { 115 return false; 116 } 117 118 CumulativeScopeArtifactFilter that = (CumulativeScopeArtifactFilter) obj; 119 120 return scopes.equals( that.scopes ); 121 } 122 123 }