X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcore%2FMacAddress.java;h=4470e17e82bc2b77109a4ca39b9acc741c7a1515;hb=0df356fd6dd1e24f82a4afaa6c824517d354fb20;hp=d5fbdbc74371df64bbd204ed7965e156c21512da;hpb=2aa5c39bdd7c498a3b33db434d3943c130e05bc8;p=controller.git diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/MacAddress.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/MacAddress.java index d5fbdbc743..4470e17e82 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/MacAddress.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/MacAddress.java @@ -8,14 +8,12 @@ package org.opendaylight.controller.sal.core; -import java.util.Arrays; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.opendaylight.controller.sal.utils.HexEncode; /** * The class contains MAC address property. @@ -25,7 +23,7 @@ import org.apache.commons.lang3.builder.ReflectionToStringBuilder; public class MacAddress extends Property implements Cloneable { private static final long serialVersionUID = 1L; @XmlElement(name="macAddress") - private final byte[] address; + private final String address; public static final String name = "macAddress"; /* @@ -43,20 +41,36 @@ public class MacAddress extends Property implements Cloneable { * * * @param nodeMacAddress - * Data Link Address for the node + * Data Link Address for the node in byte array format * * @return the constructed object */ public MacAddress(byte[] nodeMacAddress) { super(name); - this.address = nodeMacAddress.clone(); + this.address = HexEncode.bytesToHexStringFormat(nodeMacAddress); + } + + /** + * Constructor to create DatalinkAddress property which contains the MAC + * address. The property will be attached to a + * {@link org.opendaylight.controller.sal.core.Node}. + * + * + * @param nodeMacAddress + * Data Link Address for the node in String format + * + * @return the constructed object + */ + public MacAddress(String nodeMacAddress) { + super(name); + this.address = nodeMacAddress; } /** - * @return the node MAC address + * @return the node MAC address in byte array format */ public byte[] getMacAddress() { - return this.address.clone(); + return HexEncode.bytesFromHexString(this.address); } @Override @@ -68,7 +82,8 @@ public class MacAddress extends Property implements Cloneable { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + Arrays.hashCode(address); + result = prime * result + + ((address == null) ? 0 : address.hashCode()); return result; } @@ -84,7 +99,7 @@ public class MacAddress extends Property implements Cloneable { return false; } MacAddress other = (MacAddress) obj; - if (!Arrays.equals(address, other.address)) { + if (!address.equals(other.address)) { return false; } return true; @@ -92,6 +107,6 @@ public class MacAddress extends Property implements Cloneable { @Override public String toString() { - return "MacAddress[" + ReflectionToStringBuilder.toString(this) + "]"; + return "MacAddress[" + address + "]"; } }