blob: b5f801ceb4c5b15ffe786e6301dcb534d0efc85a [file] [log] [blame]
Stuart McCullochacef9482009-09-02 18:33:41 +00001package 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
22import java.util.Arrays;
23import java.util.Collections;
24import java.util.Iterator;
25import java.util.List;
26
27import org.apache.maven.shared.dependency.tree.DependencyNode;
28
29/**
30 * A dependency node filter that logically ANDs together a number of other dependency node filters.
31 *
32 * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
33 * @version $Id: AndDependencyNodeFilter.java 661727 2008-05-30 14:21:49Z bentmann $
34 * @since 1.1
35 */
36public class AndDependencyNodeFilter implements DependencyNodeFilter
37{
38 // fields -----------------------------------------------------------------
39
40 /**
41 * The dependency node filters that this filter ANDs together.
42 */
43 private final List 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
51 * the first dependency node filter to logically AND together
52 * @param filter2
53 * the second dependency node filter to logically AND together
54 */
55 public AndDependencyNodeFilter( DependencyNodeFilter filter1, DependencyNodeFilter filter2 )
56 {
57 this( Arrays.asList( new DependencyNodeFilter[] { filter1, filter2 } ) );
58 }
59
60 /**
61 * Creates a dependency node filter that logically ANDs together the specified dependency node filters.
62 *
63 * @param filters
64 * the list of dependency node filters to logically AND together
65 */
66 public AndDependencyNodeFilter( List filters )
67 {
68 this.filters = Collections.unmodifiableList( filters );
69 }
70
71 // DependencyNodeFilter methods -------------------------------------------
72
73 /**
74 * {@inheritDoc}
75 */
76 public boolean accept( DependencyNode node )
77 {
78 boolean accept = true;
79
80 for ( Iterator iterator = filters.iterator(); accept && iterator.hasNext(); )
81 {
82 DependencyNodeFilter filter = (DependencyNodeFilter) iterator.next();
83
84 accept = filter.accept( node );
85 }
86
87 return accept;
88 }
89
90 // public methods ---------------------------------------------------------
91
92 /**
93 * Gets the list of dependency node filters that this filter ANDs together.
94 *
95 * @return the dependency node filters that this filter ANDs together
96 */
97 public List getDependencyNodeFilters()
98 {
99 return filters;
100 }
101}