BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / Edge.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 /**
11  * @file   Edge.java
12  *
13  * @brief  Describe an edge in network made of multiple SDN technologies
14  *
15  * Class that describe an Edge connecting two NodeConnector, the edge
16  * is directed because there is the head and the tail concept which
17  * implies a direction.
18  */
19 package org.opendaylight.controller.sal.core;
20
21 import java.io.Serializable;
22
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;
27
28 /**
29  *
30  * Class that describe an Edge connecting two NodeConnector, the edge
31  * is directed because there is the tail and the head concept which
32  * implies a direction.
33  *
34  */
35 @XmlRootElement
36 @XmlAccessorType(XmlAccessType.NONE)
37 public class Edge implements Serializable {
38     private static final long serialVersionUID = 1L;
39     @XmlElement
40     private NodeConnector tailNodeConnector;
41     @XmlElement
42     private NodeConnector headNodeConnector;
43
44     /**
45      * Private constructor used for JAXB mapping
46      */
47     @SuppressWarnings("unused")
48     private Edge() {
49         this.tailNodeConnector = null;
50         this.headNodeConnector = null;
51     }
52
53     /**
54      * Construct the Edge
55      *
56      * @param tailNodeConnector Tail Node output connector
57      * @param headNodeConnector Head Node input connector
58      *
59      */
60     public Edge(NodeConnector tailNodeConnector, NodeConnector headNodeConnector)
61             throws ConstructionException {
62         if (tailNodeConnector == null || headNodeConnector == null) {
63             throw new ConstructionException(
64                     "Null tail or head NodeConnector supplied");
65         } else {
66             this.tailNodeConnector = tailNodeConnector;
67             this.headNodeConnector = headNodeConnector;
68         }
69     }
70
71     /**
72      * Copy Construct the Edge
73      *
74      * @param src Edge to copy from
75      *
76      */
77     public Edge(Edge src) throws ConstructionException {
78         if (src != null) {
79             this.tailNodeConnector = new NodeConnector(src
80                     .getTailNodeConnector());
81             this.headNodeConnector = new NodeConnector(src
82                     .getHeadNodeConnector());
83         } else {
84             throw new ConstructionException("src supplied was null");
85         }
86     }
87
88     /**
89      * Create the reversed edge
90      * @return The reversed edge.
91      */
92     public Edge reverse() {
93         Edge re;
94         try {
95             re = new Edge(this.headNodeConnector, this.tailNodeConnector);
96         } catch (ConstructionException e) {
97             re = null;
98         }
99         return re;
100     }
101     /**
102      * getter of edge
103      *
104      *
105      * @return tail NodeConnector of the edge
106      */
107     public NodeConnector getTailNodeConnector() {
108         return tailNodeConnector;
109     }
110
111     /**
112      * setter for edge
113      *
114      * @param tailNodeConnector NodeConnector to set the tail
115      */
116     public void setTailNodeConnector(NodeConnector tailNodeConnector) {
117         this.tailNodeConnector = tailNodeConnector;
118     }
119
120     /**
121      * getter of edge
122      *
123      *
124      * @return head NodeConnector of the edge
125      */
126     public NodeConnector getHeadNodeConnector() {
127         return headNodeConnector;
128     }
129
130     /**
131      * setter for edge
132      *
133      * @param headNodeConnector NodeConnector to set the head
134      */
135     public void setHeadNodeConnector(NodeConnector headNodeConnector) {
136         this.headNodeConnector = headNodeConnector;
137     }
138
139     @Override
140     public int hashCode() {
141         final int prime = 31;
142         int result = 1;
143         result = prime
144                 * result
145                 + ((headNodeConnector == null) ? 0 : headNodeConnector
146                         .hashCode());
147         result = prime
148                 * result
149                 + ((tailNodeConnector == null) ? 0 : tailNodeConnector
150                         .hashCode());
151         return result;
152     }
153
154     @Override
155     public boolean equals(Object obj) {
156         if (this == obj)
157             return true;
158         if (obj == null)
159             return false;
160         if (getClass() != obj.getClass())
161             return false;
162         Edge other = (Edge) obj;
163         if (headNodeConnector == null) {
164             if (other.headNodeConnector != null)
165                 return false;
166         } else if (!headNodeConnector.equals(other.headNodeConnector))
167             return false;
168         if (tailNodeConnector == null) {
169             if (other.tailNodeConnector != null)
170                 return false;
171         } else if (!tailNodeConnector.equals(other.tailNodeConnector))
172             return false;
173         return true;
174     }
175
176     @Override
177     public String toString() {
178         return "(" + this.tailNodeConnector + "->" + this.headNodeConnector
179                 + ")";
180     }
181 }