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

- Refactor most of *Id classes in onos-api package
- Refactor all of *Id classes in incubator package

Change-Id: Ief6322d3fb42c80e82f695e9d4dcee439346215b
diff --git a/core/api/src/main/java/org/onosproject/cluster/NodeId.java b/core/api/src/main/java/org/onosproject/cluster/NodeId.java
index 8b7d540..2ff2cf5 100644
--- a/core/api/src/main/java/org/onosproject/cluster/NodeId.java
+++ b/core/api/src/main/java/org/onosproject/cluster/NodeId.java
@@ -52,5 +52,4 @@
     public int compareTo(NodeId that) {
         return identifier.compareTo(that.identifier);
     }
-
 }
diff --git a/core/api/src/main/java/org/onosproject/cluster/PartitionId.java b/core/api/src/main/java/org/onosproject/cluster/PartitionId.java
index f1deedb..12af622 100644
--- a/core/api/src/main/java/org/onosproject/cluster/PartitionId.java
+++ b/core/api/src/main/java/org/onosproject/cluster/PartitionId.java
@@ -15,16 +15,14 @@
  */
 package org.onosproject.cluster;
 
-import static com.google.common.base.Preconditions.checkArgument;
+import org.onlab.util.Identifier;
 
-import java.util.Objects;
+import static com.google.common.base.Preconditions.checkArgument;
 
 /**
  * {@link Partition} identifier.
  */
-public class PartitionId implements Comparable<PartitionId> {
-
-    private final int id;
+public class PartitionId extends Identifier<Integer> implements Comparable<PartitionId> {
 
     /**
      * Creates a partition identifier from an integer.
@@ -32,8 +30,8 @@
      * @param id input integer
      */
     public PartitionId(int id) {
+        super(id);
         checkArgument(id >= 0, "partition id must be non-negative");
-        this.id = id;
     }
 
     /**
@@ -51,33 +49,11 @@
      * @return number
      */
     public int asInt() {
-        return id;
-    }
-
-    @Override
-    public int hashCode() {
-        return id;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof PartitionId) {
-            final PartitionId other = (PartitionId) obj;
-            return Objects.equals(this.id, other.id);
-        }
-        return false;
-    }
-
-    @Override
-    public String toString() {
-        return String.valueOf(id);
+        return id();
     }
 
     @Override
     public int compareTo(PartitionId that) {
-        return Integer.compare(this.id, that.id);
+        return Integer.compare(this.identifier, that.identifier);
     }
 }
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java b/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java
index 243e521..7467c3c 100644
--- a/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java
+++ b/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java
@@ -22,6 +22,7 @@
 /**
  * Default implementation of {@link GroupId}.
  */
+// TODO: require refactor to extend from Identifier base class
 public class DefaultGroupId implements GroupId {
 
     private final int id;
diff --git a/core/api/src/main/java/org/onosproject/core/GroupId.java b/core/api/src/main/java/org/onosproject/core/GroupId.java
index 739fc7f..3bfd290 100644
--- a/core/api/src/main/java/org/onosproject/core/GroupId.java
+++ b/core/api/src/main/java/org/onosproject/core/GroupId.java
@@ -18,6 +18,7 @@
 /**
  * Group identifier.
  */
+// TODO: require refactor to extend from Identifier base class
 public interface GroupId {
 
     /**
diff --git a/core/api/src/main/java/org/onosproject/net/NshServicePathId.java b/core/api/src/main/java/org/onosproject/net/NshServicePathId.java
index 16fbc4e..1fd478f 100644
--- a/core/api/src/main/java/org/onosproject/net/NshServicePathId.java
+++ b/core/api/src/main/java/org/onosproject/net/NshServicePathId.java
@@ -15,16 +15,12 @@
  */
 package org.onosproject.net;
 
-import java.util.Objects;
-
-import com.google.common.base.MoreObjects;
+import org.onlab.util.Identifier;
 
 /*
  * Representation of NSH Service path Identifier
  */
-public final class NshServicePathId {
-
-    private final int servicePathId;
+public final class NshServicePathId extends Identifier<Integer> {
 
     /**
      * Default constructor.
@@ -32,7 +28,7 @@
      * @param servicePathId nsh service path identifier
      */
     private NshServicePathId(int servicePathId) {
-        this.servicePathId = servicePathId;
+        super(servicePathId);
     }
 
     /**
@@ -45,39 +41,13 @@
         return new NshServicePathId(servicePathId);
     }
 
-
     /**
      * Returns nsh context service path identifier.
      *
      * @return the nsh context service path id
      */
     public int servicePathId() {
-        return servicePathId;
-    }
-
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(servicePathId);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof NshServicePathId)) {
-            return false;
-        }
-        final NshServicePathId other = (NshServicePathId) obj;
-        return   Objects.equals(this.servicePathId, other.servicePathId);
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(this)
-                .add("servicePathId", servicePathId)
-                .toString();
+        return identifier;
     }
 }
 
diff --git a/core/api/src/main/java/org/onosproject/net/flow/FlowId.java b/core/api/src/main/java/org/onosproject/net/flow/FlowId.java
index 52500f5..b6d952f 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/FlowId.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/FlowId.java
@@ -15,17 +15,15 @@
  */
 package org.onosproject.net.flow;
 
-import com.google.common.base.Objects;
+import org.onlab.util.Identifier;
 
 /**
  * Representation of a Flow ID.
  */
-public final class FlowId {
-
-    private final long flowid;
+public final class FlowId extends Identifier<Long> {
 
     private FlowId(long id) {
-        this.flowid = id;
+        super(id);
     }
 
     public static FlowId valueOf(long id) {
@@ -33,26 +31,6 @@
     }
 
     public long value() {
-        return flowid;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (obj.getClass()  == this.getClass()) {
-            FlowId that = (FlowId) obj;
-            return Objects.equal(this.flowid, that.flowid);
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hashCode(this.flowid);
+        return this.identifier;
     }
 }
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentId.java b/core/api/src/main/java/org/onosproject/net/intent/IntentId.java
index b9a30d2..4494eea 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentId.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentId.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.intent;
 
 import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
 import org.onosproject.net.newresource.ResourceConsumer;
 
 /**
@@ -23,9 +24,7 @@
  * <p>This class is immutable.</p>
  */
 @Beta
-public final class IntentId implements ResourceConsumer {
-
-    private final long value;
+public final class IntentId extends Identifier<Long> implements ResourceConsumer {
 
     /**
      * Creates an intent identifier from the specified long representation.
@@ -41,7 +40,7 @@
      * Constructor for serializer.
      */
     IntentId() {
-        this.value = 0;
+        super(0L);
     }
 
     /**
@@ -50,7 +49,7 @@
      * @param value the underlying value of this ID
      */
     IntentId(long value) {
-        this.value = value;
+        super(value);
     }
 
     /**
@@ -59,29 +58,12 @@
      * @return the value
      */
     public long fingerprint() {
-        return value;
-    }
-
-    @Override
-    public int hashCode() {
-        return Long.hashCode(value);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == this) {
-            return true;
-        }
-        if (!(obj instanceof IntentId)) {
-            return false;
-        }
-        IntentId that = (IntentId) obj;
-        return this.value == that.value;
+        return identifier;
     }
 
     @Override
     public String toString() {
-        return "0x" + Long.toHexString(value);
+        return "0x" + Long.toHexString(identifier);
     }
 
 }
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterId.java b/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
index 43c4141..4ed74b4 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
@@ -15,64 +15,39 @@
  */
 package org.onosproject.net.meter;
 
+import org.onlab.util.Identifier;
+
 import static com.google.common.base.Preconditions.checkArgument;
 
 /**
  * A representation of a meter id.
  * Uniquely identifies a meter in the scope of a single device.
  */
-public final class MeterId {
+public final class MeterId extends Identifier<Long> {
 
     static final long MAX = 0xFFFF0000;
 
-    private final long id;
-
     public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFD);
     public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE);
     public static final MeterId ALL = new MeterId(0xFFFFFFFF);
 
     private MeterId(long id) {
+        super(id);
         checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000");
-        this.id = id;
-    }
-
-    /**
-     * The integer representation of the meter id.
-     *
-     * @return a long
-     */
-    public long id() {
-        return id;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        MeterId meterId = (MeterId) o;
-
-        return id == meterId.id;
-
-    }
-
-    @Override
-    public int hashCode() {
-        return Long.hashCode(id);
     }
 
     @Override
     public String toString() {
-        return Long.toHexString(this.id);
+        return Long.toHexString(this.identifier);
     }
 
+    /**
+     * Creates a new meter identifier.
+     *
+     * @param id backing identifier value
+     * @return meter identifier
+     */
     public static MeterId meterId(long id) {
         return new MeterId(id);
-
     }
-
 }
diff --git a/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java b/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java
index 1e6780f..c9e28a0 100644
--- a/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java
+++ b/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java
@@ -15,20 +15,16 @@
  */
 package org.onosproject.net.topology;
 
-import java.util.Objects;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
+import org.onlab.util.Identifier;
 
 /**
  * Representation of the topology cluster identity.
  */
-public final class ClusterId {
-
-    private final int id;
+public final class ClusterId extends Identifier<Integer> {
 
     // Public construction is prohibit
     private ClusterId(int id) {
-        this.id = id;
+        super(id);
     }
 
     /**
@@ -48,29 +44,6 @@
      * @return backing integer index
      */
     public int index() {
-        return id;
+        return identifier;
     }
-
-    @Override
-    public int hashCode() {
-        return id;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof ClusterId) {
-            final ClusterId other = (ClusterId) obj;
-            return Objects.equals(this.id, other.id);
-        }
-        return false;
-    }
-
-    @Override
-    public String toString() {
-        return toStringHelper(this).add("id", id).toString();
-    }
-
 }
diff --git a/core/api/src/main/java/org/onosproject/store/primitives/TransactionId.java b/core/api/src/main/java/org/onosproject/store/primitives/TransactionId.java
index 21cf24b..c47de8b 100644
--- a/core/api/src/main/java/org/onosproject/store/primitives/TransactionId.java
+++ b/core/api/src/main/java/org/onosproject/store/primitives/TransactionId.java
@@ -15,42 +15,24 @@
  */
 package org.onosproject.store.primitives;
 
-import com.google.common.base.Objects;
+import org.onlab.util.Identifier;
 
 /**
  * Transaction identifier.
  */
-public final class TransactionId {
+public final class TransactionId extends Identifier<String> {
 
+    /**
+     * Creates a new transaction identifier.
+     *
+     * @param id backing identifier value
+     * @return transaction identifier
+     */
     public static TransactionId from(String id) {
         return new TransactionId(id);
     }
 
-    private final String id;
-
     private TransactionId(String id) {
-        this.id = id;
-    }
-
-    @Override
-    public String toString() {
-        return id;
-    }
-
-    @Override
-    public int hashCode() {
-        return id.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object other) {
-        if (this == other) {
-            return true;
-        }
-        if (other instanceof TransactionId) {
-            TransactionId that = (TransactionId) other;
-            return Objects.equal(this.id, that.id);
-        }
-        return false;
+        super(id);
     }
 }
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/ButtonId.java b/core/api/src/main/java/org/onosproject/ui/topo/ButtonId.java
index 05b7317..262c378 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/ButtonId.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/ButtonId.java
@@ -16,14 +16,12 @@
 
 package org.onosproject.ui.topo;
 
-import com.google.common.base.MoreObjects;
+import org.onlab.util.Identifier;
 
 /**
  * Designates the identity of a button on the topology view panels.
  */
-public class ButtonId {
-
-    private final String id;
+public class ButtonId extends Identifier<String> {
 
     /**
      * Creates a button ID with the given identifier.
@@ -31,39 +29,6 @@
      * @param id identifier for the button
      */
     public ButtonId(String id) {
-        this.id = id;
-    }
-
-    /**
-     * Returns the identifier for this button.
-     *
-     * @return identifier
-     */
-    public String id() {
-        return id;
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(getClass())
-                .add("id", id()).toString();
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        ButtonId that = (ButtonId) o;
-        return id.equals(that.id);
-    }
-
-    @Override
-    public int hashCode() {
-        return id.hashCode();
+        super(id);
     }
 }