1 package org.apache.maven.shared.dependency.tree.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.tree.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: AndDependencyNodeFilter.java 1595642 2014-05-18 17:32:08Z jvanzyl $ 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( new DependencyNodeFilter[] { 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 public boolean accept( DependencyNode node ) 74 { 75 for ( DependencyNodeFilter filter : filters ) 76 { 77 if ( !filter.accept( node ) ) 78 { 79 return false; 80 } 81 } 82 83 return true; 84 } 85 86 // public methods --------------------------------------------------------- 87 88 /** 89 * Gets the list of dependency node filters that this filter ANDs together. 90 * 91 * @return the dependency node filters that this filter ANDs together 92 */ 93 public List<DependencyNodeFilter> getDependencyNodeFilters() 94 { 95 return filters; 96 } 97 }