1 package org.apache.maven.shared.dependency.graph.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.Arrays; 23 import java.util.Collections; 24 import java.util.List; 25 26 import org.apache.maven.shared.dependency.graph.DependencyNode; 27 28 /** 29 * A dependency node filter that logically ANDs together a number of other dependency node filters. 30 * 31 * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a> 32 * @version $Id$ 33 * @since 1.1 34 */ 35 public class AndDependencyNodeFilter 36 implements DependencyNodeFilter 37 { 38 // fields ----------------------------------------------------------------- 39 40 /** 41 * The dependency node filters that this filter ANDs together. 42 */ 43 private final List<DependencyNodeFilter> filters; 44 45 // constructors ----------------------------------------------------------- 46 47 /** 48 * Creates a dependency node filter that logically ANDs together the two specified dependency node filters. 49 * 50 * @param filter1 the first dependency node filter to logically AND together 51 * @param filter2 the second dependency node filter to logically AND together 52 */ 53 public AndDependencyNodeFilter( DependencyNodeFilter filter1, DependencyNodeFilter filter2 ) 54 { 55 this( Arrays.asList( filter1, filter2 ) ); 56 } 57 58 /** 59 * Creates a dependency node filter that logically ANDs together the specified dependency node filters. 60 * 61 * @param filters the list of dependency node filters to logically AND together 62 */ 63 public AndDependencyNodeFilter( List<DependencyNodeFilter> filters ) 64 { 65 this.filters = Collections.unmodifiableList( filters ); 66 } 67 68 // DependencyNodeFilter methods ------------------------------------------- 69 70 /** 71 * {@inheritDoc} 72 */ 73 @Override 74 public boolean accept( DependencyNode node ) 75 { 76 for ( DependencyNodeFilter filter : filters ) 77 { 78 if ( !filter.accept( node ) ) 79 { 80 return false; 81 } 82 } 83 84 return true; 85 } 86 87 // public methods --------------------------------------------------------- 88 89 /** 90 * Gets the list of dependency node filters that this filter ANDs together. 91 * 92 * @return the dependency node filters that this filter ANDs together 93 */ 94 public List<DependencyNodeFilter> getDependencyNodeFilters() 95 { 96 return filters; 97 } 98 }