Jian Li
Committed by Gerrit Code Review

[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
Showing 22 changed files with 144 additions and 614 deletions
...@@ -52,5 +52,4 @@ public final class NodeId extends Identifier<String> implements Comparable<NodeI ...@@ -52,5 +52,4 @@ public final class NodeId extends Identifier<String> implements Comparable<NodeI
52 public int compareTo(NodeId that) { 52 public int compareTo(NodeId that) {
53 return identifier.compareTo(that.identifier); 53 return identifier.compareTo(that.identifier);
54 } 54 }
55 -
56 } 55 }
......
...@@ -15,16 +15,14 @@ ...@@ -15,16 +15,14 @@
15 */ 15 */
16 package org.onosproject.cluster; 16 package org.onosproject.cluster;
17 17
18 -import static com.google.common.base.Preconditions.checkArgument; 18 +import org.onlab.util.Identifier;
19 19
20 -import java.util.Objects; 20 +import static com.google.common.base.Preconditions.checkArgument;
21 21
22 /** 22 /**
23 * {@link Partition} identifier. 23 * {@link Partition} identifier.
24 */ 24 */
25 -public class PartitionId implements Comparable<PartitionId> { 25 +public class PartitionId extends Identifier<Integer> implements Comparable<PartitionId> {
26 -
27 - private final int id;
28 26
29 /** 27 /**
30 * Creates a partition identifier from an integer. 28 * Creates a partition identifier from an integer.
...@@ -32,8 +30,8 @@ public class PartitionId implements Comparable<PartitionId> { ...@@ -32,8 +30,8 @@ public class PartitionId implements Comparable<PartitionId> {
32 * @param id input integer 30 * @param id input integer
33 */ 31 */
34 public PartitionId(int id) { 32 public PartitionId(int id) {
33 + super(id);
35 checkArgument(id >= 0, "partition id must be non-negative"); 34 checkArgument(id >= 0, "partition id must be non-negative");
36 - this.id = id;
37 } 35 }
38 36
39 /** 37 /**
...@@ -51,33 +49,11 @@ public class PartitionId implements Comparable<PartitionId> { ...@@ -51,33 +49,11 @@ public class PartitionId implements Comparable<PartitionId> {
51 * @return number 49 * @return number
52 */ 50 */
53 public int asInt() { 51 public int asInt() {
54 - return id; 52 + return id();
55 - }
56 -
57 - @Override
58 - public int hashCode() {
59 - return id;
60 - }
61 -
62 - @Override
63 - public boolean equals(Object obj) {
64 - if (this == obj) {
65 - return true;
66 - }
67 - if (obj instanceof PartitionId) {
68 - final PartitionId other = (PartitionId) obj;
69 - return Objects.equals(this.id, other.id);
70 - }
71 - return false;
72 - }
73 -
74 - @Override
75 - public String toString() {
76 - return String.valueOf(id);
77 } 53 }
78 54
79 @Override 55 @Override
80 public int compareTo(PartitionId that) { 56 public int compareTo(PartitionId that) {
81 - return Integer.compare(this.id, that.id); 57 + return Integer.compare(this.identifier, that.identifier);
82 } 58 }
83 } 59 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -22,6 +22,7 @@ import java.util.Objects; ...@@ -22,6 +22,7 @@ import java.util.Objects;
22 /** 22 /**
23 * Default implementation of {@link GroupId}. 23 * Default implementation of {@link GroupId}.
24 */ 24 */
25 +// TODO: require refactor to extend from Identifier base class
25 public class DefaultGroupId implements GroupId { 26 public class DefaultGroupId implements GroupId {
26 27
27 private final int id; 28 private final int id;
......
...@@ -18,6 +18,7 @@ package org.onosproject.core; ...@@ -18,6 +18,7 @@ package org.onosproject.core;
18 /** 18 /**
19 * Group identifier. 19 * Group identifier.
20 */ 20 */
21 +// TODO: require refactor to extend from Identifier base class
21 public interface GroupId { 22 public interface GroupId {
22 23
23 /** 24 /**
......
...@@ -15,16 +15,12 @@ ...@@ -15,16 +15,12 @@
15 */ 15 */
16 package org.onosproject.net; 16 package org.onosproject.net;
17 17
18 -import java.util.Objects; 18 +import org.onlab.util.Identifier;
19 -
20 -import com.google.common.base.MoreObjects;
21 19
22 /* 20 /*
23 * Representation of NSH Service path Identifier 21 * Representation of NSH Service path Identifier
24 */ 22 */
25 -public final class NshServicePathId { 23 +public final class NshServicePathId extends Identifier<Integer> {
26 -
27 - private final int servicePathId;
28 24
29 /** 25 /**
30 * Default constructor. 26 * Default constructor.
...@@ -32,7 +28,7 @@ public final class NshServicePathId { ...@@ -32,7 +28,7 @@ public final class NshServicePathId {
32 * @param servicePathId nsh service path identifier 28 * @param servicePathId nsh service path identifier
33 */ 29 */
34 private NshServicePathId(int servicePathId) { 30 private NshServicePathId(int servicePathId) {
35 - this.servicePathId = servicePathId; 31 + super(servicePathId);
36 } 32 }
37 33
38 /** 34 /**
...@@ -45,39 +41,13 @@ public final class NshServicePathId { ...@@ -45,39 +41,13 @@ public final class NshServicePathId {
45 return new NshServicePathId(servicePathId); 41 return new NshServicePathId(servicePathId);
46 } 42 }
47 43
48 -
49 /** 44 /**
50 * Returns nsh context service path identifier. 45 * Returns nsh context service path identifier.
51 * 46 *
52 * @return the nsh context service path id 47 * @return the nsh context service path id
53 */ 48 */
54 public int servicePathId() { 49 public int servicePathId() {
55 - return servicePathId; 50 + return identifier;
56 - }
57 -
58 -
59 - @Override
60 - public int hashCode() {
61 - return Objects.hash(servicePathId);
62 - }
63 -
64 - @Override
65 - public boolean equals(Object obj) {
66 - if (this == obj) {
67 - return true;
68 - }
69 - if (!(obj instanceof NshServicePathId)) {
70 - return false;
71 - }
72 - final NshServicePathId other = (NshServicePathId) obj;
73 - return Objects.equals(this.servicePathId, other.servicePathId);
74 - }
75 -
76 - @Override
77 - public String toString() {
78 - return MoreObjects.toStringHelper(this)
79 - .add("servicePathId", servicePathId)
80 - .toString();
81 } 51 }
82 } 52 }
83 53
......
...@@ -15,17 +15,15 @@ ...@@ -15,17 +15,15 @@
15 */ 15 */
16 package org.onosproject.net.flow; 16 package org.onosproject.net.flow;
17 17
18 -import com.google.common.base.Objects; 18 +import org.onlab.util.Identifier;
19 19
20 /** 20 /**
21 * Representation of a Flow ID. 21 * Representation of a Flow ID.
22 */ 22 */
23 -public final class FlowId { 23 +public final class FlowId extends Identifier<Long> {
24 -
25 - private final long flowid;
26 24
27 private FlowId(long id) { 25 private FlowId(long id) {
28 - this.flowid = id; 26 + super(id);
29 } 27 }
30 28
31 public static FlowId valueOf(long id) { 29 public static FlowId valueOf(long id) {
...@@ -33,26 +31,6 @@ public final class FlowId { ...@@ -33,26 +31,6 @@ public final class FlowId {
33 } 31 }
34 32
35 public long value() { 33 public long value() {
36 - return flowid; 34 + return this.identifier;
37 - }
38 -
39 - @Override
40 - public boolean equals(Object obj) {
41 - if (this == obj) {
42 - return true;
43 - }
44 - if (obj == null) {
45 - return false;
46 - }
47 - if (obj.getClass() == this.getClass()) {
48 - FlowId that = (FlowId) obj;
49 - return Objects.equal(this.flowid, that.flowid);
50 - }
51 - return false;
52 - }
53 -
54 - @Override
55 - public int hashCode() {
56 - return Objects.hashCode(this.flowid);
57 } 35 }
58 } 36 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.intent; 16 package org.onosproject.net.intent;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 +import org.onlab.util.Identifier;
19 import org.onosproject.net.newresource.ResourceConsumer; 20 import org.onosproject.net.newresource.ResourceConsumer;
20 21
21 /** 22 /**
...@@ -23,9 +24,7 @@ import org.onosproject.net.newresource.ResourceConsumer; ...@@ -23,9 +24,7 @@ import org.onosproject.net.newresource.ResourceConsumer;
23 * <p>This class is immutable.</p> 24 * <p>This class is immutable.</p>
24 */ 25 */
25 @Beta 26 @Beta
26 -public final class IntentId implements ResourceConsumer { 27 +public final class IntentId extends Identifier<Long> implements ResourceConsumer {
27 -
28 - private final long value;
29 28
30 /** 29 /**
31 * Creates an intent identifier from the specified long representation. 30 * Creates an intent identifier from the specified long representation.
...@@ -41,7 +40,7 @@ public final class IntentId implements ResourceConsumer { ...@@ -41,7 +40,7 @@ public final class IntentId implements ResourceConsumer {
41 * Constructor for serializer. 40 * Constructor for serializer.
42 */ 41 */
43 IntentId() { 42 IntentId() {
44 - this.value = 0; 43 + super(0L);
45 } 44 }
46 45
47 /** 46 /**
...@@ -50,7 +49,7 @@ public final class IntentId implements ResourceConsumer { ...@@ -50,7 +49,7 @@ public final class IntentId implements ResourceConsumer {
50 * @param value the underlying value of this ID 49 * @param value the underlying value of this ID
51 */ 50 */
52 IntentId(long value) { 51 IntentId(long value) {
53 - this.value = value; 52 + super(value);
54 } 53 }
55 54
56 /** 55 /**
...@@ -59,29 +58,12 @@ public final class IntentId implements ResourceConsumer { ...@@ -59,29 +58,12 @@ public final class IntentId implements ResourceConsumer {
59 * @return the value 58 * @return the value
60 */ 59 */
61 public long fingerprint() { 60 public long fingerprint() {
62 - return value; 61 + return identifier;
63 - }
64 -
65 - @Override
66 - public int hashCode() {
67 - return Long.hashCode(value);
68 - }
69 -
70 - @Override
71 - public boolean equals(Object obj) {
72 - if (obj == this) {
73 - return true;
74 - }
75 - if (!(obj instanceof IntentId)) {
76 - return false;
77 - }
78 - IntentId that = (IntentId) obj;
79 - return this.value == that.value;
80 } 62 }
81 63
82 @Override 64 @Override
83 public String toString() { 65 public String toString() {
84 - return "0x" + Long.toHexString(value); 66 + return "0x" + Long.toHexString(identifier);
85 } 67 }
86 68
87 } 69 }
......
...@@ -15,64 +15,39 @@ ...@@ -15,64 +15,39 @@
15 */ 15 */
16 package org.onosproject.net.meter; 16 package org.onosproject.net.meter;
17 17
18 +import org.onlab.util.Identifier;
19 +
18 import static com.google.common.base.Preconditions.checkArgument; 20 import static com.google.common.base.Preconditions.checkArgument;
19 21
20 /** 22 /**
21 * A representation of a meter id. 23 * A representation of a meter id.
22 * Uniquely identifies a meter in the scope of a single device. 24 * Uniquely identifies a meter in the scope of a single device.
23 */ 25 */
24 -public final class MeterId { 26 +public final class MeterId extends Identifier<Long> {
25 27
26 static final long MAX = 0xFFFF0000; 28 static final long MAX = 0xFFFF0000;
27 29
28 - private final long id;
29 -
30 public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFD); 30 public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFD);
31 public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE); 31 public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE);
32 public static final MeterId ALL = new MeterId(0xFFFFFFFF); 32 public static final MeterId ALL = new MeterId(0xFFFFFFFF);
33 33
34 private MeterId(long id) { 34 private MeterId(long id) {
35 + super(id);
35 checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000"); 36 checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000");
36 - this.id = id;
37 - }
38 -
39 - /**
40 - * The integer representation of the meter id.
41 - *
42 - * @return a long
43 - */
44 - public long id() {
45 - return id;
46 - }
47 -
48 - @Override
49 - public boolean equals(Object o) {
50 - if (this == o) {
51 - return true;
52 - }
53 - if (o == null || getClass() != o.getClass()) {
54 - return false;
55 - }
56 -
57 - MeterId meterId = (MeterId) o;
58 -
59 - return id == meterId.id;
60 -
61 - }
62 -
63 - @Override
64 - public int hashCode() {
65 - return Long.hashCode(id);
66 } 37 }
67 38
68 @Override 39 @Override
69 public String toString() { 40 public String toString() {
70 - return Long.toHexString(this.id); 41 + return Long.toHexString(this.identifier);
71 } 42 }
72 43
44 + /**
45 + * Creates a new meter identifier.
46 + *
47 + * @param id backing identifier value
48 + * @return meter identifier
49 + */
73 public static MeterId meterId(long id) { 50 public static MeterId meterId(long id) {
74 return new MeterId(id); 51 return new MeterId(id);
75 -
76 } 52 }
77 -
78 } 53 }
......
...@@ -15,20 +15,16 @@ ...@@ -15,20 +15,16 @@
15 */ 15 */
16 package org.onosproject.net.topology; 16 package org.onosproject.net.topology;
17 17
18 -import java.util.Objects; 18 +import org.onlab.util.Identifier;
19 -
20 -import static com.google.common.base.MoreObjects.toStringHelper;
21 19
22 /** 20 /**
23 * Representation of the topology cluster identity. 21 * Representation of the topology cluster identity.
24 */ 22 */
25 -public final class ClusterId { 23 +public final class ClusterId extends Identifier<Integer> {
26 -
27 - private final int id;
28 24
29 // Public construction is prohibit 25 // Public construction is prohibit
30 private ClusterId(int id) { 26 private ClusterId(int id) {
31 - this.id = id; 27 + super(id);
32 } 28 }
33 29
34 /** 30 /**
...@@ -48,29 +44,6 @@ public final class ClusterId { ...@@ -48,29 +44,6 @@ public final class ClusterId {
48 * @return backing integer index 44 * @return backing integer index
49 */ 45 */
50 public int index() { 46 public int index() {
51 - return id; 47 + return identifier;
52 } 48 }
53 -
54 - @Override
55 - public int hashCode() {
56 - return id;
57 - }
58 -
59 - @Override
60 - public boolean equals(Object obj) {
61 - if (this == obj) {
62 - return true;
63 - }
64 - if (obj instanceof ClusterId) {
65 - final ClusterId other = (ClusterId) obj;
66 - return Objects.equals(this.id, other.id);
67 - }
68 - return false;
69 - }
70 -
71 - @Override
72 - public String toString() {
73 - return toStringHelper(this).add("id", id).toString();
74 - }
75 -
76 } 49 }
......
...@@ -15,42 +15,24 @@ ...@@ -15,42 +15,24 @@
15 */ 15 */
16 package org.onosproject.store.primitives; 16 package org.onosproject.store.primitives;
17 17
18 -import com.google.common.base.Objects; 18 +import org.onlab.util.Identifier;
19 19
20 /** 20 /**
21 * Transaction identifier. 21 * Transaction identifier.
22 */ 22 */
23 -public final class TransactionId { 23 +public final class TransactionId extends Identifier<String> {
24 - 24 +
25 + /**
26 + * Creates a new transaction identifier.
27 + *
28 + * @param id backing identifier value
29 + * @return transaction identifier
30 + */
25 public static TransactionId from(String id) { 31 public static TransactionId from(String id) {
26 return new TransactionId(id); 32 return new TransactionId(id);
27 } 33 }
28 34
29 - private final String id;
30 -
31 private TransactionId(String id) { 35 private TransactionId(String id) {
32 - this.id = id; 36 + super(id);
33 - }
34 -
35 - @Override
36 - public String toString() {
37 - return id;
38 - }
39 -
40 - @Override
41 - public int hashCode() {
42 - return id.hashCode();
43 - }
44 -
45 - @Override
46 - public boolean equals(Object other) {
47 - if (this == other) {
48 - return true;
49 - }
50 - if (other instanceof TransactionId) {
51 - TransactionId that = (TransactionId) other;
52 - return Objects.equal(this.id, that.id);
53 - }
54 - return false;
55 } 37 }
56 } 38 }
......
...@@ -16,14 +16,12 @@ ...@@ -16,14 +16,12 @@
16 16
17 package org.onosproject.ui.topo; 17 package org.onosproject.ui.topo;
18 18
19 -import com.google.common.base.MoreObjects; 19 +import org.onlab.util.Identifier;
20 20
21 /** 21 /**
22 * Designates the identity of a button on the topology view panels. 22 * Designates the identity of a button on the topology view panels.
23 */ 23 */
24 -public class ButtonId { 24 +public class ButtonId extends Identifier<String> {
25 -
26 - private final String id;
27 25
28 /** 26 /**
29 * Creates a button ID with the given identifier. 27 * Creates a button ID with the given identifier.
...@@ -31,39 +29,6 @@ public class ButtonId { ...@@ -31,39 +29,6 @@ public class ButtonId {
31 * @param id identifier for the button 29 * @param id identifier for the button
32 */ 30 */
33 public ButtonId(String id) { 31 public ButtonId(String id) {
34 - this.id = id; 32 + super(id);
35 - }
36 -
37 - /**
38 - * Returns the identifier for this button.
39 - *
40 - * @return identifier
41 - */
42 - public String id() {
43 - return id;
44 - }
45 -
46 - @Override
47 - public String toString() {
48 - return MoreObjects.toStringHelper(getClass())
49 - .add("id", id()).toString();
50 - }
51 -
52 - @Override
53 - public boolean equals(Object o) {
54 - if (this == o) {
55 - return true;
56 - }
57 - if (o == null || getClass() != o.getClass()) {
58 - return false;
59 - }
60 -
61 - ButtonId that = (ButtonId) o;
62 - return id.equals(that.id);
63 - }
64 -
65 - @Override
66 - public int hashCode() {
67 - return id.hashCode();
68 } 33 }
69 } 34 }
......
...@@ -15,24 +15,20 @@ ...@@ -15,24 +15,20 @@
15 */ 15 */
16 package org.onosproject.store.intent.impl; 16 package org.onosproject.store.intent.impl;
17 17
18 -import com.google.common.base.MoreObjects; 18 +import org.onlab.util.Identifier;
19 -
20 -import java.util.Objects;
21 19
22 /** 20 /**
23 * Identifies a partition of the intent keyspace which will be assigned to and 21 * Identifies a partition of the intent keyspace which will be assigned to and
24 * processed by a single ONOS instance at a time. 22 * processed by a single ONOS instance at a time.
25 */ 23 */
26 -final class PartitionId { 24 +final class PartitionId extends Identifier<Integer> {
27 - private final int id;
28 -
29 /** 25 /**
30 * Creates a new partition ID. 26 * Creates a new partition ID.
31 * 27 *
32 * @param id the partition ID 28 * @param id the partition ID
33 */ 29 */
34 PartitionId(int id) { 30 PartitionId(int id) {
35 - this.id = id; 31 + super(id);
36 } 32 }
37 33
38 /** 34 /**
...@@ -41,28 +37,6 @@ final class PartitionId { ...@@ -41,28 +37,6 @@ final class PartitionId {
41 * @return ID value 37 * @return ID value
42 */ 38 */
43 int value() { 39 int value() {
44 - return id; 40 + return identifier;
45 - }
46 -
47 - @Override
48 - public boolean equals(Object o) {
49 - if (!(o instanceof PartitionId)) {
50 - return false;
51 - }
52 -
53 - PartitionId that = (PartitionId) o;
54 - return Objects.equals(this.id, that.id);
55 - }
56 -
57 - @Override
58 - public int hashCode() {
59 - return id;
60 - }
61 -
62 - @Override
63 - public String toString() {
64 - return MoreObjects.toStringHelper(getClass())
65 - .add("partition ID", id)
66 - .toString();
67 } 41 }
68 } 42 }
......
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
16 package org.onosproject.incubator.net.domain; 16 package org.onosproject.incubator.net.domain;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 - 19 +import org.onlab.util.Identifier;
20 -import java.util.Objects;
21 20
22 import static com.google.common.base.Preconditions.checkNotNull; 21 import static com.google.common.base.Preconditions.checkNotNull;
23 22
...@@ -25,10 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -25,10 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
25 * Intent domain identifier. 24 * Intent domain identifier.
26 */ 25 */
27 @Beta 26 @Beta
28 -public class IntentDomainId { 27 +public class IntentDomainId extends Identifier<String> {
29 -
30 - private final String id;
31 -
32 /** 28 /**
33 * Creates an intent domain identifier from the specified string representation. 29 * Creates an intent domain identifier from the specified string representation.
34 * 30 *
...@@ -43,7 +39,7 @@ public class IntentDomainId { ...@@ -43,7 +39,7 @@ public class IntentDomainId {
43 * Constructor for serializer. 39 * Constructor for serializer.
44 */ 40 */
45 IntentDomainId() { 41 IntentDomainId() {
46 - this.id = null; 42 + super(null);
47 } 43 }
48 44
49 /** 45 /**
...@@ -52,28 +48,6 @@ public class IntentDomainId { ...@@ -52,28 +48,6 @@ public class IntentDomainId {
52 * @param value the underlying value of this ID 48 * @param value the underlying value of this ID
53 */ 49 */
54 IntentDomainId(String value) { 50 IntentDomainId(String value) {
55 - this.id = checkNotNull(value, "Intent domain ID cannot be null."); 51 + super(checkNotNull(value, "Intent domain ID cannot be null."));
56 - }
57 -
58 - @Override
59 - public int hashCode() {
60 - return id.hashCode();
61 - }
62 -
63 - @Override
64 - public boolean equals(Object obj) {
65 - if (obj == this) {
66 - return true;
67 - }
68 - if (!(obj instanceof IntentDomainId)) {
69 - return false;
70 - }
71 - IntentDomainId that = (IntentDomainId) obj;
72 - return Objects.equals(this.id, that.id);
73 - }
74 -
75 - @Override
76 - public String toString() {
77 - return id;
78 } 52 }
79 } 53 }
......
...@@ -15,29 +15,29 @@ ...@@ -15,29 +15,29 @@
15 */ 15 */
16 package org.onosproject.incubator.net.faultmanagement.alarm; 16 package org.onosproject.incubator.net.faultmanagement.alarm;
17 17
18 -import static com.google.common.base.Preconditions.checkArgument;
19 import com.google.common.collect.ImmutableSet; 18 import com.google.common.collect.ImmutableSet;
19 +import org.onlab.util.Identifier;
20 +
20 import java.net.URI; 21 import java.net.URI;
21 -import java.util.Objects;
22 import java.util.Set; 22 import java.util.Set;
23 23
24 +import static com.google.common.base.Preconditions.checkArgument;
25 +
24 /** 26 /**
25 * Immutable representation of a alarm source. It is meaningful within the 27 * Immutable representation of a alarm source. It is meaningful within the
26 * context of a device. 28 * context of a device.
27 */ 29 */
28 -public final class AlarmEntityId { 30 +public final class AlarmEntityId extends Identifier<URI> {
29 31
30 public static final AlarmEntityId NONE = new AlarmEntityId(URI.create("none:none")); 32 public static final AlarmEntityId NONE = new AlarmEntityId(URI.create("none:none"));
31 public static final Set<String> SCHEMES = ImmutableSet.of("none", "port", "och", "other"); 33 public static final Set<String> SCHEMES = ImmutableSet.of("none", "port", "och", "other");
32 34
33 - private final URI uri;
34 -
35 private AlarmEntityId(final URI uri) { 35 private AlarmEntityId(final URI uri) {
36 - this.uri = uri; 36 + super(uri);
37 } 37 }
38 38
39 protected AlarmEntityId() { 39 protected AlarmEntityId() {
40 - uri = NONE.uri; 40 + super(NONE.identifier);
41 } 41 }
42 42
43 public static AlarmEntityId alarmEntityId(final String string) { 43 public static AlarmEntityId alarmEntityId(final String string) {
...@@ -48,28 +48,4 @@ public final class AlarmEntityId { ...@@ -48,28 +48,4 @@ public final class AlarmEntityId {
48 checkArgument(SCHEMES.contains(uri.getScheme()), "Unexpected scheme"); 48 checkArgument(SCHEMES.contains(uri.getScheme()), "Unexpected scheme");
49 return new AlarmEntityId(uri); 49 return new AlarmEntityId(uri);
50 } 50 }
51 -
52 - @Override
53 - public String toString() {
54 - return uri.toString();
55 - }
56 -
57 - @Override
58 - public int hashCode() {
59 - return Objects.hash(uri);
60 -
61 - }
62 -
63 - @Override
64 - public boolean equals(final Object obj) {
65 - if (this == obj) {
66 - return true;
67 - }
68 - if (obj instanceof AlarmEntityId) {
69 - final AlarmEntityId other = (AlarmEntityId) obj;
70 - return Objects.equals(this.uri, other.uri);
71 - }
72 - return false;
73 - }
74 -
75 } 51 }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 package org.onosproject.incubator.net.faultmanagement.alarm; 16 package org.onosproject.incubator.net.faultmanagement.alarm;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 -import java.util.Objects; 19 +import org.onlab.util.Identifier;
20 -import static com.google.common.base.MoreObjects.toStringHelper; 20 +
21 import static com.google.common.base.Preconditions.checkArgument; 21 import static com.google.common.base.Preconditions.checkArgument;
22 /** 22 /**
23 * Alarm identifier suitable as an external key. 23 * Alarm identifier suitable as an external key.
...@@ -25,9 +25,8 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -25,9 +25,8 @@ import static com.google.common.base.Preconditions.checkArgument;
25 * This class is immutable.</p> 25 * This class is immutable.</p>
26 */ 26 */
27 @Beta 27 @Beta
28 -public final class AlarmId { 28 +public final class AlarmId extends Identifier<Long> {
29 29
30 - private final long id;
31 public static final AlarmId NONE = new AlarmId(); 30 public static final AlarmId NONE = new AlarmId();
32 31
33 /** 32 /**
...@@ -36,12 +35,12 @@ public final class AlarmId { ...@@ -36,12 +35,12 @@ public final class AlarmId {
36 * @param id the id 35 * @param id the id
37 */ 36 */
38 private AlarmId(long id) { 37 private AlarmId(long id) {
38 + super(id);
39 checkArgument(id != 0L, "id must be non-zero"); 39 checkArgument(id != 0L, "id must be non-zero");
40 - this.id = id;
41 } 40 }
42 41
43 private AlarmId() { 42 private AlarmId() {
44 - this.id = 0L; 43 + super(0L);
45 } 44 }
46 45
47 /** 46 /**
...@@ -60,29 +59,6 @@ public final class AlarmId { ...@@ -60,29 +59,6 @@ public final class AlarmId {
60 * @return backing integer index 59 * @return backing integer index
61 */ 60 */
62 public long fingerprint() { 61 public long fingerprint() {
63 - return id; 62 + return identifier;
64 - }
65 -
66 - @Override
67 - public int hashCode() {
68 - return Objects.hash(id);
69 - }
70 -
71 - @Override
72 - public boolean equals(Object obj) {
73 - if (this == obj) {
74 - return true;
75 - }
76 - if (obj instanceof AlarmId) {
77 - AlarmId other = (AlarmId) obj;
78 - return Objects.equals(this.id, other.id);
79 - }
80 - return false;
81 - }
82 -
83 - @Override
84 - public String toString() {
85 - return toStringHelper(this).add("id", id).toString();
86 } 63 }
87 -
88 } 64 }
......
...@@ -16,48 +16,36 @@ ...@@ -16,48 +16,36 @@
16 package org.onosproject.incubator.net.resource.label; 16 package org.onosproject.incubator.net.resource.label;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 +import org.onlab.util.Identifier;
19 import org.onosproject.net.resource.ResourceId; 20 import org.onosproject.net.resource.ResourceId;
20 21
21 -import java.util.Objects;
22 -
23 /** 22 /**
24 * Representation of a label. 23 * Representation of a label.
25 */ 24 */
26 @Beta 25 @Beta
27 -public final class LabelResourceId implements ResourceId { 26 +public final class LabelResourceId extends Identifier<Long> implements ResourceId {
28 - 27 +
29 - private long labelId; 28 + /**
30 - 29 + * Creates a new label identifier.
30 + *
31 + * @param labelResourceId backing identifier value
32 + * @return label identifier
33 + */
31 public static LabelResourceId labelResourceId(long labelResourceId) { 34 public static LabelResourceId labelResourceId(long labelResourceId) {
32 return new LabelResourceId(labelResourceId); 35 return new LabelResourceId(labelResourceId);
33 } 36 }
34 37
35 // Public construction is prohibited 38 // Public construction is prohibited
36 private LabelResourceId(long labelId) { 39 private LabelResourceId(long labelId) {
37 - this.labelId = labelId; 40 + super(labelId);
38 } 41 }
39 42
43 + /**
44 + * Returns label identifier.
45 + *
46 + * @return label identifier
47 + */
40 public long labelId() { 48 public long labelId() {
41 - return labelId; 49 + return identifier;
42 - }
43 -
44 - @Override
45 - public int hashCode() {
46 - return Objects.hashCode(labelId);
47 } 50 }
48 -
49 - @Override
50 - public boolean equals(Object obj) {
51 - if (obj instanceof LabelResourceId) {
52 - LabelResourceId that = (LabelResourceId) obj;
53 - return Objects.equals(this.labelId, that.labelId);
54 - }
55 - return false;
56 - }
57 -
58 - @Override
59 - public String toString() {
60 - return String.valueOf(this.labelId);
61 - }
62 -
63 } 51 }
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
16 16
17 package org.onosproject.incubator.net.tunnel; 17 package org.onosproject.incubator.net.tunnel;
18 18
19 +import org.onlab.util.Identifier;
20 +
19 /** 21 /**
20 * A wrapper class for a long used to identify domain level tunnels. 22 * A wrapper class for a long used to identify domain level tunnels.
21 */ 23 */
22 -public final class DomainTunnelId { 24 +public final class DomainTunnelId extends Identifier<Long> {
23 -
24 - private final long value;
25 25
26 /** 26 /**
27 * Creates a tunnel identifier from the specified tunnel. 27 * Creates a tunnel identifier from the specified tunnel.
...@@ -47,7 +47,7 @@ public final class DomainTunnelId { ...@@ -47,7 +47,7 @@ public final class DomainTunnelId {
47 * Constructor for serializer. 47 * Constructor for serializer.
48 */ 48 */
49 protected DomainTunnelId() { 49 protected DomainTunnelId() {
50 - this.value = 0; 50 + super(0L);
51 } 51 }
52 52
53 /** 53 /**
...@@ -56,37 +56,11 @@ public final class DomainTunnelId { ...@@ -56,37 +56,11 @@ public final class DomainTunnelId {
56 * @param value the underlying value of this domain ID 56 * @param value the underlying value of this domain ID
57 */ 57 */
58 public DomainTunnelId(long value) { 58 public DomainTunnelId(long value) {
59 - this.value = value; 59 + super(value);
60 - }
61 -
62 - /**
63 - * Returns the backing value of this domain ID.
64 - *
65 - * @return the long value
66 - */
67 - public long id() {
68 - return value;
69 - }
70 -
71 - @Override
72 - public int hashCode() {
73 - return Long.hashCode(value);
74 - }
75 -
76 - @Override
77 - public boolean equals(Object obj) {
78 - if (obj == this) {
79 - return true;
80 - }
81 - if (!(obj instanceof DomainTunnelId)) {
82 - return false;
83 - }
84 - DomainTunnelId that = (DomainTunnelId) obj;
85 - return this.value == that.value;
86 } 60 }
87 61
88 @Override 62 @Override
89 public String toString() { 63 public String toString() {
90 - return "0x" + Long.toHexString(value); 64 + return "0x" + Long.toHexString(identifier);
91 } 65 }
92 } 66 }
......
...@@ -17,14 +17,13 @@ ...@@ -17,14 +17,13 @@
17 package org.onosproject.incubator.net.tunnel; 17 package org.onosproject.incubator.net.tunnel;
18 18
19 import com.google.common.annotations.Beta; 19 import com.google.common.annotations.Beta;
20 +import org.onlab.util.Identifier;
20 21
21 /** 22 /**
22 * Representation of a Network Tunnel Id. 23 * Representation of a Network Tunnel Id.
23 */ 24 */
24 @Beta 25 @Beta
25 -public final class NetworkTunnelId { 26 +public final class NetworkTunnelId extends Identifier<Long> {
26 - private final long value;
27 -
28 /** 27 /**
29 * Creates an tunnel identifier from the specified tunnel. 28 * Creates an tunnel identifier from the specified tunnel.
30 * 29 *
...@@ -43,7 +42,7 @@ public final class NetworkTunnelId { ...@@ -43,7 +42,7 @@ public final class NetworkTunnelId {
43 * Constructor for serializer. 42 * Constructor for serializer.
44 */ 43 */
45 NetworkTunnelId() { 44 NetworkTunnelId() {
46 - this.value = 0; 45 + super(0L);
47 } 46 }
48 47
49 /** 48 /**
...@@ -52,38 +51,11 @@ public final class NetworkTunnelId { ...@@ -52,38 +51,11 @@ public final class NetworkTunnelId {
52 * @param value the underlying value of this ID 51 * @param value the underlying value of this ID
53 */ 52 */
54 public NetworkTunnelId(long value) { 53 public NetworkTunnelId(long value) {
55 - this.value = value; 54 + super(value);
56 - }
57 -
58 - /**
59 - * Returns the backing value.
60 - *
61 - * @return the value
62 - */
63 - public long id() {
64 - return value;
65 - }
66 -
67 - @Override
68 - public int hashCode() {
69 - return Long.hashCode(value);
70 - }
71 -
72 - @Override
73 - public boolean equals(Object obj) {
74 - if (obj == this) {
75 - return true;
76 - }
77 - if (!(obj instanceof NetworkTunnelId)) {
78 - return false;
79 - }
80 - NetworkTunnelId that = (NetworkTunnelId) obj;
81 - return this.value == that.value;
82 } 55 }
83 56
84 @Override 57 @Override
85 public String toString() { 58 public String toString() {
86 - return "0x" + Long.toHexString(value); 59 + return "0x" + Long.toHexString(identifier);
87 } 60 }
88 -
89 } 61 }
......
...@@ -16,66 +16,44 @@ ...@@ -16,66 +16,44 @@
16 16
17 package org.onosproject.incubator.net.tunnel; 17 package org.onosproject.incubator.net.tunnel;
18 18
19 -import java.util.Objects;
20 -
21 import com.google.common.annotations.Beta; 19 import com.google.common.annotations.Beta;
22 import com.google.common.primitives.UnsignedLongs; 20 import com.google.common.primitives.UnsignedLongs;
21 +import org.onlab.util.Identifier;
23 22
24 /** 23 /**
25 * Representation of a label Id, a logical port identifier. 24 * Representation of a label Id, a logical port identifier.
26 */ 25 */
27 @Beta 26 @Beta
28 -public final class OpticalLogicId { 27 +public final class OpticalLogicId extends Identifier<Long> {
29 - /** 28 +
30 - * Represents a logical Id. 29 + /**
31 - */ 30 + * Constructor, public creation is prohibited.
32 - private final long logicId; 31 + */
33 - 32 + private OpticalLogicId(long id) {
34 - /** 33 + super(id);
35 - * Constructor, public creation is prohibited. 34 + }
36 - */ 35 +
37 - private OpticalLogicId(long id) { 36 + /**
38 - this.logicId = id; 37 + * Returns the LabelId representing the specified long value.
39 - } 38 + *
40 - 39 + * @param id identifier as long value
41 - /** 40 + * @return LabelId
42 - * Returns the LabelId representing the specified long value. 41 + */
43 - * 42 + public static OpticalLogicId logicId(long id) {
44 - * @param id identifier as long value 43 + return new OpticalLogicId(id);
45 - * @return LabelId 44 + }
46 - */ 45 +
47 - public static OpticalLogicId logicId(long id) { 46 + /**
48 - return new OpticalLogicId(id); 47 + * Returns the LabelId representing the specified string value.
49 - } 48 + *
50 - 49 + * @param string identifier as string value
51 - public static OpticalLogicId logicId(String string) { 50 + * @return LabelId
52 - return new OpticalLogicId(UnsignedLongs.decode(string)); 51 + */
53 - } 52 + public static OpticalLogicId logicId(String string) {
54 - 53 + return new OpticalLogicId(UnsignedLongs.decode(string));
55 - public long toLong() { 54 + }
56 - return logicId; 55 +
57 - } 56 + public long toLong() {
58 - 57 + return identifier;
59 - @Override 58 + }
60 - public String toString() {
61 - return UnsignedLongs.toString(logicId);
62 - }
63 -
64 - @Override
65 - public int hashCode() {
66 - return Objects.hashCode(logicId);
67 - }
68 -
69 - @Override
70 - public boolean equals(Object obj) {
71 - if (this == obj) {
72 - return true;
73 - }
74 - if (obj instanceof OpticalLogicId) {
75 - final OpticalLogicId other = (OpticalLogicId) obj;
76 - return this.logicId == other.logicId;
77 - }
78 - return false;
79 - }
80 -
81 } 59 }
......
...@@ -17,14 +17,13 @@ ...@@ -17,14 +17,13 @@
17 package org.onosproject.incubator.net.tunnel; 17 package org.onosproject.incubator.net.tunnel;
18 18
19 import com.google.common.annotations.Beta; 19 import com.google.common.annotations.Beta;
20 +import org.onlab.util.Identifier;
20 21
21 /** 22 /**
22 * Representation of a Tunnel Id. 23 * Representation of a Tunnel Id.
23 */ 24 */
24 @Beta 25 @Beta
25 -public final class TunnelId { 26 +public final class TunnelId extends Identifier<Long> {
26 - private final long value;
27 -
28 /** 27 /**
29 * Creates an tunnel identifier from the specified tunnel. 28 * Creates an tunnel identifier from the specified tunnel.
30 * 29 *
...@@ -43,7 +42,7 @@ public final class TunnelId { ...@@ -43,7 +42,7 @@ public final class TunnelId {
43 * Constructor for serializer. 42 * Constructor for serializer.
44 */ 43 */
45 TunnelId() { 44 TunnelId() {
46 - this.value = 0; 45 + super(0L);
47 } 46 }
48 47
49 /** 48 /**
...@@ -52,38 +51,11 @@ public final class TunnelId { ...@@ -52,38 +51,11 @@ public final class TunnelId {
52 * @param value the underlying value of this ID 51 * @param value the underlying value of this ID
53 */ 52 */
54 TunnelId(long value) { 53 TunnelId(long value) {
55 - this.value = value; 54 + super(value);
56 - }
57 -
58 - /**
59 - * Returns the backing value.
60 - *
61 - * @return the value
62 - */
63 - public long id() {
64 - return value;
65 - }
66 -
67 - @Override
68 - public int hashCode() {
69 - return Long.hashCode(value);
70 - }
71 -
72 - @Override
73 - public boolean equals(Object obj) {
74 - if (obj == this) {
75 - return true;
76 - }
77 - if (!(obj instanceof TunnelId)) {
78 - return false;
79 - }
80 - TunnelId that = (TunnelId) obj;
81 - return this.value == that.value;
82 } 55 }
83 56
84 @Override 57 @Override
85 public String toString() { 58 public String toString() {
86 - return "0x" + Long.toHexString(value); 59 + return "0x" + Long.toHexString(identifier);
87 } 60 }
88 -
89 } 61 }
......
...@@ -16,14 +16,13 @@ ...@@ -16,14 +16,13 @@
16 package org.onosproject.incubator.net.virtual; 16 package org.onosproject.incubator.net.virtual;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 - 19 +import org.onlab.util.Identifier;
20 -import java.util.Objects;
21 20
22 /** 21 /**
23 * Representation of network identity. 22 * Representation of network identity.
24 */ 23 */
25 @Beta 24 @Beta
26 -public final class NetworkId { 25 +public final class NetworkId extends Identifier<Long> {
27 26
28 /** 27 /**
29 * Represents no network, or an unspecified network. 28 * Represents no network, or an unspecified network.
...@@ -35,18 +34,15 @@ public final class NetworkId { ...@@ -35,18 +34,15 @@ public final class NetworkId {
35 */ 34 */
36 public static final NetworkId PHYSICAL = networkId(0L); 35 public static final NetworkId PHYSICAL = networkId(0L);
37 36
38 -
39 - private final long id;
40 -
41 // Public construction is prohibited 37 // Public construction is prohibited
42 private NetworkId(long id) { 38 private NetworkId(long id) {
43 - this.id = id; 39 + super(id);
44 } 40 }
45 41
46 42
47 // Default constructor for serialization 43 // Default constructor for serialization
48 protected NetworkId() { 44 protected NetworkId() {
49 - this.id = -1; 45 + super(-1L);
50 } 46 }
51 47
52 /** 48 /**
...@@ -58,27 +54,4 @@ public final class NetworkId { ...@@ -58,27 +54,4 @@ public final class NetworkId {
58 public static NetworkId networkId(long id) { 54 public static NetworkId networkId(long id) {
59 return new NetworkId(id); 55 return new NetworkId(id);
60 } 56 }
61 -
62 - @Override
63 - public int hashCode() {
64 - return Objects.hash(id);
65 - }
66 -
67 - @Override
68 - public boolean equals(Object obj) {
69 - if (this == obj) {
70 - return true;
71 - }
72 - if (obj instanceof NetworkId) {
73 - final NetworkId that = (NetworkId) obj;
74 - return this.getClass() == that.getClass() && this.id == that.id;
75 - }
76 - return false;
77 - }
78 -
79 - @Override
80 - public String toString() {
81 - return Long.toString(id);
82 - }
83 -
84 } 57 }
......
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
16 package org.onosproject.incubator.net.virtual; 16 package org.onosproject.incubator.net.virtual;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 - 19 +import org.onlab.util.Identifier;
20 -import java.util.Objects;
21 20
22 import static com.google.common.base.Preconditions.checkArgument; 21 import static com.google.common.base.Preconditions.checkArgument;
23 22
...@@ -25,26 +24,22 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -25,26 +24,22 @@ import static com.google.common.base.Preconditions.checkArgument;
25 * Representation of network tenant. 24 * Representation of network tenant.
26 */ 25 */
27 @Beta 26 @Beta
28 -public final class TenantId { 27 +public final class TenantId extends Identifier<String> {
29 28
30 /** 29 /**
31 * Represents no tenant, or an unspecified tenant. 30 * Represents no tenant, or an unspecified tenant.
32 */ 31 */
33 public static final TenantId NONE = new TenantId(); 32 public static final TenantId NONE = new TenantId();
34 33
35 -
36 - private final String id;
37 -
38 // Public construction is prohibited 34 // Public construction is prohibited
39 private TenantId(String id) { 35 private TenantId(String id) {
36 + super(id);
40 checkArgument(id != null && id.length() > 0, "Tenant ID cannot be null or empty"); 37 checkArgument(id != null && id.length() > 0, "Tenant ID cannot be null or empty");
41 - this.id = id;
42 } 38 }
43 39
44 -
45 // Default constructor for serialization 40 // Default constructor for serialization
46 protected TenantId() { 41 protected TenantId() {
47 - this.id = ""; 42 + super("");
48 } 43 }
49 44
50 /** 45 /**
...@@ -56,28 +51,4 @@ public final class TenantId { ...@@ -56,28 +51,4 @@ public final class TenantId {
56 public static TenantId tenantId(String id) { 51 public static TenantId tenantId(String id) {
57 return new TenantId(id); 52 return new TenantId(id);
58 } 53 }
59 -
60 - @Override
61 - public int hashCode() {
62 - return id.hashCode();
63 - }
64 -
65 - @Override
66 - public boolean equals(Object obj) {
67 - if (this == obj) {
68 - return true;
69 - }
70 - if (obj instanceof TenantId) {
71 - final TenantId that = (TenantId) obj;
72 - return this.getClass() == that.getClass() &&
73 - Objects.equals(this.id, that.id);
74 - }
75 - return false;
76 - }
77 -
78 - @Override
79 - public String toString() {
80 - return id;
81 - }
82 -
83 } 54 }
......