Jian Li
Committed by Thomas Vachuska

[ONOS-4014] Refactor *Id classes to extend from Identifier class

- Refactor all of *Id classes in protocols package
- Refactor all of *Id classes in utils package

Change-Id: Ie53f078174d0bd0cb5ab4ef6786f1025a7d70846
......@@ -17,9 +17,10 @@
package org.onosproject.bgp.controller;
import org.onlab.packet.IpAddress;
import org.onlab.util.Identifier;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkArgument;
......@@ -27,11 +28,10 @@ import static com.google.common.base.Preconditions.checkArgument;
* The class representing a network peer bgp ip.
* This class is immutable.
*/
public final class BgpId {
public final class BgpId extends Identifier<IpAddress> {
private static final String SCHEME = "bgp";
private static final long UNKNOWN = 0;
private final IpAddress ipAddress;
/**
* Constructor to initialize ipAddress.
......@@ -39,7 +39,7 @@ public final class BgpId {
* @param ipAddress Ip address
*/
public BgpId(IpAddress ipAddress) {
this.ipAddress = ipAddress;
super(ipAddress);
}
/**
......@@ -58,32 +58,7 @@ public final class BgpId {
* @return ipAddress
*/
public IpAddress ipAddress() {
return ipAddress;
}
/**
* Convert the BGPId value to a ':' separated hexadecimal string.
*
* @return the BGPId value as a ':' separated hexadecimal string.
*/
@Override
public String toString() {
return ipAddress.toString();
}
@Override
public boolean equals(Object other) {
if (!(other instanceof BgpId)) {
return false;
}
BgpId otherBGPid = (BgpId) other;
return Objects.equals(ipAddress, otherBGPid.ipAddress);
}
@Override
public int hashCode() {
return Objects.hash(ipAddress);
return identifier;
}
/**
......
......@@ -15,25 +15,22 @@
*/
package org.onosproject.ovsdb.controller;
import static com.google.common.base.MoreObjects.toStringHelper;
import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Objects;
/**
* The class representing a datapathid.
* This class is immutable.
*/
public final class OvsdbDatapathId {
private final String value;
public final class OvsdbDatapathId extends Identifier<String> {
/**
* Constructor from a String.
*
* @param value the datapathid to use
*/
public OvsdbDatapathId(String value) {
checkNotNull(value, "value is not null");
this.value = value;
super(checkNotNull(value, "value is not null"));
}
/**
......@@ -42,28 +39,6 @@ public final class OvsdbDatapathId {
* @return the value of datapathid
*/
public String value() {
return value;
}
@Override
public int hashCode() {
return value.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OvsdbDatapathId) {
final OvsdbDatapathId otherDatapathId = (OvsdbDatapathId) obj;
return Objects.equals(this.value, otherDatapathId.value);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("value", value).toString();
return identifier;
}
}
......
......@@ -15,25 +15,22 @@
*/
package org.onosproject.ovsdb.controller;
import static com.google.common.base.MoreObjects.toStringHelper;
import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Objects;
/**
* The class representing an ifaceid.
* This class is immutable.
*/
public class OvsdbIfaceId {
private final String value;
public class OvsdbIfaceId extends Identifier<String> {
/**
* Constructor from a String.
*
* @param value the ifaceid to use
*/
public OvsdbIfaceId(String value) {
checkNotNull(value, "value is not null");
this.value = value;
super(checkNotNull(value, "value is not null"));
}
/**
......@@ -42,28 +39,6 @@ public class OvsdbIfaceId {
* @return the value of ifaceid
*/
public String value() {
return value;
}
@Override
public int hashCode() {
return value.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OvsdbIfaceId) {
final OvsdbIfaceId otherIfaceId = (OvsdbIfaceId) obj;
return Objects.equals(this.value, otherIfaceId.value);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("value", value).toString();
return identifier;
}
}
......
......@@ -15,19 +15,17 @@
*/
package org.onosproject.ovsdb.controller;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Objects;
import org.onlab.packet.IpAddress;
import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The class representing a nodeId of node which using ovsdb connection.
* This class is immutable.
*/
public final class OvsdbNodeId {
public final class OvsdbNodeId extends Identifier<String> {
private static final String SCHEME = "ovsdb";
private final String nodeId;
private final String ipAddress;
/**
......@@ -37,30 +35,14 @@ public final class OvsdbNodeId {
* @param port node port
*/
public OvsdbNodeId(IpAddress ipAddress, long port) {
checkNotNull(ipAddress, "ipAddress is not null");
// TODO: port is currently not in use, need to remove it later
super(checkNotNull(ipAddress, "ipAddress is not null").toString());
this.ipAddress = ipAddress.toString();
this.nodeId = ipAddress.toString();
}
@Override
public int hashCode() {
return nodeId.hashCode();
}
@Override
public boolean equals(Object other) {
if (!(other instanceof OvsdbNodeId)) {
return false;
}
OvsdbNodeId otherNodeId = (OvsdbNodeId) other;
return Objects.equals(otherNodeId.nodeId, this.nodeId);
}
@Override
public String toString() {
return SCHEME + ":" + nodeId;
return SCHEME + ":" + identifier;
}
/**
......@@ -69,7 +51,7 @@ public final class OvsdbNodeId {
* @return the value of the NodeId.
*/
public String nodeId() {
return SCHEME + ":" + nodeId;
return SCHEME + ":" + identifier;
}
/**
......
......@@ -15,28 +15,28 @@
*/
package org.onosproject.pcep.controller;
import static com.google.common.base.Preconditions.checkArgument;
import org.onlab.packet.IpAddress;
import org.onlab.util.Identifier;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
import org.onlab.packet.IpAddress;
import static com.google.common.base.Preconditions.checkArgument;
/**
* The class representing a network client pc ip.
* This class is immutable.
*/
public final class PccId {
public final class PccId extends Identifier<IpAddress> {
private static final String SCHEME = "pcep";
private static final long UNKNOWN = 0;
private final IpAddress ipAddress;
/**
* Private constructor.
*/
private PccId(IpAddress ipAddress) {
this.ipAddress = ipAddress;
super(ipAddress);
}
/**
......@@ -55,32 +55,7 @@ public final class PccId {
* @return ipAddress
*/
public IpAddress ipAddress() {
return ipAddress;
}
/**
* Convert the PccId value to a ':' separated hexadecimal string.
*
* @return the PccId value as a ':' separated hexadecimal string.
*/
@Override
public String toString() {
return ipAddress.toString();
}
@Override
public boolean equals(Object other) {
if (!(other instanceof PccId)) {
return false;
}
PccId otherPccid = (PccId) other;
return Objects.equals(ipAddress, otherPccid.ipAddress);
}
@Override
public int hashCode() {
return Objects.hash(ipAddress);
return identifier;
}
/**
......
......@@ -16,29 +16,24 @@
package org.onosproject.pcepio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.util.Identifier;
import org.onosproject.pcepio.protocol.PcepNai;
import com.google.common.base.MoreObjects;
/**
* Provides Pcep Nai Ipv4 Node Id.
*/
public class PcepNaiIpv4NodeId implements PcepNai {
public class PcepNaiIpv4NodeId extends Identifier<Integer> implements PcepNai {
public static final byte ST_TYPE = 0x01;
private final int ipv4NodeId;
/**
* Constructor to initialize ipv4NodeId.
*
* @param value ipv4 node id
*/
public PcepNaiIpv4NodeId(int value) {
this.ipv4NodeId = value;
super(value);
}
/**
......@@ -59,7 +54,7 @@ public class PcepNaiIpv4NodeId implements PcepNai {
@Override
public int write(ChannelBuffer bb) {
int iLenStartIndex = bb.writerIndex();
bb.writeInt(ipv4NodeId);
bb.writeInt(identifier);
return bb.writerIndex() - iLenStartIndex;
}
......@@ -72,28 +67,4 @@ public class PcepNaiIpv4NodeId implements PcepNai {
public static PcepNaiIpv4NodeId read(ChannelBuffer bb) {
return new PcepNaiIpv4NodeId(bb.readInt());
}
@Override
public int hashCode() {
return Objects.hash(ipv4NodeId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PcepNaiIpv4NodeId) {
PcepNaiIpv4NodeId other = (PcepNaiIpv4NodeId) obj;
return Objects.equals(this.ipv4NodeId, other.ipv4NodeId);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("IPv4NodeId", ipv4NodeId)
.toString();
}
}
......
......@@ -15,20 +15,21 @@
*/
package org.onlab.packet;
import org.onlab.util.Identifier;
/**
* The class representing a network device chassisId.
* This class is immutable.
*/
public final class ChassisId {
public final class ChassisId extends Identifier<Long> {
private static final long UNKNOWN = 0;
private final long value;
/**
* Default constructor.
*/
public ChassisId() {
this.value = ChassisId.UNKNOWN;
super(ChassisId.UNKNOWN);
}
/**
......@@ -37,7 +38,7 @@ public final class ChassisId {
* @param value the value to use.
*/
public ChassisId(long value) {
this.value = value;
super(value);
}
/**
......@@ -46,7 +47,7 @@ public final class ChassisId {
* @param value the value to use.
*/
public ChassisId(String value) {
this.value = Long.parseLong(value, 16);
super(Long.parseLong(value, 16));
}
/**
......@@ -55,7 +56,7 @@ public final class ChassisId {
* @return the value of the chassis id.
*/
public long value() {
return value;
return identifier;
}
/**
......@@ -65,22 +66,11 @@ public final class ChassisId {
*/
@Override
public String toString() {
return Long.toHexString(this.value);
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ChassisId)) {
return false;
}
ChassisId otherChassisId = (ChassisId) other;
return value == otherChassisId.value;
return Long.toHexString(identifier);
}
@Override
public int hashCode() {
return Long.hashCode(value);
return Long.hashCode(identifier);
}
}
......
......@@ -15,13 +15,12 @@
*/
package org.onlab.packet;
import org.onlab.util.Identifier;
/**
* Representation of a VLAN ID.
*/
public class VlanId {
private final short value;
public class VlanId extends Identifier<Short> {
// Based on convention used elsewhere? Check and change if needed
public static final short UNTAGGED = (short) 0xffff;
......@@ -37,11 +36,11 @@ public class VlanId {
public static final short MAX_VLAN = 4095;
protected VlanId() {
this.value = UNTAGGED;
super(UNTAGGED);
}
protected VlanId(short value) {
this.value = value;
super(value);
}
public static VlanId vlanId() {
......@@ -65,38 +64,15 @@ public class VlanId {
}
public short toShort() {
return this.value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof VlanId) {
VlanId other = (VlanId) obj;
if (this.value == other.value) {
return true;
}
}
return false;
}
@Override
public int hashCode() {
return this.value;
return this.identifier;
}
@Override
public String toString() {
if (this.value == ANY_VALUE) {
if (this.identifier == ANY_VALUE) {
return "Any";
}
return String.valueOf(this.value);
return String.valueOf(this.identifier);
}
}
......