Fixing warnings in the sal sub-project.
[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      * getter of edge
90      *
91      *
92      * @return tail NodeConnector of the edge
93      */
94     public NodeConnector getTailNodeConnector() {
95         return tailNodeConnector;
96     }
97
98     /**
99      * setter for edge
100      *
101      * @param tailNodeConnector NodeConnector to set the tail
102      */
103     public void setTailNodeConnector(NodeConnector tailNodeConnector) {
104         this.tailNodeConnector = tailNodeConnector;
105     }
106
107     /**
108      * getter of edge
109      *
110      *
111      * @return head NodeConnector of the edge
112      */
113     public NodeConnector getHeadNodeConnector() {
114         return headNodeConnector;
115     }
116
117     /**
118      * setter for edge
119      *
120      * @param headNodeConnector NodeConnector to set the head
121      */
122     public void setHeadNodeConnector(NodeConnector headNodeConnector) {
123         this.headNodeConnector = headNodeConnector;
124     }
125
126     @Override
127     public int hashCode() {
128         final int prime = 31;
129         int result = 1;
130         result = prime
131                 * result
132                 + ((headNodeConnector == null) ? 0 : headNodeConnector
133                         .hashCode());
134         result = prime
135                 * result
136                 + ((tailNodeConnector == null) ? 0 : tailNodeConnector
137                         .hashCode());
138         return result;
139     }
140
141     @Override
142     public boolean equals(Object obj) {
143         if (this == obj)
144             return true;
145         if (obj == null)
146             return false;
147         if (getClass() != obj.getClass())
148             return false;
149         Edge other = (Edge) obj;
150         if (headNodeConnector == null) {
151             if (other.headNodeConnector != null)
152                 return false;
153         } else if (!headNodeConnector.equals(other.headNodeConnector))
154             return false;
155         if (tailNodeConnector == null) {
156             if (other.tailNodeConnector != null)
157                 return false;
158         } else if (!tailNodeConnector.equals(other.tailNodeConnector))
159             return false;
160         return true;
161     }
162
163     @Override
164     public String toString() {
165         return "(" + this.tailNodeConnector + "->" + this.headNodeConnector
166                 + ")";
167     }
168 }