Stuart McCulloch | acef948 | 2009-09-02 18:33:41 +0000 | [diff] [blame^] | 1 | package org.apache.maven.shared.dependency.tree.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.tree.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: CollectingDependencyNodeVisitor.java 661727 2008-05-30 14:21:49Z bentmann $ |
| 33 | * @since 1.1 |
| 34 | */ |
| 35 | public class CollectingDependencyNodeVisitor implements DependencyNodeVisitor |
| 36 | { |
| 37 | // fields ----------------------------------------------------------------- |
| 38 | |
| 39 | /** |
| 40 | * The collected list of nodes. |
| 41 | */ |
| 42 | private final List nodes; |
| 43 | |
| 44 | // constructors ----------------------------------------------------------- |
| 45 | |
| 46 | /** |
| 47 | * Creates a dependency node visitor that collects visited nodes for further processing. |
| 48 | */ |
| 49 | public CollectingDependencyNodeVisitor() |
| 50 | { |
| 51 | nodes = new ArrayList(); |
| 52 | } |
| 53 | |
| 54 | // DependencyNodeVisitor methods ------------------------------------------ |
| 55 | |
| 56 | /** |
| 57 | * {@inheritDoc} |
| 58 | */ |
| 59 | public boolean visit( DependencyNode node ) |
| 60 | { |
| 61 | // collect node |
| 62 | nodes.add( node ); |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * {@inheritDoc} |
| 69 | */ |
| 70 | public boolean endVisit( DependencyNode node ) |
| 71 | { |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | // public methods --------------------------------------------------------- |
| 76 | |
| 77 | /** |
| 78 | * Gets the list of collected dependency nodes. |
| 79 | * |
| 80 | * @return the list of collected dependency nodes |
| 81 | */ |
| 82 | public List getNodes() |
| 83 | { |
| 84 | return Collections.unmodifiableList( nodes ); |
| 85 | } |
| 86 | } |