Mark AD-SAL interfaces as deprecated
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / core / MacAddress.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.sal.core;
10
11 import javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlElement;
14 import javax.xml.bind.annotation.XmlRootElement;
15
16 import org.opendaylight.controller.sal.utils.HexEncode;
17
18 /**
19  * The class contains MAC address property.
20  */
21 @XmlRootElement
22 @XmlAccessorType(XmlAccessType.NONE)
23 @Deprecated
24 public class MacAddress extends Property implements Cloneable {
25     private static final long serialVersionUID = 1L;
26     @XmlElement(name="value")
27     private final String address;
28     public static final String name = "macAddress";
29
30     /*
31      * Private constructor used for JAXB mapping
32      */
33     private MacAddress() {
34         super(name);
35         this.address = null;
36     }
37
38     /**
39      * Constructor to create DatalinkAddress property which contains the MAC
40      * address. The property will be attached to a
41      * {@link org.opendaylight.controller.sal.core.Node}.
42      *
43      *
44      * @param nodeMacAddress
45      *            Data Link Address for the node in byte array format
46      *
47      * @return the constructed object
48      */
49     public MacAddress(byte[] nodeMacAddress) {
50         super(name);
51         this.address = HexEncode.bytesToHexStringFormat(nodeMacAddress);
52     }
53
54     /**
55      * Constructor to create DatalinkAddress property which contains the MAC
56      * address. The property will be attached to a
57      * {@link org.opendaylight.controller.sal.core.Node}.
58      *
59      *
60      * @param nodeMacAddress
61      *            Data Link Address for the node in String format
62      *
63      * @return the constructed object
64      */
65     public MacAddress(String nodeMacAddress) {
66         super(name);
67         this.address = nodeMacAddress;
68     }
69
70     /**
71      * @return the node MAC address in byte array format
72      */
73     public byte[] getMacAddress() {
74         return HexEncode.bytesFromHexString(this.address);
75     }
76
77     @Override
78     public MacAddress clone() {
79         return new MacAddress(this.address);
80     }
81
82     @Override
83     public int hashCode() {
84         final int prime = 31;
85         int result = super.hashCode();
86         result = prime * result
87                 + ((address == null) ? 0 : address.hashCode());
88         return result;
89     }
90
91     @Override
92     public boolean equals(Object obj) {
93         if (this == obj) {
94             return true;
95         }
96         if (!super.equals(obj)) {
97             return false;
98         }
99         if (getClass() != obj.getClass()) {
100             return false;
101         }
102         MacAddress other = (MacAddress) obj;
103         if (!address.equals(other.address)) {
104             return false;
105         }
106         return true;
107     }
108
109     @Override
110     public String toString() {
111         return "MacAddress[" + address + "]";
112     }
113
114     @Override
115     public String getStringValue() {
116         return address;
117     }
118 }