blob: ddfbecf6eb571a45423beeaec9c7e05554db2e28 [file] [log] [blame]
package net.onrc.onos.core.util;
import javax.annotation.concurrent.Immutable;
import net.onrc.onos.core.util.serializers.DpidDeserializer;
import net.onrc.onos.core.util.serializers.DpidSerializer;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.projectfloodlight.openflow.util.HexString;
import com.google.common.primitives.Longs;
/**
* The class representing a network switch DPID.
* This class is immutable.
*/
@JsonDeserialize(using = DpidDeserializer.class)
@JsonSerialize(using = DpidSerializer.class)
@Immutable
public final class Dpid {
private static final long UNKNOWN = 0;
private final long value;
/**
* Default constructor.
*/
protected Dpid() {
this.value = Dpid.UNKNOWN;
}
/**
* Constructor from a long value.
*
* @param value the value to use.
*/
public Dpid(long value) {
this.value = value;
}
/**
* Constructor from a string.
*
* @param value the value to use.
*/
public Dpid(String value) {
this.value = HexString.toLong(value);
}
/**
* Get the value of the DPID.
*
* @return the value of the DPID.
*/
public long value() {
return value;
}
/**
* Convert the DPID value to a ':' separated hexadecimal string.
*
* @return the DPID value as a ':' separated hexadecimal string.
*/
@Override
public String toString() {
return HexString.toHexString(this.value);
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Dpid)) {
return false;
}
Dpid otherDpid = (Dpid) other;
return value == otherDpid.value;
}
@Override
public int hashCode() {
return Longs.hashCode(value);
}
}