Five more Equals/HashCode/StringBuilder replacements
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / MacAddress.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 package org.opendaylight.controller.sal.core;
11
12 import java.util.Arrays;
13
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
20
21 /**
22  * The class contains the controller MAC address and node MAC address.
23  *
24  *
25  */
26 @XmlRootElement
27 @XmlAccessorType(XmlAccessType.NONE)
28 public class MacAddress extends Property {
29     private static final long serialVersionUID = 1L;
30     @XmlElement
31     private byte[] controllerMacAddress;
32     @XmlElement
33     private byte[] nodeMacAddress;
34     public static final String MacPropName = "macAddress";
35
36     /*
37      * Private constructor used for JAXB mapping
38      */
39     private MacAddress() {
40         super(MacPropName);
41         this.controllerMacAddress = null;
42         this.nodeMacAddress = null;
43     }
44
45         /**
46          * Constructor to create DatalinkAddress property which contains the
47          * controller MAC address and node MAC address. The property will be
48          * attached to a {@link org.opendaylight.controller.sal.core.Node}.
49          * 
50          * @param controllerMacAddress Data Link Address for the controller
51          * @param nodeMacAddress Data Link Address for the node
52          * 
53          * @return the constructed object
54          */
55     public MacAddress(byte[] controllerMacAddress, byte[] nodeMacAddress) {
56         super(MacPropName);
57         
58         this.controllerMacAddress = controllerMacAddress;
59         this.nodeMacAddress = nodeMacAddress;
60     }
61
62     /**
63      * @return the controller MAC address
64      */
65     public byte[] getControllerMacAddress() {
66         return this.controllerMacAddress;
67     }
68
69     /**
70      * @return the node MAC address
71      */
72     public byte[] getNodeMacAddress() {
73         return this.nodeMacAddress;
74     }
75
76     public MacAddress clone() {
77         return new MacAddress(this.controllerMacAddress, this.nodeMacAddress);
78     }
79
80     @Override
81     public int hashCode() {
82         final int prime = 31;
83         int result = super.hashCode();
84         result = prime * result + Arrays.hashCode(controllerMacAddress);
85         result = prime * result + Arrays.hashCode(nodeMacAddress);
86         return result;
87     }
88
89     @Override
90     public boolean equals(Object obj) {
91         if (this == obj)
92             return true;
93         if (!super.equals(obj))
94             return false;
95         if (getClass() != obj.getClass())
96             return false;
97         MacAddress other = (MacAddress) obj;
98         if (!Arrays.equals(controllerMacAddress, other.controllerMacAddress))
99             return false;
100         if (!Arrays.equals(nodeMacAddress, other.nodeMacAddress))
101             return false;
102         return true;
103     }
104
105     @Override
106     public String toString() {
107         return "MacAddress[" + ReflectionToStringBuilder.toString(this) + "]";
108     }
109 }