[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/domain/IntentDomainId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainId.java
index 554702a..5b3248c 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainId.java
@@ -16,8 +16,7 @@
package org.onosproject.incubator.net.domain;
import com.google.common.annotations.Beta;
-
-import java.util.Objects;
+import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -25,10 +24,7 @@
* Intent domain identifier.
*/
@Beta
-public class IntentDomainId {
-
- private final String id;
-
+public class IntentDomainId extends Identifier<String> {
/**
* Creates an intent domain identifier from the specified string representation.
*
@@ -43,7 +39,7 @@
* Constructor for serializer.
*/
IntentDomainId() {
- this.id = null;
+ super(null);
}
/**
@@ -52,28 +48,6 @@
* @param value the underlying value of this ID
*/
IntentDomainId(String value) {
- this.id = checkNotNull(value, "Intent domain ID cannot be null.");
- }
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof IntentDomainId)) {
- return false;
- }
- IntentDomainId that = (IntentDomainId) obj;
- return Objects.equals(this.id, that.id);
- }
-
- @Override
- public String toString() {
- return id;
+ super(checkNotNull(value, "Intent domain ID cannot be null."));
}
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmEntityId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmEntityId.java
index 5bf8674..7b594c2 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmEntityId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmEntityId.java
@@ -15,29 +15,29 @@
*/
package org.onosproject.incubator.net.faultmanagement.alarm;
-import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.ImmutableSet;
+import org.onlab.util.Identifier;
+
import java.net.URI;
-import java.util.Objects;
import java.util.Set;
+import static com.google.common.base.Preconditions.checkArgument;
+
/**
* Immutable representation of a alarm source. It is meaningful within the
* context of a device.
*/
-public final class AlarmEntityId {
+public final class AlarmEntityId extends Identifier<URI> {
public static final AlarmEntityId NONE = new AlarmEntityId(URI.create("none:none"));
public static final Set<String> SCHEMES = ImmutableSet.of("none", "port", "och", "other");
- private final URI uri;
-
private AlarmEntityId(final URI uri) {
- this.uri = uri;
+ super(uri);
}
protected AlarmEntityId() {
- uri = NONE.uri;
+ super(NONE.identifier);
}
public static AlarmEntityId alarmEntityId(final String string) {
@@ -48,28 +48,4 @@
checkArgument(SCHEMES.contains(uri.getScheme()), "Unexpected scheme");
return new AlarmEntityId(uri);
}
-
- @Override
- public String toString() {
- return uri.toString();
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(uri);
-
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof AlarmEntityId) {
- final AlarmEntityId other = (AlarmEntityId) obj;
- return Objects.equals(this.uri, other.uri);
- }
- return false;
- }
-
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmId.java
index 4e65009..7c16d98 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/faultmanagement/alarm/AlarmId.java
@@ -16,8 +16,8 @@
package org.onosproject.incubator.net.faultmanagement.alarm;
import com.google.common.annotations.Beta;
-import java.util.Objects;
-import static com.google.common.base.MoreObjects.toStringHelper;
+import org.onlab.util.Identifier;
+
import static com.google.common.base.Preconditions.checkArgument;
/**
* Alarm identifier suitable as an external key.
@@ -25,9 +25,8 @@
* This class is immutable.</p>
*/
@Beta
-public final class AlarmId {
+public final class AlarmId extends Identifier<Long> {
- private final long id;
public static final AlarmId NONE = new AlarmId();
/**
@@ -36,12 +35,12 @@
* @param id the id
*/
private AlarmId(long id) {
+ super(id);
checkArgument(id != 0L, "id must be non-zero");
- this.id = id;
}
private AlarmId() {
- this.id = 0L;
+ super(0L);
}
/**
@@ -60,29 +59,6 @@
* @return backing integer index
*/
public long fingerprint() {
- return id;
+ return identifier;
}
-
- @Override
- public int hashCode() {
- return Objects.hash(id);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof AlarmId) {
- AlarmId other = (AlarmId) obj;
- return Objects.equals(this.id, other.id);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return toStringHelper(this).add("id", id).toString();
- }
-
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java
index 6fe7067..25af76d 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java
@@ -16,48 +16,36 @@
package org.onosproject.incubator.net.resource.label;
import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
import org.onosproject.net.resource.ResourceId;
-import java.util.Objects;
-
/**
* Representation of a label.
*/
@Beta
-public final class LabelResourceId implements ResourceId {
+public final class LabelResourceId extends Identifier<Long> implements ResourceId {
- private long labelId;
-
+ /**
+ * Creates a new label identifier.
+ *
+ * @param labelResourceId backing identifier value
+ * @return label identifier
+ */
public static LabelResourceId labelResourceId(long labelResourceId) {
return new LabelResourceId(labelResourceId);
}
// Public construction is prohibited
private LabelResourceId(long labelId) {
- this.labelId = labelId;
+ super(labelId);
}
+ /**
+ * Returns label identifier.
+ *
+ * @return label identifier
+ */
public long labelId() {
- return labelId;
+ return identifier;
}
-
- @Override
- public int hashCode() {
- return Objects.hashCode(labelId);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof LabelResourceId) {
- LabelResourceId that = (LabelResourceId) obj;
- return Objects.equals(this.labelId, that.labelId);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return String.valueOf(this.labelId);
- }
-
}
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);
}
-
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/NetworkId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/NetworkId.java
index 2712328..b3d920b 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/NetworkId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/NetworkId.java
@@ -16,14 +16,13 @@
package org.onosproject.incubator.net.virtual;
import com.google.common.annotations.Beta;
-
-import java.util.Objects;
+import org.onlab.util.Identifier;
/**
* Representation of network identity.
*/
@Beta
-public final class NetworkId {
+public final class NetworkId extends Identifier<Long> {
/**
* Represents no network, or an unspecified network.
@@ -35,18 +34,15 @@
*/
public static final NetworkId PHYSICAL = networkId(0L);
-
- private final long id;
-
// Public construction is prohibited
private NetworkId(long id) {
- this.id = id;
+ super(id);
}
// Default constructor for serialization
protected NetworkId() {
- this.id = -1;
+ super(-1L);
}
/**
@@ -58,27 +54,4 @@
public static NetworkId networkId(long id) {
return new NetworkId(id);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(id);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof NetworkId) {
- final NetworkId that = (NetworkId) obj;
- return this.getClass() == that.getClass() && this.id == that.id;
- }
- return false;
- }
-
- @Override
- public String toString() {
- return Long.toString(id);
- }
-
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java
index 196c17d..7488be0 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java
@@ -16,8 +16,7 @@
package org.onosproject.incubator.net.virtual;
import com.google.common.annotations.Beta;
-
-import java.util.Objects;
+import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkArgument;
@@ -25,26 +24,22 @@
* Representation of network tenant.
*/
@Beta
-public final class TenantId {
+public final class TenantId extends Identifier<String> {
/**
* Represents no tenant, or an unspecified tenant.
*/
public static final TenantId NONE = new TenantId();
-
- private final String id;
-
// Public construction is prohibited
private TenantId(String id) {
+ super(id);
checkArgument(id != null && id.length() > 0, "Tenant ID cannot be null or empty");
- this.id = id;
}
-
// Default constructor for serialization
protected TenantId() {
- this.id = "";
+ super("");
}
/**
@@ -56,28 +51,4 @@
public static TenantId tenantId(String id) {
return new TenantId(id);
}
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof TenantId) {
- final TenantId that = (TenantId) obj;
- return this.getClass() == that.getClass() &&
- Objects.equals(this.id, that.id);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return id;
- }
-
}