[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/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/DomainTunnelId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/DomainTunnelId.java
index 430823c..a267c4e 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/DomainTunnelId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/DomainTunnelId.java
@@ -16,12 +16,12 @@
package org.onosproject.incubator.net.tunnel;
+import org.onlab.util.Identifier;
+
/**
* A wrapper class for a long used to identify domain level tunnels.
*/
-public final class DomainTunnelId {
-
- private final long value;
+public final class DomainTunnelId extends Identifier<Long> {
/**
* Creates a tunnel identifier from the specified tunnel.
@@ -47,7 +47,7 @@
* Constructor for serializer.
*/
protected DomainTunnelId() {
- this.value = 0;
+ super(0L);
}
/**
@@ -56,37 +56,11 @@
* @param value the underlying value of this domain ID
*/
public DomainTunnelId(long value) {
- this.value = value;
- }
-
- /**
- * Returns the backing value of this domain ID.
- *
- * @return the long value
- */
- public long id() {
- return value;
- }
-
- @Override
- public int hashCode() {
- return Long.hashCode(value);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof DomainTunnelId)) {
- return false;
- }
- DomainTunnelId that = (DomainTunnelId) obj;
- return this.value == that.value;
+ super(value);
}
@Override
public String toString() {
- return "0x" + Long.toHexString(value);
+ return "0x" + Long.toHexString(identifier);
}
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/NetworkTunnelId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/NetworkTunnelId.java
index a3de788..e3c2338 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/NetworkTunnelId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/NetworkTunnelId.java
@@ -17,14 +17,13 @@
package org.onosproject.incubator.net.tunnel;
import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
/**
* Representation of a Network Tunnel Id.
*/
@Beta
-public final class NetworkTunnelId {
- private final long value;
-
+public final class NetworkTunnelId extends Identifier<Long> {
/**
* Creates an tunnel identifier from the specified tunnel.
*
@@ -43,7 +42,7 @@
* Constructor for serializer.
*/
NetworkTunnelId() {
- this.value = 0;
+ super(0L);
}
/**
@@ -52,38 +51,11 @@
* @param value the underlying value of this ID
*/
public NetworkTunnelId(long value) {
- this.value = value;
- }
-
- /**
- * Returns the backing value.
- *
- * @return the value
- */
- public long id() {
- return value;
- }
-
- @Override
- public int hashCode() {
- return Long.hashCode(value);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof NetworkTunnelId)) {
- return false;
- }
- NetworkTunnelId that = (NetworkTunnelId) obj;
- return this.value == that.value;
+ super(value);
}
@Override
public String toString() {
- return "0x" + Long.toHexString(value);
+ return "0x" + Long.toHexString(identifier);
}
-
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java
index d599486..2017850 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java
@@ -16,66 +16,44 @@
package org.onosproject.incubator.net.tunnel;
-import java.util.Objects;
-
import com.google.common.annotations.Beta;
import com.google.common.primitives.UnsignedLongs;
+import org.onlab.util.Identifier;
/**
* Representation of a label Id, a logical port identifier.
*/
@Beta
-public final class OpticalLogicId {
- /**
- * Represents a logical Id.
- */
- private final long logicId;
+public final class OpticalLogicId extends Identifier<Long> {
- /**
- * Constructor, public creation is prohibited.
- */
- private OpticalLogicId(long id) {
- this.logicId = id;
- }
+ /**
+ * Constructor, public creation is prohibited.
+ */
+ private OpticalLogicId(long id) {
+ super(id);
+ }
- /**
- * Returns the LabelId representing the specified long value.
- *
- * @param id identifier as long value
- * @return LabelId
- */
- public static OpticalLogicId logicId(long id) {
- return new OpticalLogicId(id);
- }
+ /**
+ * Returns the LabelId representing the specified long value.
+ *
+ * @param id identifier as long value
+ * @return LabelId
+ */
+ public static OpticalLogicId logicId(long id) {
+ return new OpticalLogicId(id);
+ }
- public static OpticalLogicId logicId(String string) {
- return new OpticalLogicId(UnsignedLongs.decode(string));
- }
+ /**
+ * Returns the LabelId representing the specified string value.
+ *
+ * @param string identifier as string value
+ * @return LabelId
+ */
+ public static OpticalLogicId logicId(String string) {
+ return new OpticalLogicId(UnsignedLongs.decode(string));
+ }
- public long toLong() {
- return logicId;
- }
-
- @Override
- public String toString() {
- return UnsignedLongs.toString(logicId);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(logicId);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof OpticalLogicId) {
- final OpticalLogicId other = (OpticalLogicId) obj;
- return this.logicId == other.logicId;
- }
- return false;
- }
-
+ public long toLong() {
+ return identifier;
+ }
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelId.java
index 5a3f97f..ac5e7e0 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelId.java
@@ -17,14 +17,13 @@
package org.onosproject.incubator.net.tunnel;
import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
/**
* Representation of a Tunnel Id.
*/
@Beta
-public final class TunnelId {
- private final long value;
-
+public final class TunnelId extends Identifier<Long> {
/**
* Creates an tunnel identifier from the specified tunnel.
*
@@ -43,7 +42,7 @@
* Constructor for serializer.
*/
TunnelId() {
- this.value = 0;
+ super(0L);
}
/**
@@ -52,38 +51,11 @@
* @param value the underlying value of this ID
*/
TunnelId(long value) {
- this.value = value;
- }
-
- /**
- * Returns the backing value.
- *
- * @return the value
- */
- public long id() {
- return value;
- }
-
- @Override
- public int hashCode() {
- return Long.hashCode(value);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof TunnelId)) {
- return false;
- }
- TunnelId that = (TunnelId) obj;
- return this.value == that.value;
+ super(value);
}
@Override
public String toString() {
- return "0x" + Long.toHexString(value);
+ return "0x" + Long.toHexString(identifier);
}
-
}