Jian Li
Committed by Gerrit Code Review

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

- Refactor all of *Id classes in apps package

Change-Id: I31fafbf7f15aee3a1b3b37b7c281b3f99eae0883
......@@ -19,13 +19,13 @@
*/
package org.onosproject.acl;
import org.onlab.util.Identifier;
/**
* ACL rule identifier suitable as an external key.
* <p>This class is immutable.</p>
*/
public final class RuleId {
private final long value;
public final class RuleId extends Identifier<Long> {
/**
* Creates an ACL rule identifier from the specified long value.
*
......@@ -40,7 +40,7 @@ public final class RuleId {
* Constructor for serializer.
*/
RuleId() {
this.value = 0;
super(0L);
}
/**
......@@ -49,7 +49,7 @@ public final class RuleId {
* @param value the underlying value of this ID
*/
RuleId(long value) {
this.value = value;
super(value);
}
/**
......@@ -58,28 +58,11 @@ public final class RuleId {
* @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 RuleId)) {
return false;
}
RuleId that = (RuleId) obj;
return this.value == that.value;
return identifier;
}
@Override
public String toString() {
return "0x" + Long.toHexString(value);
return "0x" + Long.toHexString(identifier);
}
}
......
......@@ -15,26 +15,21 @@
*/
package org.onosproject.cordvtn;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of service identifier.
*/
public final class CordServiceId {
private final String id;
public final class CordServiceId extends Identifier<String> {
/**
* Default constructor.
*
* @param id service identifier
*/
private CordServiceId(String id) {
this.id = id;
super(id);
}
/**
......@@ -47,37 +42,4 @@ public final class CordServiceId {
checkNotNull(id);
return new CordServiceId(id);
}
/**
* Returns service identifier.
*
* @return service id
*/
public String id() {
return id;
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof CordServiceId)) {
return false;
}
final CordServiceId other = (CordServiceId) obj;
return Objects.equals(this.id, other.id);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.toString();
}
}
......
......@@ -15,23 +15,19 @@
*/
package org.onosproject.iptopology.api;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
import org.onlab.util.Identifier;
/**
* Area identifier class (32 Bit Area-ID).
*/
public class AreaId {
private final int areaId;
public class AreaId extends Identifier<Integer> {
/**
* Constructor to set area identifier.
*
* @param areaId area id
*/
public AreaId(int areaId) {
this.areaId = areaId;
super(areaId);
}
/**
......@@ -40,31 +36,6 @@ public class AreaId {
* @return area identifier
*/
public int areaId() {
return areaId;
}
@Override
public int hashCode() {
return Objects.hash(areaId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof AreaId) {
AreaId other = (AreaId) obj;
return Objects.equals(areaId, other.areaId);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this)
.add("areaId", areaId)
.toString();
return identifier;
}
}
\ No newline at end of file
......
......@@ -16,23 +16,19 @@
package org.onosproject.iptopology.api;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
import org.onlab.util.Identifier;
/**
* Domain Identifier(32 Bit).
*/
public class DomainId {
private final int domainIdentifier;
public class DomainId extends Identifier<Integer> {
/**
* Constructor to initialize domain identifier.
*
* @param domainIdentifier domain identifier
*/
public DomainId(int domainIdentifier) {
this.domainIdentifier = domainIdentifier;
super(domainIdentifier);
}
/**
......@@ -41,31 +37,6 @@ public class DomainId {
* @return domain identifier
*/
public int domainIdentifier() {
return domainIdentifier;
}
@Override
public int hashCode() {
return Objects.hash(domainIdentifier);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DomainId) {
DomainId other = (DomainId) obj;
return Objects.equals(domainIdentifier, other.domainIdentifier);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this)
.add("domainIdentifier", domainIdentifier)
.toString();
return identifier;
}
}
\ No newline at end of file
......
......@@ -15,23 +15,19 @@
*/
package org.onosproject.iptopology.api;
import java.util.Objects;
import com.google.common.base.MoreObjects;
import org.onlab.util.Identifier;
/**
* Represents Multi-Topology IDs for a network link, node or prefix.
*/
public class TopologyId {
private final short topologyId;
public class TopologyId extends Identifier<Short> {
/**
* Constructor to initialize its parameter.
*
* @param topologyId topology id for node/link/prefix
*/
public TopologyId(short topologyId) {
this.topologyId = topologyId;
super(topologyId);
}
/**
......@@ -40,31 +36,6 @@ public class TopologyId {
* @return topology ID
*/
public short topologyId() {
return topologyId;
}
@Override
public int hashCode() {
return Objects.hash(topologyId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof TopologyId) {
TopologyId other = (TopologyId) obj;
return Objects.equals(topologyId, other.topologyId);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("topologyId", topologyId)
.toString();
return identifier;
}
}
\ No newline at end of file
......
......@@ -15,17 +15,14 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Objects;
import org.onlab.util.Identifier;
public final class BindingHostId {
private final String bindingHostId;
import static com.google.common.base.Preconditions.checkNotNull;
public final class BindingHostId extends Identifier<String> {
// Public construction is prohibited
private BindingHostId(String bindingHostId) {
checkNotNull(bindingHostId, "BindingHosttId cannot be null");
this.bindingHostId = bindingHostId;
super(checkNotNull(bindingHostId, "BindingHosttId cannot be null"));
}
/**
......@@ -44,29 +41,6 @@ public final class BindingHostId {
* @return the bindingHostId identifier
*/
public String bindingHostId() {
return bindingHostId;
}
@Override
public int hashCode() {
return bindingHostId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof BindingHostId) {
final BindingHostId that = (BindingHostId) obj;
return this.getClass() == that.getClass()
&& Objects.equals(this.bindingHostId, that.bindingHostId);
}
return false;
}
@Override
public String toString() {
return bindingHostId;
return identifier;
}
}
......
......@@ -15,21 +15,19 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.Identifier;
import java.util.Objects;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Immutable representation of a floating IP identifier.
*/
public final class FloatingIpId {
private final UUID floatingIpId;
public final class FloatingIpId extends Identifier<UUID> {
// Public construction is prohibited
private FloatingIpId(UUID floatingIpId) {
this.floatingIpId = checkNotNull(floatingIpId, "floatingIpId cannot be null");
super(checkNotNull(floatingIpId, "floatingIpId cannot be null"));
}
/**
......@@ -58,28 +56,6 @@ public final class FloatingIpId {
* @return the floating IP identifier
*/
public UUID floatingIpId() {
return floatingIpId;
}
@Override
public int hashCode() {
return floatingIpId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof FloatingIpId) {
final FloatingIpId that = (FloatingIpId) obj;
return Objects.equals(this.floatingIpId, that.floatingIpId);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("floatingIpId", floatingIpId).toString();
return identifier;
}
}
......
......@@ -15,28 +15,23 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.MoreObjects;
import org.onlab.util.Identifier;
import java.util.UUID;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Flow classification identifier.
*/
public final class FlowClassifierId {
private final UUID flowClassifierId;
public final class FlowClassifierId extends Identifier<UUID> {
/**
* Constructor to create flow classifier id.
*
* @param flowClassifierId flow classifier id.
*/
private FlowClassifierId(final UUID flowClassifierId) {
checkNotNull(flowClassifierId, "Flow classifier id can not be null");
this.flowClassifierId = flowClassifierId;
super(checkNotNull(flowClassifierId, "Flow classifier id can not be null"));
}
/**
......@@ -65,30 +60,6 @@ public final class FlowClassifierId {
* @return flow classifier id.
*/
public UUID value() {
return flowClassifierId;
}
@Override
public int hashCode() {
return Objects.hashCode(this.flowClassifierId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof FlowClassifierId) {
final FlowClassifierId other = (FlowClassifierId) obj;
return Objects.equals(this.flowClassifierId, other.flowClassifierId);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("FlowClassifierId", flowClassifierId)
.toString();
return identifier;
}
}
......
......@@ -15,19 +15,16 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.Objects;
import org.onlab.util.Identifier;
import com.google.common.base.MoreObjects;
import static com.google.common.base.Preconditions.checkArgument;
/*
* Representation of 5 bit load balance identifier for a service function
*/
public final class LoadBalanceId {
public final class LoadBalanceId extends Identifier<Byte> {
private static final byte MAX_ID = 0x1F;
private final byte loadBalanceId;
/**
* Default constructor.
......@@ -35,8 +32,8 @@ public final class LoadBalanceId {
* @param loadBalanceId service function chain path's load balance identifier
*/
private LoadBalanceId(byte loadBalanceId) {
super(loadBalanceId);
checkArgument(loadBalanceId <= MAX_ID, "Load balance id should not be more than 5 bit identifier");
this.loadBalanceId = (loadBalanceId);
}
/**
......@@ -56,31 +53,6 @@ public final class LoadBalanceId {
* @return loadBalanceId
*/
public byte loadBalanceId() {
return loadBalanceId;
}
@Override
public int hashCode() {
return Objects.hash(loadBalanceId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LoadBalanceId)) {
return false;
}
final LoadBalanceId other = (LoadBalanceId) obj;
return Objects.equals(this.loadBalanceId, other.loadBalanceId);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("loadBalanceId", loadBalanceId)
.toString();
return identifier;
}
}
......
......@@ -15,27 +15,23 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.Identifier;
import java.util.UUID;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of a Port Chain ID.
*/
public final class PortChainId {
private final UUID portChainId;
public final class PortChainId extends Identifier<UUID> {
/**
* Private constructor for port chain id.
*
* @param id UUID id of port chain
*/
private PortChainId(UUID id) {
checkNotNull(id, "Port chain id can not be null");
this.portChainId = id;
super(checkNotNull(id, "Port chain id can not be null"));
}
/**
......@@ -64,28 +60,6 @@ public final class PortChainId {
* @return port chain id
*/
public UUID value() {
return portChainId;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PortChainId) {
final PortChainId other = (PortChainId) obj;
return Objects.equals(this.portChainId, other.portChainId);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(this.portChainId);
}
@Override
public String toString() {
return toStringHelper(this).add("portChainId", portChainId).toString();
return identifier;
}
}
......
......@@ -15,27 +15,23 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.Identifier;
import java.util.UUID;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of a Port Pair Group ID.
*/
public final class PortPairGroupId {
private final UUID portPairGroupId;
public final class PortPairGroupId extends Identifier<UUID> {
/**
* Private constructor for port pair group id.
*
* @param id UUID id of port pair group
*/
private PortPairGroupId(UUID id) {
checkNotNull(id, "Port pair group id can not be null");
this.portPairGroupId = id;
super(checkNotNull(id, "Port pair group id can not be null"));
}
/**
......@@ -64,29 +60,6 @@ public final class PortPairGroupId {
* @return port pair group id
*/
public UUID value() {
return portPairGroupId;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PortPairGroupId) {
final PortPairGroupId other = (PortPairGroupId) obj;
return Objects.equals(this.portPairGroupId, other.portPairGroupId);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(this.portPairGroupId);
}
@Override
public String toString() {
return toStringHelper(this).add("portPairGroupId", portPairGroupId)
.toString();
return identifier;
}
}
......
......@@ -15,27 +15,23 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.Identifier;
import java.util.UUID;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Representation of a Port Pair ID.
*/
public final class PortPairId {
private final UUID portPairId;
public final class PortPairId extends Identifier<UUID> {
/**
* Private constructor for port pair id.
*
* @param id UUID id of port pair
*/
private PortPairId(UUID id) {
checkNotNull(id, "Port chain id can not be null");
this.portPairId = id;
super(checkNotNull(id, "Port chain id can not be null"));
}
/**
......@@ -64,30 +60,6 @@ public final class PortPairId {
* @return port pair id
*/
public UUID value() {
return portPairId;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PortPairId) {
final PortPairId other = (PortPairId) obj;
return Objects.equals(this.portPairId, other.portPairId);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(this.portPairId);
}
@Override
public String toString() {
return toStringHelper(this)
.add("portPairId", portPairId)
.toString();
return identifier;
}
}
......
......@@ -15,22 +15,17 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.Identifier;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Immutable representation of a router identifier.
*/
public final class RouterId {
private final String routerId;
public final class RouterId extends Identifier<String> {
// Public construction is prohibited
private RouterId(String routerId) {
checkNotNull(routerId, "routerId cannot be null");
this.routerId = routerId;
super(checkNotNull(routerId, "routerId cannot be null"));
}
/**
......@@ -49,29 +44,7 @@ public final class RouterId {
* @return the router identifier
*/
public String routerId() {
return routerId;
}
@Override
public int hashCode() {
return routerId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof RouterId) {
final RouterId that = (RouterId) obj;
return Objects.equals(this.routerId, that.routerId);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("routerId", routerId).toString();
return identifier;
}
}
......
......@@ -15,21 +15,17 @@
*/
package org.onosproject.vtnrsc;
import java.util.Objects;
import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Immutable representation of a Segmentation identifier.
*/
public final class SegmentationId {
private final String segmentationId;
public final class SegmentationId extends Identifier<String> {
// Public construction is prohibited
private SegmentationId(String segmentationId) {
checkNotNull(segmentationId, "SegmentationId cannot be null");
this.segmentationId = segmentationId;
super(checkNotNull(segmentationId, "SegmentationId cannot be null"));
}
/**
......@@ -48,30 +44,6 @@ public final class SegmentationId {
* @return segmentationId
*/
public String segmentationId() {
return segmentationId;
return identifier;
}
@Override
public int hashCode() {
return segmentationId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof SegmentationId) {
final SegmentationId that = (SegmentationId) obj;
return this.getClass() == that.getClass()
&& Objects.equals(this.segmentationId, that.segmentationId);
}
return false;
}
@Override
public String toString() {
return segmentationId;
}
}
......
......@@ -15,21 +15,17 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.Identifier;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Immutable representation of a subnet identifier.
*/
public final class SubnetId {
private final String subnetId;
public final class SubnetId extends Identifier<String> {
// Public construction is prohibited
private SubnetId(String subnetId) {
checkNotNull(subnetId, "SubnetId cannot be null");
this.subnetId = subnetId;
super(checkNotNull(subnetId, "SubnetId cannot be null"));
}
/**
......@@ -48,29 +44,6 @@ public final class SubnetId {
* @return the subnet identifier
*/
public String subnetId() {
return subnetId;
}
@Override
public int hashCode() {
return subnetId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof SubnetId) {
final SubnetId that = (SubnetId) obj;
return this.getClass() == that.getClass()
&& Objects.equals(this.subnetId, that.subnetId);
}
return false;
}
@Override
public String toString() {
return subnetId;
return identifier;
}
}
......
......@@ -15,20 +15,17 @@
*/
package org.onosproject.vtnrsc;
import java.util.Objects;
import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Immutable representation of a tenant identifier.
*/
public final class TenantId {
private final String tenantId;
public final class TenantId extends Identifier<String> {
// Public construction is prohibited
private TenantId(String tenantId) {
this.tenantId = tenantId;
super(tenantId);
}
/**
......@@ -38,7 +35,7 @@ public final class TenantId {
* @return TenantId
*/
public static TenantId tenantId(String tenantid) {
checkNotNull(tenantid, "Tenantid can not be null");
checkNotNull(tenantid, "Tenant id can not be null");
return new TenantId(tenantid);
}
......@@ -48,30 +45,6 @@ public final class TenantId {
* @return the tenant identifier
*/
public String tenantId() {
return tenantId;
return identifier;
}
@Override
public int hashCode() {
return tenantId.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.tenantId, that.tenantId);
}
return false;
}
@Override
public String toString() {
return tenantId;
}
}
......
......@@ -15,19 +15,17 @@
*/
package org.onosproject.vtnrsc;
import java.util.Objects;
import org.onlab.util.Identifier;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Immutable representation of a tenantNetwork identity.
*/
public final class TenantNetworkId {
private final String networkId;
public final class TenantNetworkId extends Identifier<String> {
// Public construction is prohibited
private TenantNetworkId(String networkId) {
this.networkId = networkId;
super(networkId);
}
/**
......@@ -47,30 +45,6 @@ public final class TenantNetworkId {
* @return the tenantNetwork identifier
*/
public String networkId() {
return networkId;
}
@Override
public int hashCode() {
return networkId.hashCode();
return identifier;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof TenantNetworkId) {
final TenantNetworkId that = (TenantNetworkId) obj;
return this.getClass() == that.getClass()
&& Objects.equals(this.networkId, that.networkId);
}
return false;
}
@Override
public String toString() {
return networkId;
}
}
......
......@@ -15,23 +15,21 @@
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.util.Identifier;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Immutable representation of a virtual port identifier.
*/
public final class VirtualPortId {
private final String portId;
public final class VirtualPortId extends Identifier<String> {
// Public construction is prohibited
private VirtualPortId(String virtualPortId) {
checkNotNull(virtualPortId, "VirtualPortId cannot be null");
this.portId = virtualPortId;
super(checkNotNull(virtualPortId, "VirtualPortId cannot be null"));
}
public String portId() {
return portId;
return identifier;
}
/**
......@@ -43,28 +41,4 @@ public final class VirtualPortId {
public static VirtualPortId portId(String portId) {
return new VirtualPortId(portId);
}
@Override
public int hashCode() {
return portId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof VirtualPortId) {
final VirtualPortId that = (VirtualPortId) obj;
return this.getClass() == that.getClass()
&& Objects.equals(this.portId, that.portId);
}
return false;
}
@Override
public String toString() {
return portId;
}
}
......