c119eb79f554fc47f34f05fba02bdd17591fede5
[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     private Edge() {
48         this.tailNodeConnector = null;
49         this.headNodeConnector = null;
50     }
51
52     /**
53      * Construct the Edge
54      *
55      * @param tailNodeConnector Tail Node output connector
56      * @param headNodeConnector Head Node input connector
57      *
58      */
59     public Edge(NodeConnector tailNodeConnector, NodeConnector headNodeConnector)
60             throws ConstructionException {
61         if (tailNodeConnector == null || headNodeConnector == null) {
62             throw new ConstructionException(
63                     "Null tail or head NodeConnector supplied");
64         } else {
65             this.tailNodeConnector = tailNodeConnector;
66             this.headNodeConnector = headNodeConnector;
67         }
68     }
69
70     /**
71      * Copy Construct the Edge
72      *
73      * @param src Edge to copy from
74      *
75      */
76     public Edge(Edge src) throws ConstructionException {
77         if (src != null) {
78             this.tailNodeConnector = new NodeConnector(src
79                     .getTailNodeConnector());
80             this.headNodeConnector = new NodeConnector(src
81                     .getHeadNodeConnector());
82         } else {
83             throw new ConstructionException("src supplied was null");
84         }
85     }
86
87     /**
88      * getter of edge
89      *
90      *
91      * @return tail NodeConnector of the edge
92      */
93     public NodeConnector getTailNodeConnector() {
94         return tailNodeConnector;
95     }
96
97     /**
98      * setter for edge
99      *
100      * @param tailNodeConnector NodeConnector to set the tail
101      */
102     public void setTailNodeConnector(NodeConnector tailNodeConnector) {
103         this.tailNodeConnector = tailNodeConnector;
104     }
105
106     /**
107      * getter of edge
108      *
109      *
110      * @return head NodeConnector of the edge
111      */
112     public NodeConnector getHeadNodeConnector() {
113         return headNodeConnector;
114     }
115
116     /**
117      * setter for edge
118      *
119      * @param headNodeConnector NodeConnector to set the head
120      */
121     public void setHeadNodeConnector(NodeConnector headNodeConnector) {
122         this.headNodeConnector = headNodeConnector;
123     }
124
125     @Override
126     public int hashCode() {
127         final int prime = 31;
128         int result = 1;
129         result = prime
130                 * result
131                 + ((headNodeConnector == null) ? 0 : headNodeConnector
132                         .hashCode());
133         result = prime
134                 * result
135                 + ((tailNodeConnector == null) ? 0 : tailNodeConnector
136                         .hashCode());
137         return result;
138     }
139
140     @Override
141     public boolean equals(Object obj) {
142         if (this == obj)
143             return true;
144         if (obj == null)
145             return false;
146         if (getClass() != obj.getClass())
147             return false;
148         Edge other = (Edge) obj;
149         if (headNodeConnector == null) {
150             if (other.headNodeConnector != null)
151                 return false;
152         } else if (!headNodeConnector.equals(other.headNodeConnector))
153             return false;
154         if (tailNodeConnector == null) {
155             if (other.tailNodeConnector != null)
156                 return false;
157         } else if (!tailNodeConnector.equals(other.tailNodeConnector))
158             return false;
159         return true;
160     }
161
162     @Override
163     public String toString() {
164         return "(" + this.tailNodeConnector + "->" + this.headNodeConnector
165                 + ")";
166     }
167 }