X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcore%2FPath.java;h=3a4a192fc9b86c3df90576b393f7c23222974899;hb=0fe04fdf4271be914d43d35231c1706ec34b05f6;hp=e21f6f14720d9d510d72cf65ccc7ed1159acae14;hpb=9ff610f03e7fe11a5c9e40405cf24dd3e3af8a89;p=controller.git diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Path.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Path.java index e21f6f1472..3a4a192fc9 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Path.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Path.java @@ -17,6 +17,9 @@ package org.opendaylight.controller.sal.core; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -41,6 +44,7 @@ public class Path implements Serializable { /** * Private constructor used for JAXB mapping */ + @SuppressWarnings("unused") private Path() { this.edges = null; } @@ -62,11 +66,9 @@ public class Path implements Serializable { for (int i = 0; i < edges.size() - 1; i++) { Edge current = edges.get(i); Edge next = edges.get(i + 1); - if (!current.getHeadNodeConnector().getNode() - .equals( - next.getTailNodeConnector() - .getNode())) { + if (!current.getHeadNodeConnector().getNode().equals(next.getTailNodeConnector().getNode())) { sequential = false; + break; } } } else if (edges.size() == 0) { @@ -80,6 +82,39 @@ public class Path implements Serializable { this.edges = edges; } + /** + * Create the reversed path + * @return The reversed path + */ + public Path reverse() { + int j = edges.size(); // size always > 0 + Edge[] aEdges = new Edge[j]; + for (Edge e : edges) { + j--; + aEdges[j] = e.reverse(); + } + Path rp; + try { + rp = new Path(Arrays.asList(aEdges)); + } catch (ConstructionException ce) { + rp = null; + } + return rp; + } + + /** + * Return the list of nodes of this path, the first node is the start node + * @return the list of nodes + */ + public List getNodes() { + List nl = new ArrayList(); + nl.add(this.getStartNode()); + for (Edge e : edges) { + nl.add(e.getHeadNodeConnector().getNode()); + } + return nl; + } + /** * Copy Construct for a path * @@ -119,10 +154,10 @@ public class Path implements Serializable { * getter method for the Path * * - * @return Return the list of edges that constitue the Path + * @return Return the list of edges that constitute the Path */ public List getEdges() { - return this.edges; + return (edges == null) ? Collections.emptyList() : new ArrayList(edges); } @Override @@ -135,18 +170,23 @@ public class Path implements Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Path other = (Path) obj; if (edges == null) { - if (other.edges != null) + if (other.edges != null) { return false; - } else if (!edges.equals(other.edges)) + } + } else if (!edges.equals(other.edges)) { return false; + } return true; }