1 package org.apache.maven.shared.dependency.graph.traversal; 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 org.apache.maven.shared.dependency.graph.DependencyNode; 23 import org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter; 24 25 /** 26 * A dependency node visitor that filters nodes and delegates to another visitor. 27 * 28 * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a> 29 * @version $Id: FilteringDependencyNodeVisitor.java 1595642 2014-05-18 17:32:08Z jvanzyl $ 30 * @since 1.1 31 */ 32 public class FilteringDependencyNodeVisitor 33 implements DependencyNodeVisitor 34 { 35 // fields ----------------------------------------------------------------- 36 37 /** 38 * The dependency node visitor to delegate to. 39 */ 40 private final DependencyNodeVisitor visitor; 41 42 /** 43 * The dependency node filter to apply before delegation. 44 */ 45 private final DependencyNodeFilter filter; 46 47 // constructors ----------------------------------------------------------- 48 49 /** 50 * Creates a dependency node visitor that delegates nodes that are accepted by the specified filter to the specified 51 * visitor. 52 * 53 * @param visitor the dependency node visitor to delegate to 54 * @param filter the dependency node filter to apply before delegation 55 */ 56 public FilteringDependencyNodeVisitor( DependencyNodeVisitor visitor, DependencyNodeFilter filter ) 57 { 58 this.visitor = visitor; 59 this.filter = filter; 60 } 61 62 // DependencyNodeVisitor methods ------------------------------------------ 63 64 /** 65 * {@inheritDoc} 66 */ 67 public boolean visit( DependencyNode node ) 68 { 69 boolean visit; 70 71 if ( filter.accept( node ) ) 72 { 73 visit = visitor.visit( node ); 74 } 75 else 76 { 77 visit = true; 78 } 79 80 return visit; 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 public boolean endVisit( DependencyNode node ) 87 { 88 boolean visit; 89 90 if ( filter.accept( node ) ) 91 { 92 visit = visitor.endVisit( node ); 93 } 94 else 95 { 96 visit = true; 97 } 98 99 return visit; 100 } 101 102 // public methods --------------------------------------------------------- 103 104 /** 105 * Gets the dependency node visitor that this visitor delegates to. 106 * 107 * @return the dependency node visitor 108 */ 109 public DependencyNodeVisitor getDependencyNodeVisitor() 110 { 111 return visitor; 112 } 113 114 /** 115 * Gets the dependency node filter that this visitor applies before delegation. 116 * 117 * @return the dependency node filter 118 */ 119 public DependencyNodeFilter getDependencyNodeFilter() 120 { 121 return filter; 122 } 123 }