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 java.util.ArrayList; 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 visitor that collects visited nodes for further processing. 30 * 31 * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a> 32 * @version $Id$ 33 * @since 1.1 34 */ 35 public class CollectingDependencyNodeVisitor 36 implements DependencyNodeVisitor 37 { 38 // fields ----------------------------------------------------------------- 39 40 /** 41 * The collected list of nodes. 42 */ 43 private final List<DependencyNode> nodes; 44 45 // constructors ----------------------------------------------------------- 46 47 /** 48 * Creates a dependency node visitor that collects visited nodes for further processing. 49 */ 50 public CollectingDependencyNodeVisitor() 51 { 52 nodes = new ArrayList<>(); 53 } 54 55 // DependencyNodeVisitor methods ------------------------------------------ 56 57 /** 58 * {@inheritDoc} 59 */ 60 @Override 61 public boolean visit( DependencyNode node ) 62 { 63 // collect node 64 nodes.add( node ); 65 66 return true; 67 } 68 69 /** 70 * {@inheritDoc} 71 */ 72 @Override 73 public boolean endVisit( DependencyNode node ) 74 { 75 return true; 76 } 77 78 // public methods --------------------------------------------------------- 79 80 /** 81 * Gets the list of collected dependency nodes. 82 * 83 * @return the list of collected dependency nodes 84 */ 85 public List<DependencyNode> getNodes() 86 { 87 return Collections.unmodifiableList( nodes ); 88 } 89 }