3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
13 * @brief Describe a path as a sequence of Edge such that from
14 * each of its Head Node there is an link to the next Tail Node in the sequence
17 package org.opendaylight.controller.sal.core;
19 import java.io.Serializable;
20 import java.util.LinkedList;
21 import java.util.List;
23 import javax.xml.bind.annotation.XmlAccessType;
24 import javax.xml.bind.annotation.XmlAccessorType;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlRootElement;
29 * Describe a path as a sequence of Edge such that from
30 * each of its Head Node there is an link to the next Tail Node in the
35 @XmlAccessorType(XmlAccessType.NONE)
36 public class Path implements Serializable {
37 private static final long serialVersionUID = 1L;
39 private List<Edge> edges;
42 * Private constructor used for JAXB mapping
49 * Construct an object representing a path, the constructor will
50 * check if the passed list of edges is such that for every
51 * consecutive edges the head node of the first edge coincide with
52 * the tail node of the subsequent in order for connectivity to be there.
54 * @param edges Edges of the path
57 public Path(List<Edge> edges) throws ConstructionException {
58 // Lets check if the list of edges is such that the head node
59 // of an edge is also the tail node of the subsequent one
60 boolean sequential = true;
61 if (edges.size() >= 2) {
62 for (int i = 0; i < edges.size() - 1; i++) {
63 Edge current = edges.get(i);
64 Edge next = edges.get(i + 1);
65 if (!current.getHeadNodeConnector().getNode()
67 next.getTailNodeConnector()
72 } else if (edges.size() == 0) {
73 throw new ConstructionException("Path is empty");
77 throw new ConstructionException("Path is not sequential");
84 * Copy Construct for a path
86 * @param src Path to copy from
89 public Path(Path src) throws ConstructionException {
91 this.edges = new LinkedList<Edge>(src.getEdges());
93 throw new ConstructionException("src supplied was null");
98 * get the First Node of the path
101 * @return The start Node of the Path
103 public Node getStartNode() {
104 return this.edges.get(0).getTailNodeConnector().getNode();
108 * get the Last Node of the path
111 * @return The last Node of the Path
113 public Node getEndNode() {
114 return this.edges.get(this.edges.size() - 1).getHeadNodeConnector()
119 * getter method for the Path
122 * @return Return the list of edges that constitue the Path
124 public List<Edge> getEdges() {
129 public int hashCode() {
130 final int prime = 31;
132 result = prime * result + ((edges == null) ? 0 : edges.hashCode());
137 public boolean equals(Object obj) {
142 if (getClass() != obj.getClass())
144 Path other = (Path) obj;
146 if (other.edges != null)
148 } else if (!edges.equals(other.edges))
154 public String toString() {
155 StringBuilder sb = new StringBuilder();
157 for (int i = 0; i < this.edges.size(); i++) {
159 // add the comma to the previous element
162 sb.append(this.edges.get(i).toString());
165 return sb.toString();