Upgrade to Jung 2.1.1 59/70059/2
authorStephen Kitt <skitt@redhat.com>
Sun, 25 Mar 2018 18:50:33 +0000 (11:50 -0700)
committerStephen Kitt <skitt@redhat.com>
Sun, 25 Mar 2018 19:03:03 +0000 (12:03 -0700)
This drops the dependency on collections-generic, and allows the
project to pull its Jung dependencies from odlparent.

Change-Id: I7d9f03e24fb6c67853ba2be4c3e4e010d71cccbd
Signed-off-by: Stephen Kitt <skitt@redhat.com>
nemo-impl/pom.xml
nemo-impl/src/main/java/org/opendaylight/nemo/intent/algorithm/RoutingAlgorithm.java
nemo-impl/src/test/java/org/opendaylight/nemo/intent/algorithm/RoutingAlgorithmTest.java

index 65f13813f5b74f93490c5948d0fcc966f3c916ae..6da8bfbcb38c9a382024843507cd42e98d064c20 100644 (file)
@@ -59,25 +59,17 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>nemo-api</artifactId>
       <version>${project.version}</version>
     </dependency>
-    <dependency>
-      <groupId>net.sourceforge.collections</groupId>
-      <artifactId>collections-generic</artifactId>
-      <version>4.01</version>
-    </dependency>
     <dependency>
       <groupId>net.sf.jung</groupId>
       <artifactId>jung-api</artifactId>
-      <version>2.0.1</version>
     </dependency>
     <dependency>
       <groupId>net.sf.jung</groupId>
       <artifactId>jung-graph-impl</artifactId>
-      <version>2.0.1</version>
     </dependency>
     <dependency>
       <groupId>net.sf.jung</groupId>
       <artifactId>jung-algorithms</artifactId>
-      <version>2.0.1</version>
     </dependency>
     <dependency>
       <groupId>com.google.guava</groupId>
index 86a02999dede34b42b0b6e59daef9b56bc98a3e5..887258d38b09dd04e815791f6d5b5c7333182243 100644 (file)
@@ -13,8 +13,6 @@ import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
 import edu.uci.ics.jung.graph.DirectedSparseGraph;\r
 import edu.uci.ics.jung.graph.Graph;\r
 import edu.uci.ics.jung.graph.util.EdgeType;\r
-import org.apache.commons.collections15.Predicate;\r
-import org.apache.commons.collections15.Transformer;\r
 \r
 import java.util.Collection;\r
 import java.util.List;\r
@@ -28,26 +26,13 @@ public class RoutingAlgorithm {
     /**\r
      * The current network topology graph.\r
      */\r
-    private Graph<Vertex, Edge> graph;\r
+    private final Graph<Vertex, Edge> graph = new DirectedSparseGraph<>();\r
 \r
     /**\r
      * The Dijkstra shortest path algorithm instance.\r
      */\r
-    private DijkstraShortestPath<Vertex, Edge> dijkstraShortestPath;\r
-\r
-    public RoutingAlgorithm() {\r
-        super();\r
-\r
-        graph = new DirectedSparseGraph<Vertex, Edge>();\r
-        dijkstraShortestPath = new DijkstraShortestPath<Vertex, Edge>(graph, new Transformer<Edge, Number>() {\r
-            @Override\r
-            public Number transform(Edge edge) {\r
-                return edge.getMetric();\r
-            }\r
-        }, false);\r
-\r
-        return;\r
-    }\r
+    private final DijkstraShortestPath<Vertex, Edge> dijkstraShortestPath =\r
+            new DijkstraShortestPath<>(graph, Edge::getMetric, false);\r
 \r
     /**\r
      * Get the vertex with the given id from the network topology graph.\r
@@ -97,8 +82,6 @@ public class RoutingAlgorithm {
      */\r
     public void addVertex(Vertex vertex) {\r
         graph.addVertex(vertex);\r
-\r
-        return;\r
     }\r
 \r
     /**\r
@@ -108,8 +91,6 @@ public class RoutingAlgorithm {
      */\r
     public void addEdge(Edge edge) {\r
         graph.addEdge(edge, getVertex(edge.getSrc()), getVertex(edge.getDest()), EdgeType.DIRECTED);\r
-\r
-        return;\r
     }\r
 \r
     /**\r
@@ -122,8 +103,6 @@ public class RoutingAlgorithm {
 \r
         edge.setMetric(newEdge.getMetric());\r
         edge.setBandwidth(newEdge.getBandwidth());\r
-\r
-        return;\r
     }\r
 \r
     /**\r
@@ -137,8 +116,6 @@ public class RoutingAlgorithm {
         if ( null != vertex ) {\r
             graph.removeVertex(vertex);\r
         }\r
-\r
-        return;\r
     }\r
 \r
     /**\r
@@ -152,8 +129,6 @@ public class RoutingAlgorithm {
         if ( null != edge ) {\r
             graph.removeEdge(edge);\r
         }\r
-\r
-        return;\r
     }\r
 \r
     /**\r
@@ -180,20 +155,12 @@ public class RoutingAlgorithm {
      * their occurrence on this path.\r
      */\r
     public List<Edge> computePath(Vertex source, Vertex target, final long bandwidth) {\r
-        EdgePredicateFilter<Vertex, Edge> edgeEdgePredicateFilter = new EdgePredicateFilter<Vertex, Edge>(new Predicate<Edge>() {\r
-            @Override\r
-            public boolean evaluate(Edge edge) {\r
-                return edge.getBandwidth() >= bandwidth;\r
-            }\r
-        });\r
+        EdgePredicateFilter<Vertex, Edge> edgeEdgePredicateFilter = new EdgePredicateFilter<>(\r
+                edge -> edge.getBandwidth() >= bandwidth);\r
 \r
-        Graph<Vertex, Edge> filteredGraph = edgeEdgePredicateFilter.transform(graph);\r
-        DijkstraShortestPath<Vertex, Edge> tempDijkstraShortestPath = new DijkstraShortestPath<Vertex, Edge>(filteredGraph, new Transformer<Edge, Number>() {\r
-            @Override\r
-            public Number transform(Edge edge) {\r
-                return edge.getMetric();\r
-            }\r
-        }, false);\r
+        Graph<Vertex, Edge> filteredGraph = edgeEdgePredicateFilter.apply(graph);\r
+        DijkstraShortestPath<Vertex, Edge> tempDijkstraShortestPath =\r
+                new DijkstraShortestPath<>(filteredGraph, Edge::getMetric, false);\r
 \r
         return tempDijkstraShortestPath.getPath(source, target);\r
     }\r
index 5a84645bba469409f5953e055c842237dc105130..efed6db130f3b0a68adffc239da7b7a36759963a 100644 (file)
@@ -7,27 +7,13 @@
  */
 package org.opendaylight.nemo.intent.algorithm;
 
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
 import junit.framework.TestCase;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-
-import static org.junit.Assert.*;
-import edu.uci.ics.jung.algorithms.filters.EdgePredicateFilter;
-import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
-import edu.uci.ics.jung.graph.DirectedSparseGraph;
-import edu.uci.ics.jung.graph.Graph;
-import edu.uci.ics.jung.graph.util.EdgeType;
-import org.apache.commons.collections15.Predicate;
-import org.apache.commons.collections15.Transformer;
-import org.opendaylight.nemo.intent.algorithm.Edge;
-import org.opendaylight.nemo.intent.algorithm.RoutingAlgorithm;
-import org.opendaylight.nemo.intent.algorithm.Vertex;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import static org.mockito.Mockito.*;
 /**
  * Created by zhangmeng on 2015/11/25.
  */
@@ -39,7 +25,7 @@ public class RoutingAlgorithmTest extends TestCase {
     }
 
     @Test
-    public void testVertexAndEdge() throws Exception {
+    public void testVertexAndEdge() {
         //test get Vertices
         Collection<Vertex> collection ;
         collection = routingAlgorithm.getVertices();
@@ -59,7 +45,7 @@ public class RoutingAlgorithmTest extends TestCase {
         Vertex vertex_test = routingAlgorithm.getVertex("null");
         Assert.assertNull(vertex_test);
         vertex_test = routingAlgorithm.getVertex("test");
-        Assert.assertNotNull(vertex1);
+        Assert.assertNotNull(vertex_test);
 
         //add edge
         Edge edge = new Edge("edge","test","test1",1,1);
@@ -115,7 +101,7 @@ public class RoutingAlgorithmTest extends TestCase {
         Assert.assertNull(vertex_test);
 
         //test toString
-        String s = new String();
+        String s = "";
         Assert.assertEquals(0,s.length());
         s = routingAlgorithm.toString();
         Assert.assertTrue(s.length() > 1);