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
44 @SuppressWarnings("unused")
50 * Construct an object representing a path, the constructor will
51 * check if the passed list of edges is such that for every
52 * consecutive edges the head node of the first edge coincide with
53 * the tail node of the subsequent in order for connectivity to be there.
55 * @param edges Edges of the path
58 public Path(List<Edge> edges) throws ConstructionException {
59 // Lets check if the list of edges is such that the head node
60 // of an edge is also the tail node of the subsequent one
61 boolean sequential = true;
62 if (edges.size() >= 2) {
63 for (int i = 0; i < edges.size() - 1; i++) {
64 Edge current = edges.get(i);
65 Edge next = edges.get(i + 1);
66 if (!current.getHeadNodeConnector().getNode()
68 next.getTailNodeConnector()
73 } else if (edges.size() == 0) {
74 throw new ConstructionException("Path is empty");
78 throw new ConstructionException("Path is not sequential");
85 * Copy Construct for a path
87 * @param src Path to copy from
90 public Path(Path src) throws ConstructionException {
92 this.edges = new LinkedList<Edge>(src.getEdges());
94 throw new ConstructionException("src supplied was null");
99 * get the First Node of the path
102 * @return The start Node of the Path
104 public Node getStartNode() {
105 return this.edges.get(0).getTailNodeConnector().getNode();
109 * get the Last Node of the path
112 * @return The last Node of the Path
114 public Node getEndNode() {
115 return this.edges.get(this.edges.size() - 1).getHeadNodeConnector()
120 * getter method for the Path
123 * @return Return the list of edges that constitue the Path
125 public List<Edge> getEdges() {
130 public int hashCode() {
131 final int prime = 31;
133 result = prime * result + ((edges == null) ? 0 : edges.hashCode());
138 public boolean equals(Object obj) {
143 if (getClass() != obj.getClass())
145 Path other = (Path) obj;
147 if (other.edges != null)
149 } else if (!edges.equals(other.edges))
155 public String toString() {
156 StringBuilder sb = new StringBuilder();
158 for (int i = 0; i < this.edges.size(); i++) {
160 // add the comma to the previous element
163 sb.append(this.edges.get(i).toString());
166 return sb.toString();