]> source.dussan.org Git - archiva.git/commitdiff
clean warnings from dependency-graph
authorBrett Porter <brett@apache.org>
Tue, 17 Mar 2009 15:18:35 +0000 (15:18 +0000)
committerBrett Porter <brett@apache.org>
Tue, 17 Mar 2009 15:18:35 +0000 (15:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@755277 13f79535-47bb-0310-9956-ffa450edef68

26 files changed:
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/DependencyGraphFactory.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraph.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphNode.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphUtils.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementApplier.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementStack.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagCyclicEdgesVisitor.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagExcludedEdgesVisitor.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/ReduceTransitiveEdgesVisitor.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsTask.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsVisitor.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/UpdateScopesVisitor.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkBreadthFirstSearch.java
archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkDepthFirstSearch.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractDependencyGraphFactoryTestCase.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractMemoryRepository.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaCommonDependencyGraphTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaWebappDependencyGraphTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaXmlToolsDependencyGraphTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ContinuumStoreDependencyGraphTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/DepManDeepVersionDependencyGraphTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/GraphvizDotTool.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/SimpleDependencyGraphTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/WagonManagerDependencyGraphTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/DependencyGraphWalkerTest.java
archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/WalkCollector.java

index daae2e29fa05edea5dd643fafe9909b78cdc89c4..90d8dfdb267a032f1c4494fa29db627196558ebe 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency;
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
 import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
 import org.apache.maven.archiva.dependency.graph.GraphListener;
@@ -37,10 +40,6 @@ import org.apache.maven.archiva.dependency.graph.tasks.UpdateScopesTask;
 import org.apache.maven.archiva.model.DependencyScope;
 import org.apache.maven.archiva.model.VersionedReference;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * DependencyGraphFactory 
  *
@@ -54,21 +53,21 @@ public class DependencyGraphFactory
 
     private ReduceScopeTask taskReduceScope;
 
-    private List listeners;
+    private List<GraphListener> listeners;
 
     private DependencyGraphBuilder graphBuilder;
 
-    private List tasks;
+    private List<GraphTask> tasks;
 
     public DependencyGraphFactory()
     {
-        listeners = new ArrayList();
+        listeners = new ArrayList<GraphListener>();
 
         taskFlagCyclicEdges = new FlagCyclicEdgesTask();
         taskPopulateGraph = new PopulateGraphMasterTask();
         taskReduceScope = new ReduceScopeTask( DependencyScope.TEST );
 
-        tasks = new ArrayList();
+        tasks = new ArrayList<GraphTask>();
 
         /* Take the basic graph, and expand the nodes fully, including depman.
          */
@@ -124,10 +123,8 @@ public class DependencyGraphFactory
 
         triggerGraphPhase( GraphPhaseEvent.GRAPH_NEW, null, graph );
 
-        Iterator it = this.tasks.iterator();
-        while ( it.hasNext() )
+        for ( GraphTask task : this.tasks )
         {
-            GraphTask task = (GraphTask) it.next();
             try
             {
                 triggerGraphPhase( GraphPhaseEvent.GRAPH_TASK_PRE, task, graph );
@@ -174,10 +171,8 @@ public class DependencyGraphFactory
 
     private void triggerGraphError( GraphTaskException e, DependencyGraph graph )
     {
-        Iterator it = listeners.iterator();
-        while ( it.hasNext() )
+        for ( GraphListener listener : listeners )
         {
-            GraphListener listener = (GraphListener) it.next();
             listener.graphError( e, graph );
         }
     }
@@ -186,10 +181,8 @@ public class DependencyGraphFactory
     {
         GraphPhaseEvent evt = new GraphPhaseEvent( type, task, graph );
 
-        Iterator it = listeners.iterator();
-        while ( it.hasNext() )
+        for ( GraphListener listener : listeners )
         {
-            GraphListener listener = (GraphListener) it.next();
             listener.graphPhaseEvent( evt );
         }
     }
index 404d300275f7a12f662053da8ee4d81afdb999f3..bf8fac55f0e17d2a390810688d7bad9601c73656 100644 (file)
@@ -50,7 +50,7 @@ public class DependencyGraph
 
     private DependencyGraphNode rootNode;
 
-    private Set edges = new HashSet();
+    private Set<DependencyGraphEdge> edges = new HashSet<DependencyGraphEdge>();
 
     private ListOrderedMap nodes = new ListOrderedMap();
 
@@ -71,12 +71,13 @@ public class DependencyGraph
         this.rootNode = root;
     }
 
-    public Collection getEdges()
+    public Collection<DependencyGraphEdge> getEdges()
     {
         return edges;
     }
 
-    public Collection getNodes()
+    @SuppressWarnings("unchecked")
+    public Collection<DependencyGraphNode> getNodes()
     {
         return nodes.values();
     }
@@ -172,9 +173,9 @@ public class DependencyGraph
      * @param node the node to use as the 'from' side of an edge.
      * @return the edges from the provided node.
      */
-    public List getEdgesFrom( DependencyGraphNode node )
+    public List<DependencyGraphEdge> getEdgesFrom( DependencyGraphNode node )
     {
-        List ret = new ArrayList();
+        List<DependencyGraphEdge> ret = new ArrayList<DependencyGraphEdge>();
         CollectionUtils.select( this.edges, new EdgeFromPredicate( node.getArtifact() ), ret );
         return ret;
     }
@@ -185,9 +186,9 @@ public class DependencyGraph
      * @param node the node to use as the 'to' side of an edge.
      * @return the edges to the provided node.
      */
-    public List getEdgesTo( DependencyGraphNode node )
+    public List<DependencyGraphEdge> getEdgesTo( DependencyGraphNode node )
     {
-        List ret = new ArrayList();
+        List<DependencyGraphEdge> ret = new ArrayList<DependencyGraphEdge>();
         CollectionUtils.select( this.edges, new EdgeToPredicate( node.getArtifact() ), ret );
         return ret;
     }
@@ -210,7 +211,7 @@ public class DependencyGraph
 
     public void removeNode( DependencyGraphNode node )
     {
-        List edges = getEdgesFrom( node );
+        List<DependencyGraphEdge> edges = getEdgesFrom( node );
         if ( !edges.isEmpty() )
         {
             System.out.println( "Removing node left <" + edges + "> hanging <from> edges." );
index dfddd3fa99f27e47c289d179c5fac65aa05eda0a..98cd2d6e02e28b11ebadbd4eafa2182a4683192f 100644 (file)
@@ -43,12 +43,12 @@ public class DependencyGraphNode
     /**
      * The project level dependency management section for this artifact.
      */
-    private List dependencyManagement = new ArrayList();
+    private List<Dependency> dependencyManagement = new ArrayList<Dependency>();
 
     /**
      * The list of excluded groupId:artifactId for this node's sub-nodes. 
      */
-    private Set excludes = new HashSet();
+    private Set<String> excludes = new HashSet<String>();
 
     /**
      * Flag indicating that this node has been resolved from disk.
@@ -115,12 +115,12 @@ public class DependencyGraphNode
         return artifact;
     }
 
-    public List getDependencyManagement()
+    public List<Dependency> getDependencyManagement()
     {
         return dependencyManagement;
     }
 
-    public Set getExcludes()
+    public Set<String> getExcludes()
     {
         return excludes;
     }
@@ -158,12 +158,12 @@ public class DependencyGraphNode
         this.conflicted = conflicted;
     }
 
-    public void setDependencyManagement( List dependencyManagement )
+    public void setDependencyManagement( List<Dependency> dependencyManagement )
     {
         this.dependencyManagement = dependencyManagement;
     }
 
-    public void setExcludes( Set excludes )
+    public void setExcludes( Set<String> excludes )
     {
         this.excludes = excludes;
     }
index d66027234f23605cc8186a14a0cdc211cda54c12..beb2071fecd162cedd4cce20e9895adef881ec27 100644 (file)
@@ -19,6 +19,10 @@ package org.apache.maven.archiva.dependency.graph;
  * under the License.
  */
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.Predicate;
 import org.apache.commons.collections.functors.AndPredicate;
@@ -33,11 +37,6 @@ import org.apache.maven.archiva.model.DependencyScope;
 import org.apache.maven.archiva.model.Exclusion;
 import org.apache.maven.archiva.model.VersionedReference;
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
 /**
  * Utilities for manipulating the DependencyGraph. 
  *
@@ -99,25 +98,18 @@ public class DependencyGraphUtils
 
         boolean isRootNode = graph.getRootNode().equals( fromNode );
 
-        Iterator it;
-
         if ( CollectionUtils.isNotEmpty( model.getDependencyManagement() ) )
         {
-            it = model.getDependencyManagement().iterator();
-            while ( it.hasNext() )
+            for ( Dependency dependency : model.getDependencyManagement() )
             {
-                Dependency dependency = (Dependency) it.next();
                 fromNode.addDependencyManagement( dependency );
             }
         }
 
         if ( CollectionUtils.isNotEmpty( model.getDependencies() ) )
         {
-            it = model.getDependencies().iterator();
-            while ( it.hasNext() )
+            for ( Dependency dependency : model.getDependencies() )
             {
-                Dependency dependency = (Dependency) it.next();
-
                 String scope = dependency.getScope();
 
                 // Test scopes *NOT* from root node can be skipped.
@@ -138,10 +130,8 @@ public class DependencyGraphUtils
 
                 if ( CollectionUtils.isNotEmpty( dependency.getExclusions() ) )
                 {
-                    Iterator itexclusion = dependency.getExclusions().iterator();
-                    while ( itexclusion.hasNext() )
+                    for ( Exclusion exclusion : dependency.getExclusions() )
                     {
-                        Exclusion exclusion = (Exclusion) itexclusion.next();
                         toNode.addExclude( exclusion );
                     }
                 }
@@ -198,12 +188,8 @@ public class DependencyGraphUtils
             }
 
             // Remove edges FROM orphaned node.
-            List edgesFrom = graph.getEdgesFrom( orphanedNode );
-
-            Iterator it = edgesFrom.iterator();
-            while ( it.hasNext() )
+            for ( DependencyGraphEdge edge : graph.getEdgesFrom( orphanedNode ) )
             {
-                DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
                 graph.removeEdge( edge );
             }
 
@@ -226,12 +212,10 @@ public class DependencyGraphUtils
      */
     public static void collapseNodes( DependencyGraph graph, DependencyGraphNode nodeFROM, DependencyGraphNode nodeTO )
     {
-        Iterator it;
-
-        Set edgesToRemove = new HashSet();
+        Set<DependencyGraphEdge> edgesToRemove = new HashSet<DependencyGraphEdge>();
 
         // 1) Remove all of the edge.from references from nodeFROM
-        List fromEdges = graph.getEdgesFrom( nodeFROM );
+        List<DependencyGraphEdge> fromEdges = graph.getEdgesFrom( nodeFROM );
         if ( CollectionUtils.isNotEmpty( fromEdges ) )
         {
             edgesToRemove.addAll( fromEdges );
@@ -240,12 +224,9 @@ public class DependencyGraphUtils
         // 2) Swing all of the edge.to references from nodeFROM to nodeTO.
         //        System.out.println( "Swinging incoming edges from " + nodeFROM );
         //        System.out.println( "                          to " + nodeTO );
-        List toEdges = graph.getEdgesTo( nodeFROM );
-        it = toEdges.iterator();
-        while ( it.hasNext() )
+        List<DependencyGraphEdge> toEdges = graph.getEdgesTo( nodeFROM );
+        for ( DependencyGraphEdge edge : toEdges )
         {
-            DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
-
             // Identify old edge to remove.
             edgesToRemove.add( edge );
 
@@ -258,10 +239,8 @@ public class DependencyGraphUtils
         }
 
         // Actually remove the old edges.
-        it = edgesToRemove.iterator();
-        while ( it.hasNext() )
+        for ( DependencyGraphEdge edge : edgesToRemove )
         {
-            DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
             graph.removeEdge( edge );
         }
 
index 35bc3aa0bce6e4680cb8d1c37327992733ba72cd..10750e43edcec4ab8e0959328372eccf74b21e55 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency.graph.tasks;
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
 import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
@@ -31,11 +34,6 @@ import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.model.VersionedReference;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Takes a stack of DependencyManagement objects and applies them to the node in question.
  * This merely sets the version / scope / and exclusions on the nodes, as defined by DependencyManagement.
@@ -58,7 +56,7 @@ public class DependencyManagementApplier
      * Performing graph changes of this scope during a walk of graph is hazardous,
      * as you will be moving nodes around, mergeing nodes, dropping edges, etc.
      */
-    private Map nodeVersionChanges = new HashMap();
+    private Map<ArtifactReference, String> nodeVersionChanges = new HashMap<ArtifactReference, String>();
 
     private int nodesAdded = 0;
 
@@ -76,11 +74,8 @@ public class DependencyManagementApplier
 
         depStack.push( node );
 
-        List edgesFrom = graph.getEdgesFrom( node );
-        Iterator it = edgesFrom.iterator();
-        while ( it.hasNext() )
+        for ( DependencyGraphEdge edge : graph.getEdgesFrom( node ) )
         {
-            DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
             Rules rules = depStack.getRules( edge );
 
             if ( rules == null )
@@ -137,11 +132,9 @@ public class DependencyManagementApplier
     {
         super.finishGraph( graph );
 
-        Iterator it = this.nodeVersionChanges.keySet().iterator();
-        while ( it.hasNext() )
+        for ( ArtifactReference ref : this.nodeVersionChanges.keySet() )
         {
-            ArtifactReference ref = (ArtifactReference) it.next();
-            String toVersion = (String) this.nodeVersionChanges.get( ref );
+            String toVersion = this.nodeVersionChanges.get( ref );
 
             collapseVersions( graph, ref, ref.getVersion(), toVersion );
         }
index 5f9d0a2daab6fb904ee3a7c507b7eacb1104a871..45c5233992a3f333ce2e2a773fb64f7f08fcbc2b 100644 (file)
@@ -19,6 +19,13 @@ package org.apache.maven.archiva.dependency.graph.tasks;
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
 import org.apache.commons.collections.iterators.ReverseListIterator;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
@@ -28,14 +35,6 @@ import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.model.Dependency;
 import org.apache.maven.archiva.model.Exclusion;
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-
 /**
  * DependencyManagementStack 
  *
@@ -49,23 +48,21 @@ public class DependencyManagementStack
 
         public String scope;
 
-        public Set exclusions = new HashSet();
+        public Set<String> exclusions = new HashSet<String>();
 
-        public void addAllExclusions( List depExclusions )
+        public void addAllExclusions( List<Exclusion> depExclusions )
         {
-            Iterator it = depExclusions.iterator();
-            while ( it.hasNext() )
+            for ( Exclusion ref : depExclusions )
             {
-                Exclusion ref = (Exclusion) it.next();
                 String key = DependencyGraphKeys.toManagementKey( ref );
                 exclusions.add( key );
             }
         }
     }
 
-    private Stack depmanStack = new Stack();
+    private Stack<DependencyGraphNode> depmanStack = new Stack<DependencyGraphNode>();
 
-    private Map depMap = new HashMap();
+    private Map<String, Rules> depMap = new HashMap<String, Rules>();
 
     private void generateDepMap()
     {
@@ -82,12 +79,10 @@ public class DependencyManagementStack
         }
     }
 
-    private void addDependencies( List dependencies )
+    private void addDependencies( List<Dependency> dependencies )
     {
-        Iterator it = dependencies.iterator();
-        while ( it.hasNext() )
+        for ( Dependency dep : dependencies )
         {
-            Dependency dep = (Dependency) it.next();
             String key = DependencyGraphKeys.toManagementKey( dep );
 
             Rules merged = (Rules) depMap.get( key );
index f49f8cb5f5d2519924f77de234ea43b039582817..df3d5e8105354896fdc3078e870190ea8260d884 100644 (file)
@@ -40,7 +40,7 @@ public class FlagCyclicEdgesVisitor
 {
     private DependencyGraphWalker walker;
 
-    private Set cyclicEdges = new HashSet();
+    private Set<DependencyGraphEdge> cyclicEdges = new HashSet<DependencyGraphEdge>();
 
     public FlagCyclicEdgesVisitor( DependencyGraphWalker walker )
     {
@@ -62,7 +62,7 @@ public class FlagCyclicEdgesVisitor
         }
     }
 
-    public Set getCyclicEdges()
+    public Set<DependencyGraphEdge> getCyclicEdges()
     {
         return cyclicEdges;
     }
index 804cdc3042eaffb9f511a849946ab7fc8736aa0b..a8829377e3054e51fc70461c47613834abe20115 100644 (file)
@@ -19,6 +19,8 @@ package org.apache.maven.archiva.dependency.graph.tasks;
  * under the License.
  */
 
+import java.util.Stack;
+
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
 import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
 import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
@@ -27,9 +29,6 @@ import org.apache.maven.archiva.dependency.graph.walk.BaseVisitor;
 import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
 import org.apache.maven.archiva.model.ArtifactReference;
 
-import java.util.Iterator;
-import java.util.Stack;
-
 /**
  * FlagExcludedEdgesVisitor 
  *
@@ -39,7 +38,7 @@ public class FlagExcludedEdgesVisitor
     extends BaseVisitor
     implements DependencyGraphVisitor
 {
-    private Stack nodePath = new Stack();
+    private Stack<DependencyGraphNode> nodePath = new Stack<DependencyGraphNode>();
 
     public void discoverEdge( DependencyGraphEdge edge )
     {
@@ -47,11 +46,8 @@ public class FlagExcludedEdgesVisitor
         
         // Process for excluded edges.
         String toKey = DependencyGraphKeys.toManagementKey( artifact );
-        Iterator it = this.nodePath.iterator();
-        while ( it.hasNext() )
+        for ( DependencyGraphNode pathNode : this.nodePath )
         {
-            DependencyGraphNode pathNode = (DependencyGraphNode) it.next();
-        
             // Process dependency declared exclusions.
             if ( pathNode.getExcludes().contains( toKey ) )
             {
index 9d753965d77d632357001bf7d556eeb3019fdf5b..fe5c5d2330a43bbf7cd44705f1cbaf128cb202d0 100644 (file)
@@ -19,20 +19,19 @@ package org.apache.maven.archiva.dependency.graph.tasks;
  * under the License.
  */
 
-import org.apache.maven.archiva.dependency.graph.DependencyGraph;
-import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
-import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
-import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
-import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.maven.archiva.dependency.graph.DependencyGraph;
+import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
+import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
+import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
+import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
+
 /**
  * Perform a transitive reduction of the graph. 
  *
@@ -50,21 +49,18 @@ public class ReduceTransitiveEdgesVisitor
     }
 
     class EdgeInfoDepthComparator
-        implements Comparator
+        implements Comparator<EdgeInfo>
     {
-        public int compare( Object obj0, Object obj1 )
+        public int compare( EdgeInfo obj0, EdgeInfo obj1 )
         {
-            EdgeInfo edgeInfo0 = (EdgeInfo) obj0;
-            EdgeInfo edgeInfo1 = (EdgeInfo) obj1;
-
-            return edgeInfo0.depth - edgeInfo1.depth;
+            return obj0.depth - obj1.depth;
         }
     }
 
     /**
      * A Map of &lt;(Node To) ArtifactReference, Map of &lt;(Node From) ArtifactReference, EdgeInfo&gt;&gt;
      */
-    private Map /*<ArtifactReference,<ArtifactReference,EdgeInfo>>*/nodeDistanceMap = new HashMap();
+    private Map<String, Map<String, EdgeInfo>> nodeDistanceMap = new HashMap<String, Map<String, EdgeInfo>>();
 
     private int currentDepth;
 
@@ -87,12 +83,12 @@ public class ReduceTransitiveEdgesVisitor
         String nodeFrom = DependencyGraphKeys.toKey( edge.getNodeFrom() );
 
         // Get sub-map
-        Map edgeInfoMap = (Map) nodeDistanceMap.get( nodeTo );
+        Map<String,EdgeInfo> edgeInfoMap = nodeDistanceMap.get( nodeTo );
 
         // Create sub-map if not present (yet)
         if ( edgeInfoMap == null )
         {
-            edgeInfoMap = new HashMap();
+            edgeInfoMap = new HashMap<String,EdgeInfo>();
             nodeDistanceMap.put( nodeTo, edgeInfoMap );
         }
 
@@ -136,16 +132,13 @@ public class ReduceTransitiveEdgesVisitor
 
         // Now we prune/remove the edges that are transitive in nature.
 
-        Comparator edgeInfoDepthComparator = new EdgeInfoDepthComparator();
+        Comparator<EdgeInfo> edgeInfoDepthComparator = new EdgeInfoDepthComparator();
 
-        Iterator it = nodeDistanceMap.values().iterator();
-        while ( it.hasNext() )
+        for ( Map<String, EdgeInfo> edgeInfoMap : nodeDistanceMap.values() )
         {
-            Map edgeInfoMap = (Map) it.next();
-
             if ( edgeInfoMap.size() > 1 )
             {
-                List edgeInfos = new ArrayList();
+                List<EdgeInfo> edgeInfos = new ArrayList<EdgeInfo>();
                 edgeInfos.addAll( edgeInfoMap.values() );
                 Collections.sort( edgeInfos, edgeInfoDepthComparator );
 
index 0c59fb4faea64a0cdf5e6f9ffc014e071e181fcb..6c08d4fca34a3484f1817602a9698d0b247c5023 100644 (file)
@@ -19,6 +19,12 @@ package org.apache.maven.archiva.dependency.graph.tasks;
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.map.MultiValueMap;
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
@@ -30,13 +36,6 @@ import org.apache.maven.archiva.dependency.graph.functors.ToArtifactReferenceTra
 import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphWalker;
 import org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
 /**
  * RefineConflictsTask 
  *
@@ -46,19 +45,17 @@ public class RefineConflictsTask
     implements GraphTask, PotentialCyclicEdgeProducer
 {
 
+    @SuppressWarnings("unchecked")
     public void executeTask( DependencyGraph graph )
     {
-        Iterator it;
         DependencyGraphWalker walker = new WalkDepthFirstSearch();
         RefineConflictsVisitor refineConflictsVisitor = new RefineConflictsVisitor();
         
         MultiValueMap depMap = new MultiValueMap();
 
         // Identify deps that need to be resolved.
-        it = graph.getNodes().iterator();
-        while ( it.hasNext() )
+        for ( DependencyGraphNode node : graph.getNodes() )
         {
-            DependencyGraphNode node = (DependencyGraphNode) it.next();
             String key = DependencyGraphKeys.toManagementKey( node.getArtifact() );
             // This will add this node to the specified key, not replace a previous one.
             depMap.put( key, node );
@@ -67,14 +64,14 @@ public class RefineConflictsTask
         // Process those depMap entries with more than 1 value. 
         ToArtifactReferenceTransformer nodeToArtifact = new ToArtifactReferenceTransformer();
 
-        it = depMap.entrySet().iterator();
+        Iterator<Map.Entry<String,Collection<DependencyGraphNode>>> it = depMap.entrySet().iterator();
         while ( it.hasNext() )
         {
-            Map.Entry entry = (Entry) it.next();
-            Collection nodes = (Collection) entry.getValue();
+            Map.Entry<String,Collection<DependencyGraphNode>> entry = it.next();
+            Collection<DependencyGraphNode> nodes = entry.getValue();
             if ( nodes.size() > 1 )
             {
-                List conflictingArtifacts = new ArrayList();
+                List<DependencyGraphNode> conflictingArtifacts = new ArrayList<DependencyGraphNode>();
                 conflictingArtifacts.addAll( nodes );
                 CollectionUtils.transform( conflictingArtifacts, nodeToArtifact );
 
index b149ded6fdbdd2306147234ba935f3de90224664..158edaa59f7ab134188bb817ca12c2ef407c4f1d 100644 (file)
@@ -19,6 +19,16 @@ package org.apache.maven.archiva.dependency.graph.tasks;
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.collections.Predicate;
@@ -35,17 +45,6 @@ import org.apache.maven.archiva.dependency.graph.walk.BaseVisitor;
 import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
 import org.apache.maven.archiva.model.ArtifactReference;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * RefineConflictsVisitor 
  *
@@ -56,14 +55,11 @@ public class RefineConflictsVisitor
     implements DependencyGraphVisitor
 {
     class DepthComparator
-        implements Comparator
+        implements Comparator<NodeLocation>
     {
-        public int compare( Object obj0, Object obj1 )
+        public int compare( NodeLocation obj0, NodeLocation obj1 )
         {
-            NodeLocation nodeLoc0 = (NodeLocation) obj0;
-            NodeLocation nodeLoc1 = (NodeLocation) obj1;
-
-            return nodeLoc0.depth - nodeLoc1.depth;
+            return obj0.depth - obj1.depth;
         }
     }
 
@@ -114,9 +110,9 @@ public class RefineConflictsVisitor
     }
 
     class NodeLocationVersionComparator
-        implements Comparator
+        implements Comparator<NodeLocation>
     {
-        public int compare( Object o1, Object o2 )
+        public int compare( NodeLocation o1, NodeLocation o2 )
         {
             if ( o1 == null && o2 == null )
             {
@@ -133,15 +129,10 @@ public class RefineConflictsVisitor
                 return -1;
             }
 
-            if ( ( o1 instanceof NodeLocation ) && ( o2 instanceof NodeLocation ) )
-            {
-                String version1 = ( (NodeLocation) o1 ).artifact.getVersion();
-                String version2 = ( (NodeLocation) o2 ).artifact.getVersion();
-
-                VersionComparator.getInstance().compare( version1, version2 );
-            }
+            String version1 = o1.artifact.getVersion();
+            String version2 = o2.artifact.getVersion();
 
-            return 0;
+            return VersionComparator.getInstance().compare( version1, version2 );
         }
     }
 
@@ -169,17 +160,18 @@ public class RefineConflictsVisitor
         }
     }
 
-    private List conflictingArtifacts;
+    private List<DependencyGraphNode> conflictingArtifacts;
 
-    private Map foundNodesMap = new HashMap();
+    private Map<String,NodeLocation> foundNodesMap = new HashMap<String, NodeLocation>();
 
     private int currentDepth = 0;
 
     private DependencyGraph currentGraph;
 
+    @SuppressWarnings("unchecked")
     public RefineConflictsVisitor()
     {
-        conflictingArtifacts = TypedList.decorate( new ArrayList(), ArtifactReference.class );
+        conflictingArtifacts = TypedList.decorate( new ArrayList<ArtifactReference>(), ArtifactReference.class );
     }
 
     public void discoverGraph( DependencyGraph graph )
@@ -195,16 +187,14 @@ public class RefineConflictsVisitor
 
         currentDepth++;
 
-        List edgesFrom = currentGraph.getEdgesFrom( node );
-        Iterator it = edgesFrom.iterator();
-        while ( it.hasNext() )
+        List<DependencyGraphEdge> edgesFrom = currentGraph.getEdgesFrom( node );
+        for ( DependencyGraphEdge edge : edgesFrom )
         {
-            DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
             if ( this.conflictingArtifacts.contains( edge.getNodeTo() ) )
             {
                 String nodeKey = DependencyGraphKeys.toKey( edge.getNodeTo() );
                 // Check for existing NodeLocation with same key
-                NodeLocation nodeloc = (NodeLocation) this.foundNodesMap.get( nodeKey );
+                NodeLocation nodeloc = this.foundNodesMap.get( nodeKey );
 
                 if ( ( nodeloc == null ) || ( currentDepth < nodeloc.depth ) )
                 {
@@ -229,23 +219,22 @@ public class RefineConflictsVisitor
         DependencyGraphNode winningNode = graph.getNode( winningArtifact );
 
         // Gather up Losing Nodes.
-        Set losingNodes = new HashSet();
+        Set<NodeLocation> losingNodes = new HashSet<NodeLocation>();
         Predicate losersPredicate = NotPredicate.getInstance( new NodeLocationPredicate( winningArtifact ) );
         CollectionUtils.select( this.foundNodesMap.values(), losersPredicate, losingNodes );
 
         // Swing losing nodes to winning node.
-        Iterator it = losingNodes.iterator();
-        while ( it.hasNext() )
+        for ( NodeLocation losingNodeLoc : losingNodes )
         {
-            NodeLocation losingNodeLoc = (NodeLocation) it.next();
             DependencyGraphNode losingNode = graph.getNode( losingNodeLoc.artifact );
             DependencyGraphUtils.collapseNodes( graph, losingNode, winningNode );
         }
     }
 
-    private ArtifactReference findWinningArtifact( Collection nodes )
+    @SuppressWarnings("unchecked")
+    private ArtifactReference findWinningArtifact( Collection<NodeLocation> nodes )
     {
-        List remainingNodes = new ArrayList();
+        List<NodeLocation> remainingNodes = new ArrayList<NodeLocation>();
         remainingNodes.addAll( nodes );
 
         /* .\ Filter by Depth \.____________________________________________________ */
@@ -254,7 +243,7 @@ public class RefineConflictsVisitor
         Collections.sort( remainingNodes, new DepthComparator() );
 
         // Determine 'closest' node depth.
-        NodeLocation nearestNode = (NodeLocation) remainingNodes.get( 0 );
+        NodeLocation nearestNode = remainingNodes.get( 0 );
         int nearest = nearestNode.depth;
 
         // Filter out distant nodes. 
@@ -265,7 +254,7 @@ public class RefineConflictsVisitor
         if ( remainingNodes.size() == 1 )
         {
             // A winner!
-            NodeLocation nodeloc = (NodeLocation) remainingNodes.get( 0 );
+            NodeLocation nodeloc = remainingNodes.get( 0 );
             return nodeloc.artifact;
         }
 
@@ -275,7 +264,7 @@ public class RefineConflictsVisitor
         // Determine which one is 'newest' based on version id.
         Collections.sort( remainingNodes, new ReverseComparator( new NodeLocationVersionComparator() ) );
 
-        NodeLocation nodeloc = (NodeLocation) remainingNodes.get( 0 );
+        NodeLocation nodeloc = remainingNodes.get( 0 );
         return nodeloc.artifact;
     }
 
@@ -285,12 +274,12 @@ public class RefineConflictsVisitor
         currentDepth--;
     }
 
-    public List getConflictingArtifacts()
+    public List<DependencyGraphNode> getConflictingArtifacts()
     {
         return conflictingArtifacts;
     }
 
-    public void addAllConflictingArtifacts( Collection nodes )
+    public void addAllConflictingArtifacts( Collection<DependencyGraphNode> nodes )
     {
         this.conflictingArtifacts.addAll( nodes );
     }
index d4affcefac789951bb1ed4cbdc176bb5a6af55c1..88951decf597a063781bd6de60cb6cfb0de95478 100644 (file)
@@ -38,13 +38,13 @@ public class UpdateScopesVisitor
     extends BaseVisitor
     implements DependencyGraphVisitor
 {
-    private Stack scopeStack;
+    private Stack<String> scopeStack;
 
     private Predicate rootEdgePredicate;
 
     public UpdateScopesVisitor()
     {
-        scopeStack = new Stack();
+        scopeStack = new Stack<String>();
         // Default setting.
         scopeStack.add( DependencyScope.COMPILE );
     }
index 96799496319b90caba3fba008ba53ae06cc2e688..60650c35ce4dcf984b0a14f44053e6f151e9845f 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency.graph.walk;
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.commons.collections.Predicate;
 import org.apache.commons.collections.functors.NotPredicate;
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
@@ -27,10 +30,6 @@ import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
 import org.apache.maven.archiva.dependency.graph.functors.EdgeDisabledPredicate;
 import org.apache.maven.archiva.model.ArtifactReference;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
 /**
  * WalkBreadthFirstSearch 
  *
@@ -39,7 +38,7 @@ import java.util.Map;
 public class WalkBreadthFirstSearch
     implements DependencyGraphWalker
 {
-    private Map nodeVisitStates = new HashMap();
+    private Map<ArtifactReference, Integer> nodeVisitStates = new HashMap<ArtifactReference, Integer>();
 
     private Predicate edgePredicate;
 
@@ -98,12 +97,9 @@ public class WalkBreadthFirstSearch
 
         visitor.discoverNode( node );
 
-        Iterator edges;
         // First dive down edges.
-        edges = graph.getEdgesFrom( node ).iterator();
-        while ( edges.hasNext() )
+        for ( DependencyGraphEdge e : graph.getEdgesFrom( node ) )
         {
-            DependencyGraphEdge e = (DependencyGraphEdge) edges.next();
             if ( this.edgePredicate.evaluate( e ) )
             {
                 visitEdge( graph, e, visitor );
@@ -111,11 +107,8 @@ public class WalkBreadthFirstSearch
         }
 
         // Next move down edges.
-        edges = graph.getEdgesFrom( node ).iterator();
-        while ( edges.hasNext() )
+        for ( DependencyGraphEdge e : graph.getEdgesFrom( node ) )
         {
-            DependencyGraphEdge e = (DependencyGraphEdge) edges.next();
-
             if ( this.edgePredicate.evaluate( e ) )
             {
                 DependencyGraphNode nodeTo = graph.getNode( e.getNodeTo() );
@@ -141,10 +134,9 @@ public class WalkBreadthFirstSearch
     {
         nodeVisitStates.clear();
 
-        Iterator nodes = graph.getNodes().iterator();
-        while ( nodes.hasNext() )
+        for ( DependencyGraphNode node : graph.getNodes() )
         {
-            setNodeVisitState( (DependencyGraphNode) nodes.next(), UNSEEN );
+            setNodeVisitState( node, UNSEEN );
         }
 
         visitor.discoverGraph( graph );
index d542819dc2b7531ce715af97b371cbe2ea4e7df4..603ec09e4d9b389229f361f74aebeb224f3a5712 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency.graph.walk;
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.commons.collections.Predicate;
 import org.apache.commons.collections.functors.NotPredicate;
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
@@ -27,10 +30,6 @@ import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
 import org.apache.maven.archiva.dependency.graph.functors.EdgeDisabledPredicate;
 import org.apache.maven.archiva.model.ArtifactReference;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
 /**
  * Perform a walk of the graph using the DepthFirstSearch algorithm.
  * 
@@ -41,7 +40,7 @@ import java.util.Map;
 public class WalkDepthFirstSearch
     implements DependencyGraphWalker
 {
-    private Map nodeVisitStates = new HashMap();
+    private Map<ArtifactReference, Integer> nodeVisitStates = new HashMap<ArtifactReference, Integer>();
 
     private Predicate edgePredicate;
 
@@ -105,10 +104,8 @@ public class WalkDepthFirstSearch
 
         visitor.discoverNode( node );
 
-        Iterator edges = graph.getEdgesFrom( node ).iterator();
-        while ( edges.hasNext() )
+        for ( DependencyGraphEdge e : graph.getEdgesFrom( node ) )
         {
-            DependencyGraphEdge e = (DependencyGraphEdge) edges.next();
             if ( this.edgePredicate.evaluate( e ) )
             {
                 visitEdge( graph, e, visitor );
@@ -129,10 +126,9 @@ public class WalkDepthFirstSearch
     {
         nodeVisitStates.clear();
 
-        Iterator nodes = graph.getNodes().iterator();
-        while ( nodes.hasNext() )
+        for ( DependencyGraphNode node : graph.getNodes() )
         {
-            setNodeVisitState( (DependencyGraphNode) nodes.next(), UNSEEN );
+            setNodeVisitState( node, UNSEEN );
         }
 
         visitor.discoverGraph( graph );
index 8bc4b7bfd799c47a13ddf86414ecac9c1c4501d0..1413b36cef06569ca0ea369789334dec3d368375 100644 (file)
@@ -19,6 +19,10 @@ package org.apache.maven.archiva.dependency.graph;
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.Predicate;
 import org.apache.commons.collections.functors.AndPredicate;
@@ -35,11 +39,6 @@ import org.apache.maven.archiva.model.Dependency;
 import org.apache.maven.archiva.model.VersionedReference;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * AbstractDependencyGraphFactoryTestCase 
  *
@@ -91,12 +90,12 @@ public abstract class AbstractDependencyGraphFactoryTestCase
         }
     }
 
-    protected void assertDirectNodes( DependencyGraph graph, List expectedNodes, String scope )
+    @SuppressWarnings("unchecked")
+    protected void assertDirectNodes( DependencyGraph graph, List<DependencyGraphNode> expectedNodes, String scope )
     {
-        Iterator it;
         DependencyGraphNode rootNode = graph.getRootNode();
-        List rootEdges = graph.getEdgesFrom( rootNode );
-        List actualEdges = new ArrayList();
+        List<DependencyGraphEdge> rootEdges = graph.getEdgesFrom( rootNode );
+        List<DependencyGraphEdge> actualEdges = new ArrayList<DependencyGraphEdge>();
 
         Predicate directDep = NotPredicate.getInstance( new NodeFromParentPredicate() );
         Predicate scopedDirectDeps = AndPredicate.getInstance( new EdgeExactScopePredicate( scope ), directDep );
@@ -114,42 +113,36 @@ public abstract class AbstractDependencyGraphFactoryTestCase
 
             CollectionUtils.transform( actualEdges, new ToKeyTransformer() );
 
-            Collection missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
-            it = missingActualKeys.iterator();
-            while ( it.hasNext() )
+            Collection<String> missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
+            for ( String key : missingActualKeys )
             {
-                sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+                sb.append( "\n (Extra Actual) " ).append( key );
             }
 
-            Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
-            it = missingExpectedKeys.iterator();
-            while ( it.hasNext() )
+            Collection<String> missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
+            for ( String key : missingExpectedKeys )
             {
-                sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+                sb.append( "\n (Extra Expected) " ).append( key );
             }
 
             fail( sb.toString() );
         }
 
-        it = actualEdges.iterator();
-        while ( it.hasNext() )
+        for ( DependencyGraphEdge edge : actualEdges )
         {
-            DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
             String actualKey = DependencyGraphKeys.toKey( edge.getNodeTo() );
             assertTrue( "Direct <" + scope + "> node To [" + actualKey + "] exists in expectedNodes.", expectedNodes
                 .contains( actualKey ) );
         }
     }
 
-    protected void assertEdges( DependencyGraph graph, List expectedEdges )
+    protected void assertEdges( DependencyGraph graph, List<ExpectedEdge> expectedEdges )
     {
         assertNotNull( "Graph.edges should never be null.", graph.getEdges() );
         assertEquals( "Graph.edges.size()", expectedEdges.size(), graph.getEdges().size() );
 
-        Iterator it = expectedEdges.iterator();
-        while ( it.hasNext() )
+        for ( ExpectedEdge expectedEdge : expectedEdges )
         {
-            ExpectedEdge expectedEdge = (ExpectedEdge) it.next();
             Predicate edgePredicate = new GraphEdgePredicate( expectedEdge.from, expectedEdge.to );
 
             DependencyGraphEdge edge = (DependencyGraphEdge) CollectionUtils.find( graph.getEdges(), edgePredicate );
@@ -160,6 +153,7 @@ public abstract class AbstractDependencyGraphFactoryTestCase
         }
     }
 
+    @SuppressWarnings("unchecked")
     protected void assertGraph( DependencyGraph graph, String rootRefKey, List expectedNodeKeys )
     {
         assertNotNull( "Graph.nodes should never be null.", graph.getNodes() );
@@ -173,8 +167,7 @@ public abstract class AbstractDependencyGraphFactoryTestCase
 
         assertEquals( "Graph.root", rootRefKey, actualRootRef.toString() );
 
-        Iterator it;
-        List actualNodes = new ArrayList();
+        List<DependencyGraphNode> actualNodes = new ArrayList<DependencyGraphNode>();
 
         Predicate notRootNode = NotPredicate.getInstance( new NodePredicate( graph.getRootNode() ) );
         CollectionUtils.select( graph.getNodes(), notRootNode, actualNodes );
@@ -192,19 +185,17 @@ public abstract class AbstractDependencyGraphFactoryTestCase
 
         CollectionUtils.transform( actualNodes, new ToKeyTransformer() );
 
-        Collection missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
-        it = missingActualKeys.iterator();
-        while ( it.hasNext() )
+        Collection<DependencyGraphNode> missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
+        for ( DependencyGraphNode key : missingActualKeys )
         {
-            sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+            sb.append( "\n (Extra Actual) " ).append( key );
             fail = true;
         }
 
-        Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
-        it = missingExpectedKeys.iterator();
-        while ( it.hasNext() )
+        Collection<DependencyGraphNode> missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
+        for ( DependencyGraphNode key : missingExpectedKeys )
         {
-            sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+            sb.append( "\n (Extra Expected) " ).append( key );
             fail = true;
         }
 
@@ -226,14 +217,14 @@ public abstract class AbstractDependencyGraphFactoryTestCase
         */
     }
 
-    protected void assertNodes( DependencyGraph graph, List expectedNodeKeys )
+    @SuppressWarnings("unchecked")
+    protected void assertNodes( DependencyGraph graph, List<String> expectedNodeKeys )
     {
         assertNotNull( "Graph.nodes should never be null.", graph.getNodes() );
         assertTrue( "Graph.nodes.size() should always be 1 or better.", graph.getNodes().size() >= 1 );
         // assertEquals( "Graph.nodes.size()", expectedNodeKeys.size(), graph.getNodes().size() );
 
-        Iterator it;
-        List actualNodes = new ArrayList();
+        List<DependencyGraphNode> actualNodes = new ArrayList<DependencyGraphNode>();
         actualNodes.addAll( graph.getNodes() );
 
         if ( expectedNodeKeys.size() != actualNodes.size() )
@@ -246,27 +237,23 @@ public abstract class AbstractDependencyGraphFactoryTestCase
 
             CollectionUtils.transform( actualNodes, new ToKeyTransformer() );
 
-            Collection missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
-            it = missingActualKeys.iterator();
-            while ( it.hasNext() )
+            Collection<DependencyGraphNode> missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
+            for ( DependencyGraphNode key : missingActualKeys )
             {
-                sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+                sb.append( "\n (Extra Actual) " ).append( key );
             }
 
-            Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
-            it = missingExpectedKeys.iterator();
-            while ( it.hasNext() )
+            Collection<String> missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
+            for ( String key : missingExpectedKeys )
             {
-                sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+                sb.append( "\n (Extra Expected) " ).append( key );
             }
 
             fail( sb.toString() );
         }
 
-        it = graph.getNodes().iterator();
-        while ( it.hasNext() )
+        for ( DependencyGraphNode node : graph.getNodes() )
         {
-            DependencyGraphNode node = (DependencyGraphNode) it.next();
             assertNotNull( "Artifact reference in node should not be null.", node.getArtifact() );
             String key = ArtifactReference.toKey( node.getArtifact() );
             assertTrue( "Artifact reference [" + key + "] should be in expectedNodeKeys.", expectedNodeKeys
@@ -282,12 +269,11 @@ public abstract class AbstractDependencyGraphFactoryTestCase
         assertEquals( "Root Node", expectedKey, actualKey );
     }
 
-    protected void assertTransientNodes( DependencyGraph graph, List expectedNodes, String scope )
+    @SuppressWarnings("unchecked")
+    protected void assertTransientNodes( DependencyGraph graph, List<DependencyGraphNode> expectedNodes, String scope )
     {
-        Iterator it;
-
         // Gather up the transient nodes from the DependencyGraph.
-        List actualEdges = new ArrayList();
+        ArrayList<DependencyGraphEdge> actualEdges = new ArrayList<DependencyGraphEdge>();
 
         DependencyGraphNode rootNode = graph.getRootNode();
 
@@ -308,27 +294,23 @@ public abstract class AbstractDependencyGraphFactoryTestCase
 
             CollectionUtils.transform( actualEdges, new ToKeyTransformer() );
 
-            Collection missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
-            it = missingActualKeys.iterator();
-            while ( it.hasNext() )
+            Collection<DependencyGraphNode> missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
+            for ( DependencyGraphNode key : missingActualKeys )
             {
-                sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+                sb.append( "\n (Extra Actual) " ).append( key );
             }
 
-            Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
-            it = missingExpectedKeys.iterator();
-            while ( it.hasNext() )
+            Collection<DependencyGraphNode> missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
+            for ( DependencyGraphNode key : missingExpectedKeys )
             {
-                sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+                sb.append( "\n (Extra Expected) " ).append( key );
             }
 
             fail( sb.toString() );
         }
 
-        it = actualEdges.iterator();
-        while ( it.hasNext() )
+        for ( DependencyGraphEdge edge : actualEdges )
         {
-            DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
             String actualKey = DependencyGraphKeys.toKey( edge.getNodeTo() );
             assertTrue( "Transient Node To [" + actualKey + "] exists in expectedNodes.", expectedNodes
                 .contains( actualKey ) );
index f1671aa8356686ed6a2f0d53e8890519a7b8eb35..9dbd4af820312c94d9cdf4ae970a26ba5f438319 100644 (file)
@@ -19,21 +19,20 @@ package org.apache.maven.archiva.dependency.graph;
  * under the License.
  */
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.model.ArchivaProjectModel;
-import org.apache.maven.archiva.model.Dependency;
-import org.apache.maven.archiva.model.Exclusion;
-import org.apache.maven.archiva.model.Keys;
-import org.apache.maven.archiva.model.VersionedReference;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.Dependency;
+import org.apache.maven.archiva.model.Exclusion;
+import org.apache.maven.archiva.model.Keys;
+import org.apache.maven.archiva.model.VersionedReference;
+
 /**
  * AbstractMemoryRepository 
  *
@@ -42,7 +41,7 @@ import java.util.Map;
 public abstract class AbstractMemoryRepository
     implements MemoryRepository
 {
-    private Map modelMap = new HashMap();
+    private Map<String,ArchivaProjectModel> modelMap = new HashMap<String, ArchivaProjectModel>();
 
     public AbstractMemoryRepository()
     {
@@ -112,12 +111,12 @@ public abstract class AbstractMemoryRepository
 
     protected ArchivaProjectModel toModel( String key )
     {
-        return toModel( key, Collections.EMPTY_LIST );
+        return toModel( key, Collections.<Dependency>emptyList() );
     }
 
-    protected ArchivaProjectModel toModel( String key, Dependency deps[] )
+    protected ArchivaProjectModel toModel( String key, Dependency[] deps )
     {
-        List depList = new ArrayList();
+        List<Dependency> depList = new ArrayList<Dependency>();
 
         if ( deps != null )
         {
@@ -127,7 +126,7 @@ public abstract class AbstractMemoryRepository
         return toModel( key, depList );
     }
 
-    protected ArchivaProjectModel toModel( String key, List deps )
+    protected ArchivaProjectModel toModel( String key, List<Dependency> deps )
     {
         String parts[] = StringUtils.splitPreserveAllTokens( key, ':' );
 
@@ -144,10 +143,8 @@ public abstract class AbstractMemoryRepository
         model.setOrigin( "testcase" );
         model.setPackaging( "jar" );
 
-        Iterator it = deps.iterator();
-        while ( it.hasNext() )
+        for ( Dependency dep : deps )
         {
-            Dependency dep = (Dependency) it.next();
             model.addDependency( dep );
         }
 
index 26a598127b8a572bbb410666518047ee70c5b9f1..5f79f40c5ce3ffe0df7318c37085ce91f4688593 100644 (file)
@@ -60,7 +60,7 @@ public class ArchivaCommonDependencyGraphTest
       assertNotNull( "Graph shouldn't be null.", graph );
 
       String expectedRootRef = "org.apache.maven.archiva:archiva-common:1.0-alpha-2-SNAPSHOT";
-      List expectedNodes = new ArrayList();
+      List<String> expectedNodes = new ArrayList<String>();
 
       // Check for all nodes, regardless of scope.
       expectedNodes.clear();
index b3bb2a1fad1836478bf2e54055c40ce1e9b19c15..eef7732951007ec23e437a8c9e75a0fa9e358275 100644 (file)
@@ -60,7 +60,7 @@ public class ArchivaWebappDependencyGraphTest
       assertNotNull( "Graph shouldn't be null.", graph );
 
       String expectedRootRef = "org.apache.maven.archiva:archiva-webapp:1.0-alpha-2-SNAPSHOT";
-      List expectedNodes = new ArrayList();
+      List<String> expectedNodes = new ArrayList<String>();
 
       // Check for all nodes, regardless of scope.
       expectedNodes.clear();
index 6733b8900a78ccc50484f3e8735d53de6d0c46e7..ceed2135dde73bc202c3eb93a842e0c3b3a823f2 100644 (file)
@@ -60,7 +60,7 @@ public class ArchivaXmlToolsDependencyGraphTest
       assertNotNull( "Graph shouldn't be null.", graph );
 
       String expectedRootRef = "org.apache.maven.archiva:archiva-xml-tools:1.0-alpha-2-SNAPSHOT";
-      List expectedNodes = new ArrayList();
+      List<String> expectedNodes = new ArrayList<String>();
 
       // Check for all nodes, regardless of scope.
       expectedNodes.clear();
index e55bf17d16e8cfb1ccfd9b76ed12aa104977c2b0..13715e0bcbb1ead0df9271c77a8b0c9897c3ec29 100644 (file)
@@ -60,7 +60,7 @@ public class ContinuumStoreDependencyGraphTest
       assertNotNull( "Graph shouldn't be null.", graph );
 
       String expectedRootRef = "org.apache.maven.continuum:continuum-store:1.1-SNAPSHOT";
-      List expectedNodes = new ArrayList();
+      List<String> expectedNodes = new ArrayList<String>();
 
       // Check for all nodes, regardless of scope.
       expectedNodes.clear();
index fa5b32f11cf61693f8f297daf70d387c1eb88738..1d043e9ea0a0efd90ad7c075feb3c080bafb5b68 100644 (file)
@@ -58,7 +58,7 @@ public class DepManDeepVersionDependencyGraphTest
         assertNotNull( "Graph shouldn't be null.", graph );
 
         String expectedRootRef = "net.example.depman.deepversion:A:1.0";
-        List expectedNodes = new ArrayList();
+        List<String> expectedNodes = new ArrayList<String>();
 
         // Check for all nodes, regardless of scope.
         expectedNodes.clear();
index 3e7d29e1058149f1faeba4a373ccfbedbff5febf..f9bdb884f108596a9f6b3fb4e30f01ccef60127a 100644 (file)
@@ -19,7 +19,13 @@ package org.apache.maven.archiva.dependency.graph;
  * under the License.
  */
 
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
 import junit.framework.Assert;
+
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
@@ -27,13 +33,6 @@ import org.apache.maven.archiva.dependency.DependencyGraphFactory;
 import org.apache.maven.archiva.model.DependencyScope;
 import org.apache.maven.archiva.model.VersionedReference;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * GraphvizDotTool - testing utility to help understand the graph. 
  *
@@ -178,21 +177,13 @@ public class GraphvizDotTool
             dot.println( "    fontsize=\"11\"," );
             dot.println( "  ];" );
 
-            Iterator it;
-
-            it = graph.getNodes().iterator();
-            while ( it.hasNext() )
+            for ( DependencyGraphNode node : graph.getNodes() )
             {
-                DependencyGraphNode node = (DependencyGraphNode) it.next();
-
                 writeNode( dot, graph, node );
             }
 
-            it = graph.getEdges().iterator();
-            while ( it.hasNext() )
+            for ( DependencyGraphEdge edge : graph.getEdges() )
             {
-                DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
-
                 DependencyGraphNode from = graph.getNode( edge.getNodeFrom() );
                 DependencyGraphNode to = graph.getNode( edge.getNodeTo() );
 
@@ -250,8 +241,7 @@ public class GraphvizDotTool
         dot.println( "  \"" + toId( node ) + "\" [" );
         dot.println( "    label=\"" + toLabel( node ) + "\"," );
 
-        List edgesTo = graph.getEdgesTo( node );
-        boolean orphan = CollectionUtils.isEmpty( edgesTo );
+        boolean orphan = CollectionUtils.isEmpty( graph.getEdgesTo( node ) );
 
         if ( node.isFromParent() )
         {
index b11c78c40e872987f323e8c11624fcd77b576cea..dd084e31de8e5525bd95e501f70d851fd1838e85 100644 (file)
@@ -19,13 +19,13 @@ package org.apache.maven.archiva.dependency.graph;
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.maven.archiva.dependency.DependencyGraphFactory;
 import org.apache.maven.archiva.model.DependencyScope;
 import org.apache.maven.archiva.model.VersionedReference;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * SimpleDependencyGraphTest 
  *
@@ -54,13 +54,13 @@ public class SimpleDependencyGraphTest
         // Test the results.
         assertNotNull( "Graph shouldn't be null.", graph );
 
-        List expectedNodes = new ArrayList();
+        List<String> expectedNodes = new ArrayList<String>();
         expectedNodes.add( "org.apache.maven.archiva:archiva-commons:1.0::pom" );
         expectedNodes.add( "org.codehaus.plexus:plexus-digest:1.0::jar" );
         expectedNodes.add( "junit:junit:3.8.1::jar" );
         assertNodes( graph, expectedNodes );
 
-        List expectedEdges = new ArrayList();
+        List<ExpectedEdge> expectedEdges = new ArrayList<ExpectedEdge>();
         expectedEdges.add( new ExpectedEdge( "org.apache.maven.archiva:archiva-commons:1.0::pom",
                                              "org.codehaus.plexus:plexus-digest:1.0::jar" ) );
         expectedEdges.add( new ExpectedEdge( "org.codehaus.plexus:plexus-digest:1.0::jar", "junit:junit:3.8.1::jar" ) );
index 3fcc04c4f2111d9bd3149734acce9fdcad04ff11..432b2a43c13c8929d4a489622c973822eaced13c 100644 (file)
@@ -60,7 +60,7 @@ public class WagonManagerDependencyGraphTest
       assertNotNull( "Graph shouldn't be null.", graph );
 
       String expectedRootRef = "org.apache.maven.wagon:wagon-manager:2.0-SNAPSHOT";
-      List expectedNodes = new ArrayList();
+      List<String> expectedNodes = new ArrayList<String>();
 
       // Check for all nodes, regardless of scope.
       expectedNodes.clear();
index 3026ed02d488c2ad1126773992b66301b559c9d5..7c2d4128686297c263db995bc875da40cf1c65fc 100644 (file)
@@ -175,13 +175,13 @@ public class DependencyGraphWalkerTest
         }
     }
 
-    private void assertPath( String[] expectedPath, List collectedPath )
+    private void assertPath( String[] expectedPath, List<String> collectedPath )
     {
         assertEquals( "Path.length", expectedPath.length, collectedPath.size() );
 
         for ( int i = 0; i < expectedPath.length; i++ )
         {
-            assertEquals( "Walk path[" + i + "]", expectedPath[i], (String) collectedPath.get( i ) );
+            assertEquals( "Walk path[" + i + "]", expectedPath[i], collectedPath.get( i ) );
         }
     }
 
index c07f1a7cb8e25fc4a179c7b1f37ce109641f94e7..ff3a69c6f1e46b791514ce42186f66ab36caa101 100644 (file)
@@ -30,7 +30,7 @@ import java.util.List;
 class WalkCollector
     implements DependencyGraphVisitor
 {
-    private List walkPath = new ArrayList();
+    private List<String> walkPath = new ArrayList<String>();
 
     private int countDiscoverGraph = 0;
 
@@ -75,7 +75,7 @@ class WalkCollector
         countFinishNode++;
     }
 
-    public List getCollectedPath()
+    public List<String> getCollectedPath()
     {
         return walkPath;
     }