[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/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();
-    }
-
 }