1 package org.apache.maven.index; 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.Collections; 24 import java.util.List; 25 26 import org.apache.maven.index.context.IndexingContext; 27 28 /** 29 * An abstract helper class for implementing ArtifactInfoFilter that actually aggregates multiple filters into one. It 30 * is up to developer to implement how will be they behave ("fail-fast", or "one-vote-enough for passing", etc). 31 * 32 * @author cstamas 33 */ 34 public abstract class AbstractMultiArtifactInfoFilter 35 implements ArtifactInfoFilter 36 { 37 private final List<ArtifactInfoFilter> filters; 38 39 public AbstractMultiArtifactInfoFilter( final List<ArtifactInfoFilter> filters ) 40 { 41 if ( filters == null || filters.isEmpty() ) 42 { 43 this.filters = null; 44 } 45 else 46 { 47 this.filters = new ArrayList<ArtifactInfoFilter>( filters ); 48 } 49 } 50 51 /** 52 * Returns an unmodifiable list of filters. 53 * 54 * @return 55 */ 56 public List<ArtifactInfoFilter> getFilters() 57 { 58 if ( filters == null ) 59 { 60 return Collections.emptyList(); 61 } 62 else 63 { 64 return Collections.unmodifiableList( filters ); 65 } 66 } 67 68 /** 69 * The filter's implementation is: if list of filters is empty, the just accept it, otherwise consult the list of 70 * filters. 71 */ 72 public boolean accepts( IndexingContext ctx, ArtifactInfo ai ) 73 { 74 if ( this.filters == null ) 75 { 76 return true; 77 } 78 else 79 { 80 return accepts( filters, ctx, ai ); 81 } 82 } 83 84 /** 85 * It is left to final implementor to implement how we want to decide using filters. This method is called only if 86 * we _have_ filters set! 87 * 88 * @param filters 89 * @param ctx 90 * @param ai 91 * @return 92 */ 93 protected abstract boolean accepts( List<ArtifactInfoFilter> filters, IndexingContext ctx, ArtifactInfo ai ); 94 }