<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>
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
/**\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
*/\r
public void addVertex(Vertex vertex) {\r
graph.addVertex(vertex);\r
-\r
- return;\r
}\r
\r
/**\r
*/\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
\r
edge.setMetric(newEdge.getMetric());\r
edge.setBandwidth(newEdge.getBandwidth());\r
-\r
- return;\r
}\r
\r
/**\r
if ( null != vertex ) {\r
graph.removeVertex(vertex);\r
}\r
-\r
- return;\r
}\r
\r
/**\r
if ( null != edge ) {\r
graph.removeEdge(edge);\r
}\r
-\r
- return;\r
}\r
\r
/**\r
* 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
*/
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.
*/
}
@Test
- public void testVertexAndEdge() throws Exception {
+ public void testVertexAndEdge() {
//test get Vertices
Collection<Vertex> collection ;
collection = routingAlgorithm.getVertices();
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);
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);