162a4d4232eef7e06b4b9162faab1cc1140b54aa
[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 import org.apache.commons.lang3.builder.HashCodeBuilder;
23 import org.apache.commons.lang3.builder.EqualsBuilder;
24
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;
29
30 /**
31  *
32  * Class that describe an Edge connecting two NodeConnector, the edge
33  * is directed because there is the tail and the head concept which
34  * implies a direction.
35  *
36  */
37 @XmlRootElement
38 @XmlAccessorType(XmlAccessType.NONE)
39 public class Edge implements Serializable {
40     private static final long serialVersionUID = 1L;
41     @XmlElement
42     private NodeConnector tailNodeConnector;
43     @XmlElement
44     private NodeConnector headNodeConnector;
45
46     /**
47      * Private constructor used for JAXB mapping
48      */
49     private Edge() {
50         this.tailNodeConnector = null;
51         this.headNodeConnector = null;
52     }
53
54     /**
55      * Construct the Edge
56      *
57      * @param tailNodeConnector Tail Node output connector
58      * @param headNodeConnector Head Node input connector
59      *
60      */
61     public Edge(NodeConnector tailNodeConnector, NodeConnector headNodeConnector)
62             throws ConstructionException {
63         if (tailNodeConnector == null || headNodeConnector == null) {
64             throw new ConstructionException(
65                     "Null tail or head NodeConnector supplied");
66         } else {
67             this.tailNodeConnector = tailNodeConnector;
68             this.headNodeConnector = headNodeConnector;
69         }
70     }
71
72     /**
73      * Copy Construct the Edge
74      *
75      * @param src Edge to copy from
76      *
77      */
78     public Edge(Edge src) throws ConstructionException {
79         if (src != null) {
80             this.tailNodeConnector = new NodeConnector(src
81                     .getTailNodeConnector());
82             this.headNodeConnector = new NodeConnector(src
83                     .getHeadNodeConnector());
84         } else {
85             throw new ConstructionException("src supplied was null");
86         }
87     }
88
89     /**
90      * getter of edge
91      *
92      *
93      * @return tail NodeConnector of the edge
94      */
95     public NodeConnector getTailNodeConnector() {
96         return tailNodeConnector;
97     }
98
99     /**
100      * setter for edge
101      *
102      * @param tailNodeConnector NodeConnector to set the tail
103      */
104     public void setTailNodeConnector(NodeConnector tailNodeConnector) {
105         this.tailNodeConnector = tailNodeConnector;
106     }
107
108     /**
109      * getter of edge
110      *
111      *
112      * @return head NodeConnector of the edge
113      */
114     public NodeConnector getHeadNodeConnector() {
115         return headNodeConnector;
116     }
117
118     /**
119      * setter for edge
120      *
121      * @param headNodeConnector NodeConnector to set the head
122      */
123     public void setHeadNodeConnector(NodeConnector headNodeConnector) {
124         this.headNodeConnector = headNodeConnector;
125     }
126
127     @Override
128     public int hashCode() {
129         return HashCodeBuilder.reflectionHashCode(this);
130     }
131
132     @Override
133     public boolean equals(Object obj) {
134         return EqualsBuilder.reflectionEquals(this, obj);
135     }
136
137     @Override
138     public String toString() {
139         return "(" + this.tailNodeConnector + "->" + this.headNodeConnector
140                 + ")";
141     }
142 }