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;
22 import org.apache.commons.lang3.builder.HashCodeBuilder;
23 import org.apache.commons.lang3.builder.EqualsBuilder;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlAccessType;
27 import javax.xml.bind.annotation.XmlAccessorType;
28 import javax.xml.bind.annotation.XmlElement;
31 * Describe a path as a sequence of Edge such that from
32 * each of its Head Node there is an link to the next Tail Node in the
37 @XmlAccessorType(XmlAccessType.NONE)
38 public class Path implements Serializable {
39 private static final long serialVersionUID = 1L;
41 private List<Edge> edges;
44 * Private constructor used for JAXB mapping
51 * Construct an object representing a path, the constructor will
52 * check if the passed list of edges is such that for every
53 * consecutive edges the head node of the first edge coincide with
54 * the tail node of the subsequent in order for connectivity to be there.
56 * @param edges Edges of the path
59 public Path(List<Edge> edges) throws ConstructionException {
60 // Lets check if the list of edges is such that the head node
61 // of an edge is also the tail node of the subsequent one
62 boolean sequential = true;
63 if (edges.size() >= 2) {
64 for (int i = 0; i < edges.size() - 1; i++) {
65 Edge current = edges.get(i);
66 Edge next = edges.get(i + 1);
67 if (!current.getHeadNodeConnector().getNode()
69 next.getTailNodeConnector()
74 } else if (edges.size() == 0) {
75 throw new ConstructionException("Path is empty");
79 throw new ConstructionException("Path is not sequential");
86 * Copy Construct for a path
88 * @param src Path to copy from
91 public Path(Path src) throws ConstructionException {
93 this.edges = new LinkedList<Edge>(src.getEdges());
95 throw new ConstructionException("src supplied was null");
100 * get the First Node of the path
103 * @return The start Node of the Path
105 public Node getStartNode() {
106 return this.edges.get(0).getTailNodeConnector().getNode();
110 * get the Last Node of the path
113 * @return The last Node of the Path
115 public Node getEndNode() {
116 return this.edges.get(this.edges.size() - 1).getHeadNodeConnector()
121 * getter method for the Path
124 * @return Return the list of edges that constitue the Path
126 public List<Edge> getEdges() {
131 public int hashCode() {
132 return HashCodeBuilder.reflectionHashCode(this);
136 public boolean equals(Object obj) {
137 return EqualsBuilder.reflectionEquals(this, obj);
141 public String toString() {
142 StringBuilder sb = new StringBuilder();
144 for (int i = 0; i < this.edges.size(); i++) {
146 // add the comma to the previous element
149 sb.append(this.edges.get(i).toString());
152 return sb.toString();