[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
diff --git a/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpId.java b/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpId.java
index 45d15bd..ca469cf 100644
--- a/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpId.java
+++ b/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpId.java
@@ -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 @@
  * 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 @@
      * @param ipAddress Ip address
      */
     public BgpId(IpAddress ipAddress) {
-        this.ipAddress = ipAddress;
+        super(ipAddress);
     }
 
     /**
@@ -58,32 +58,7 @@
      * @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;
     }
 
     /**
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbDatapathId.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbDatapathId.java
index 02989af..4230907 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbDatapathId.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbDatapathId.java
@@ -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 @@
      * @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;
     }
 }
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java
index bf724fa..ee9f1ec 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java
@@ -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 @@
      * @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;
     }
 }
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java
index 60146c8..bed44fb 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java
@@ -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 @@
      * @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 @@
      * @return the value of the NodeId.
      */
     public String nodeId() {
-        return SCHEME + ":" + nodeId;
+        return SCHEME + ":" + identifier;
     }
 
     /**
diff --git a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PccId.java b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PccId.java
index 3ff622b..0981c02 100755
--- a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PccId.java
+++ b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PccId.java
@@ -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 @@
      * @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;
     }
 
     /**
diff --git a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4NodeId.java b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4NodeId.java
index 1d4ce5d..ff69561 100644
--- a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4NodeId.java
+++ b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4NodeId.java
@@ -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 @@
     @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 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();
-    }
 }
diff --git a/utils/misc/src/main/java/org/onlab/packet/ChassisId.java b/utils/misc/src/main/java/org/onlab/packet/ChassisId.java
index 23c9859..840baf4 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ChassisId.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ChassisId.java
@@ -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 @@
      * @param value the value to use.
      */
     public ChassisId(long value) {
-        this.value = value;
+        super(value);
     }
 
     /**
@@ -46,7 +47,7 @@
      * @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 @@
      * @return the value of the chassis id.
      */
     public long value() {
-        return value;
+        return identifier;
     }
 
     /**
@@ -65,22 +66,11 @@
      */
     @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);
     }
 }
diff --git a/utils/misc/src/main/java/org/onlab/packet/VlanId.java b/utils/misc/src/main/java/org/onlab/packet/VlanId.java
index 4b38308..afda7aa 100644
--- a/utils/misc/src/main/java/org/onlab/packet/VlanId.java
+++ b/utils/misc/src/main/java/org/onlab/packet/VlanId.java
@@ -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 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 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);
     }
 }