1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.index; 20 21 import java.util.ArrayList; 22 import java.util.Collections; 23 import java.util.List; 24 25 import org.apache.maven.index.context.IndexingContext; 26 27 /** 28 * An abstract helper class for implementing ArtifactInfoFilter that actually aggregates multiple filters into one. It 29 * is up to developer to implement how will be they behave ("fail-fast", or "one-vote-enough for passing", etc). 30 * 31 * @author cstamas 32 */ 33 public abstract class AbstractMultiArtifactInfoFilter implements ArtifactInfoFilter { 34 private final List<ArtifactInfoFilter> filters; 35 36 public AbstractMultiArtifactInfoFilter(final List<ArtifactInfoFilter> filters) { 37 if (filters == null || filters.isEmpty()) { 38 this.filters = null; 39 } else { 40 this.filters = new ArrayList<>(filters); 41 } 42 } 43 44 /** 45 * Returns an unmodifiable list of filters. 46 * 47 * @return 48 */ 49 public List<ArtifactInfoFilter> getFilters() { 50 if (filters == null) { 51 return Collections.emptyList(); 52 } else { 53 return Collections.unmodifiableList(filters); 54 } 55 } 56 57 /** 58 * The filter's implementation is: if list of filters is empty, the just accept it, otherwise consult the list of 59 * filters. 60 */ 61 public boolean accepts(IndexingContext ctx, ArtifactInfo ai) { 62 if (this.filters == null) { 63 return true; 64 } else { 65 return accepts(filters, ctx, ai); 66 } 67 } 68 69 /** 70 * It is left to final implementor to implement how we want to decide using filters. This method is called only if 71 * we _have_ filters set! 72 * 73 * @param filters 74 * @param ctx 75 * @param ai 76 * @return 77 */ 78 protected abstract boolean accepts(List<ArtifactInfoFilter> filters, IndexingContext ctx, ArtifactInfo ai); 79 }