Coverage Report - org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch
 
Classes in this File Line Coverage Branch Coverage Complexity
WalkDepthFirstSearch
0%
0/38
0%
0/10
0
 
 1  
 package org.apache.maven.archiva.dependency.graph.walk;
 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.HashMap;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.apache.commons.collections.Predicate;
 26  
 import org.apache.commons.collections.functors.NotPredicate;
 27  
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
 28  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
 29  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
 30  
 import org.apache.maven.archiva.dependency.graph.functors.EdgeDisabledPredicate;
 31  
 import org.apache.maven.archiva.model.ArtifactReference;
 32  
 
 33  
 /**
 34  
  * Perform a walk of the graph using the DepthFirstSearch algorithm.
 35  
  * 
 36  
  * NOTE: Default edgePredicate is to NOT traverse disabled edges.
 37  
  *
 38  
  * @version $Id: WalkDepthFirstSearch.java 755277 2009-03-17 15:18:35Z brett $
 39  
  */
 40  
 public class WalkDepthFirstSearch
 41  
     implements DependencyGraphWalker
 42  
 {
 43  0
     private Map<ArtifactReference, Integer> nodeVisitStates = new HashMap<ArtifactReference, Integer>();
 44  
 
 45  
     private Predicate edgePredicate;
 46  
 
 47  
     public WalkDepthFirstSearch()
 48  0
     {
 49  0
         this.edgePredicate = NotPredicate.getInstance( new EdgeDisabledPredicate() );
 50  0
     }
 51  
 
 52  
     public Predicate getEdgePredicate()
 53  
     {
 54  0
         return this.edgePredicate;
 55  
     }
 56  
 
 57  
     public void setEdgePredicate( Predicate edgePredicate )
 58  
     {
 59  0
         this.edgePredicate = edgePredicate;
 60  0
     }
 61  
 
 62  
     public Integer getNodeVisitState( DependencyGraphNode node )
 63  
     {
 64  0
         if ( node == null )
 65  
         {
 66  0
             return SEEN;
 67  
         }
 68  
 
 69  0
         return (Integer) nodeVisitStates.get( node.getArtifact() );
 70  
     }
 71  
 
 72  
     public Integer getNodeVisitState( ArtifactReference artifact )
 73  
     {
 74  0
         return (Integer) nodeVisitStates.get( artifact );
 75  
     }
 76  
 
 77  
     public void setNodeVisitState( DependencyGraphNode node, Integer state )
 78  
     {
 79  0
         this.nodeVisitStates.put( node.getArtifact(), state );
 80  0
     }
 81  
 
 82  
     public void setNodeVisitState( ArtifactReference artifact, Integer state )
 83  
     {
 84  0
         this.nodeVisitStates.put( artifact, state );
 85  0
     }
 86  
 
 87  
     private void visitEdge( DependencyGraph graph, DependencyGraphEdge e, DependencyGraphVisitor visitor )
 88  
     {
 89  0
         visitor.discoverEdge( e );
 90  
 
 91  0
         DependencyGraphNode node = graph.getNode( e.getNodeTo() );
 92  
 
 93  0
         if ( getNodeVisitState( node ) == UNSEEN )
 94  
         {
 95  0
             visitNode( graph, node, visitor );
 96  
         }
 97  
 
 98  0
         visitor.finishEdge( e );
 99  0
     }
 100  
 
 101  
     private void visitNode( DependencyGraph graph, DependencyGraphNode node, DependencyGraphVisitor visitor )
 102  
     {
 103  0
         setNodeVisitState( node, PROCESSING );
 104  
 
 105  0
         visitor.discoverNode( node );
 106  
 
 107  0
         for ( DependencyGraphEdge e : graph.getEdgesFrom( node ) )
 108  
         {
 109  0
             if ( this.edgePredicate.evaluate( e ) )
 110  
             {
 111  0
                 visitEdge( graph, e, visitor );
 112  
             }
 113  
         }
 114  
 
 115  0
         visitor.finishNode( node );
 116  
 
 117  0
         setNodeVisitState( node, SEEN );
 118  0
     }
 119  
 
 120  
     public void visit( DependencyGraph graph, DependencyGraphVisitor visitor )
 121  
     {
 122  0
         visit( graph, graph.getRootNode(), visitor );
 123  0
     }
 124  
 
 125  
     public void visit( DependencyGraph graph, DependencyGraphNode startNode, DependencyGraphVisitor visitor )
 126  
     {
 127  0
         nodeVisitStates.clear();
 128  
 
 129  0
         for ( DependencyGraphNode node : graph.getNodes() )
 130  
         {
 131  0
             setNodeVisitState( node, UNSEEN );
 132  
         }
 133  
 
 134  0
         visitor.discoverGraph( graph );
 135  
 
 136  0
         visitNode( graph, startNode, visitor );
 137  
 
 138  0
         visitor.finishGraph( graph );
 139  0
     }
 140  
 }