Committed by
Thomas Vachuska
[ONOS-4014] Refactor *Id classes to extend from Identifier class
- Refactor all of *Id classes in protocols package - Refactor all of *Id classes in utils package Change-Id: Ie53f078174d0bd0cb5ab4ef6786f1025a7d70846
Showing
8 changed files
with
51 additions
and
232 deletions
| ... | @@ -17,9 +17,10 @@ | ... | @@ -17,9 +17,10 @@ |
| 17 | package org.onosproject.bgp.controller; | 17 | package org.onosproject.bgp.controller; |
| 18 | 18 | ||
| 19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
| 20 | +import org.onlab.util.Identifier; | ||
| 21 | + | ||
| 20 | import java.net.URI; | 22 | import java.net.URI; |
| 21 | import java.net.URISyntaxException; | 23 | import java.net.URISyntaxException; |
| 22 | -import java.util.Objects; | ||
| 23 | 24 | ||
| 24 | import static com.google.common.base.Preconditions.checkArgument; | 25 | import static com.google.common.base.Preconditions.checkArgument; |
| 25 | 26 | ||
| ... | @@ -27,11 +28,10 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -27,11 +28,10 @@ import static com.google.common.base.Preconditions.checkArgument; |
| 27 | * The class representing a network peer bgp ip. | 28 | * The class representing a network peer bgp ip. |
| 28 | * This class is immutable. | 29 | * This class is immutable. |
| 29 | */ | 30 | */ |
| 30 | -public final class BgpId { | 31 | +public final class BgpId extends Identifier<IpAddress> { |
| 31 | 32 | ||
| 32 | private static final String SCHEME = "bgp"; | 33 | private static final String SCHEME = "bgp"; |
| 33 | private static final long UNKNOWN = 0; | 34 | private static final long UNKNOWN = 0; |
| 34 | - private final IpAddress ipAddress; | ||
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | * Constructor to initialize ipAddress. | 37 | * Constructor to initialize ipAddress. |
| ... | @@ -39,7 +39,7 @@ public final class BgpId { | ... | @@ -39,7 +39,7 @@ public final class BgpId { |
| 39 | * @param ipAddress Ip address | 39 | * @param ipAddress Ip address |
| 40 | */ | 40 | */ |
| 41 | public BgpId(IpAddress ipAddress) { | 41 | public BgpId(IpAddress ipAddress) { |
| 42 | - this.ipAddress = ipAddress; | 42 | + super(ipAddress); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| ... | @@ -58,32 +58,7 @@ public final class BgpId { | ... | @@ -58,32 +58,7 @@ public final class BgpId { |
| 58 | * @return ipAddress | 58 | * @return ipAddress |
| 59 | */ | 59 | */ |
| 60 | public IpAddress ipAddress() { | 60 | public IpAddress ipAddress() { |
| 61 | - return ipAddress; | 61 | + return identifier; |
| 62 | - } | ||
| 63 | - | ||
| 64 | - /** | ||
| 65 | - * Convert the BGPId value to a ':' separated hexadecimal string. | ||
| 66 | - * | ||
| 67 | - * @return the BGPId value as a ':' separated hexadecimal string. | ||
| 68 | - */ | ||
| 69 | - @Override | ||
| 70 | - public String toString() { | ||
| 71 | - return ipAddress.toString(); | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - @Override | ||
| 75 | - public boolean equals(Object other) { | ||
| 76 | - if (!(other instanceof BgpId)) { | ||
| 77 | - return false; | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - BgpId otherBGPid = (BgpId) other; | ||
| 81 | - return Objects.equals(ipAddress, otherBGPid.ipAddress); | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - @Override | ||
| 85 | - public int hashCode() { | ||
| 86 | - return Objects.hash(ipAddress); | ||
| 87 | } | 62 | } |
| 88 | 63 | ||
| 89 | /** | 64 | /** | ... | ... |
| ... | @@ -15,25 +15,22 @@ | ... | @@ -15,25 +15,22 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.ovsdb.controller; | 16 | package org.onosproject.ovsdb.controller; |
| 17 | 17 | ||
| 18 | -import static com.google.common.base.MoreObjects.toStringHelper; | 18 | +import org.onlab.util.Identifier; |
| 19 | + | ||
| 19 | import static com.google.common.base.Preconditions.checkNotNull; | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | -import java.util.Objects; | ||
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * The class representing a datapathid. | 23 | * The class representing a datapathid. |
| 24 | * This class is immutable. | 24 | * This class is immutable. |
| 25 | */ | 25 | */ |
| 26 | -public final class OvsdbDatapathId { | 26 | +public final class OvsdbDatapathId extends Identifier<String> { |
| 27 | - private final String value; | ||
| 28 | - | ||
| 29 | /** | 27 | /** |
| 30 | * Constructor from a String. | 28 | * Constructor from a String. |
| 31 | * | 29 | * |
| 32 | * @param value the datapathid to use | 30 | * @param value the datapathid to use |
| 33 | */ | 31 | */ |
| 34 | public OvsdbDatapathId(String value) { | 32 | public OvsdbDatapathId(String value) { |
| 35 | - checkNotNull(value, "value is not null"); | 33 | + super(checkNotNull(value, "value is not null")); |
| 36 | - this.value = value; | ||
| 37 | } | 34 | } |
| 38 | 35 | ||
| 39 | /** | 36 | /** |
| ... | @@ -42,28 +39,6 @@ public final class OvsdbDatapathId { | ... | @@ -42,28 +39,6 @@ public final class OvsdbDatapathId { |
| 42 | * @return the value of datapathid | 39 | * @return the value of datapathid |
| 43 | */ | 40 | */ |
| 44 | public String value() { | 41 | public String value() { |
| 45 | - return value; | 42 | + return identifier; |
| 46 | - } | ||
| 47 | - | ||
| 48 | - @Override | ||
| 49 | - public int hashCode() { | ||
| 50 | - return value.hashCode(); | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - @Override | ||
| 54 | - public boolean equals(Object obj) { | ||
| 55 | - if (this == obj) { | ||
| 56 | - return true; | ||
| 57 | - } | ||
| 58 | - if (obj instanceof OvsdbDatapathId) { | ||
| 59 | - final OvsdbDatapathId otherDatapathId = (OvsdbDatapathId) obj; | ||
| 60 | - return Objects.equals(this.value, otherDatapathId.value); | ||
| 61 | - } | ||
| 62 | - return false; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - @Override | ||
| 66 | - public String toString() { | ||
| 67 | - return toStringHelper(this).add("value", value).toString(); | ||
| 68 | } | 43 | } |
| 69 | } | 44 | } | ... | ... |
| ... | @@ -15,25 +15,22 @@ | ... | @@ -15,25 +15,22 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.ovsdb.controller; | 16 | package org.onosproject.ovsdb.controller; |
| 17 | 17 | ||
| 18 | -import static com.google.common.base.MoreObjects.toStringHelper; | 18 | +import org.onlab.util.Identifier; |
| 19 | + | ||
| 19 | import static com.google.common.base.Preconditions.checkNotNull; | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | -import java.util.Objects; | ||
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * The class representing an ifaceid. | 23 | * The class representing an ifaceid. |
| 24 | * This class is immutable. | 24 | * This class is immutable. |
| 25 | */ | 25 | */ |
| 26 | -public class OvsdbIfaceId { | 26 | +public class OvsdbIfaceId extends Identifier<String> { |
| 27 | - private final String value; | ||
| 28 | - | ||
| 29 | /** | 27 | /** |
| 30 | * Constructor from a String. | 28 | * Constructor from a String. |
| 31 | * | 29 | * |
| 32 | * @param value the ifaceid to use | 30 | * @param value the ifaceid to use |
| 33 | */ | 31 | */ |
| 34 | public OvsdbIfaceId(String value) { | 32 | public OvsdbIfaceId(String value) { |
| 35 | - checkNotNull(value, "value is not null"); | 33 | + super(checkNotNull(value, "value is not null")); |
| 36 | - this.value = value; | ||
| 37 | } | 34 | } |
| 38 | 35 | ||
| 39 | /** | 36 | /** |
| ... | @@ -42,28 +39,6 @@ public class OvsdbIfaceId { | ... | @@ -42,28 +39,6 @@ public class OvsdbIfaceId { |
| 42 | * @return the value of ifaceid | 39 | * @return the value of ifaceid |
| 43 | */ | 40 | */ |
| 44 | public String value() { | 41 | public String value() { |
| 45 | - return value; | 42 | + return identifier; |
| 46 | - } | ||
| 47 | - | ||
| 48 | - @Override | ||
| 49 | - public int hashCode() { | ||
| 50 | - return value.hashCode(); | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - @Override | ||
| 54 | - public boolean equals(Object obj) { | ||
| 55 | - if (this == obj) { | ||
| 56 | - return true; | ||
| 57 | - } | ||
| 58 | - if (obj instanceof OvsdbIfaceId) { | ||
| 59 | - final OvsdbIfaceId otherIfaceId = (OvsdbIfaceId) obj; | ||
| 60 | - return Objects.equals(this.value, otherIfaceId.value); | ||
| 61 | - } | ||
| 62 | - return false; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - @Override | ||
| 66 | - public String toString() { | ||
| 67 | - return toStringHelper(this).add("value", value).toString(); | ||
| 68 | } | 43 | } |
| 69 | } | 44 | } | ... | ... |
| ... | @@ -15,19 +15,17 @@ | ... | @@ -15,19 +15,17 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.ovsdb.controller; | 16 | package org.onosproject.ovsdb.controller; |
| 17 | 17 | ||
| 18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | - | ||
| 20 | -import java.util.Objects; | ||
| 21 | - | ||
| 22 | import org.onlab.packet.IpAddress; | 18 | import org.onlab.packet.IpAddress; |
| 19 | +import org.onlab.util.Identifier; | ||
| 20 | + | ||
| 21 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 23 | 22 | ||
| 24 | /** | 23 | /** |
| 25 | * The class representing a nodeId of node which using ovsdb connection. | 24 | * The class representing a nodeId of node which using ovsdb connection. |
| 26 | * This class is immutable. | 25 | * This class is immutable. |
| 27 | */ | 26 | */ |
| 28 | -public final class OvsdbNodeId { | 27 | +public final class OvsdbNodeId extends Identifier<String> { |
| 29 | private static final String SCHEME = "ovsdb"; | 28 | private static final String SCHEME = "ovsdb"; |
| 30 | - private final String nodeId; | ||
| 31 | private final String ipAddress; | 29 | private final String ipAddress; |
| 32 | 30 | ||
| 33 | /** | 31 | /** |
| ... | @@ -37,30 +35,14 @@ public final class OvsdbNodeId { | ... | @@ -37,30 +35,14 @@ public final class OvsdbNodeId { |
| 37 | * @param port node port | 35 | * @param port node port |
| 38 | */ | 36 | */ |
| 39 | public OvsdbNodeId(IpAddress ipAddress, long port) { | 37 | public OvsdbNodeId(IpAddress ipAddress, long port) { |
| 40 | - checkNotNull(ipAddress, "ipAddress is not null"); | 38 | + // TODO: port is currently not in use, need to remove it later |
| 39 | + super(checkNotNull(ipAddress, "ipAddress is not null").toString()); | ||
| 41 | this.ipAddress = ipAddress.toString(); | 40 | this.ipAddress = ipAddress.toString(); |
| 42 | - this.nodeId = ipAddress.toString(); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - @Override | ||
| 46 | - public int hashCode() { | ||
| 47 | - return nodeId.hashCode(); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - @Override | ||
| 51 | - public boolean equals(Object other) { | ||
| 52 | - if (!(other instanceof OvsdbNodeId)) { | ||
| 53 | - return false; | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - OvsdbNodeId otherNodeId = (OvsdbNodeId) other; | ||
| 57 | - | ||
| 58 | - return Objects.equals(otherNodeId.nodeId, this.nodeId); | ||
| 59 | } | 41 | } |
| 60 | 42 | ||
| 61 | @Override | 43 | @Override |
| 62 | public String toString() { | 44 | public String toString() { |
| 63 | - return SCHEME + ":" + nodeId; | 45 | + return SCHEME + ":" + identifier; |
| 64 | } | 46 | } |
| 65 | 47 | ||
| 66 | /** | 48 | /** |
| ... | @@ -69,7 +51,7 @@ public final class OvsdbNodeId { | ... | @@ -69,7 +51,7 @@ public final class OvsdbNodeId { |
| 69 | * @return the value of the NodeId. | 51 | * @return the value of the NodeId. |
| 70 | */ | 52 | */ |
| 71 | public String nodeId() { | 53 | public String nodeId() { |
| 72 | - return SCHEME + ":" + nodeId; | 54 | + return SCHEME + ":" + identifier; |
| 73 | } | 55 | } |
| 74 | 56 | ||
| 75 | /** | 57 | /** | ... | ... |
| ... | @@ -15,28 +15,28 @@ | ... | @@ -15,28 +15,28 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.pcep.controller; | 16 | package org.onosproject.pcep.controller; |
| 17 | 17 | ||
| 18 | -import static com.google.common.base.Preconditions.checkArgument; | 18 | +import org.onlab.packet.IpAddress; |
| 19 | +import org.onlab.util.Identifier; | ||
| 20 | + | ||
| 19 | import java.net.URI; | 21 | import java.net.URI; |
| 20 | import java.net.URISyntaxException; | 22 | import java.net.URISyntaxException; |
| 21 | -import java.util.Objects; | ||
| 22 | 23 | ||
| 23 | -import org.onlab.packet.IpAddress; | 24 | +import static com.google.common.base.Preconditions.checkArgument; |
| 24 | 25 | ||
| 25 | /** | 26 | /** |
| 26 | * The class representing a network client pc ip. | 27 | * The class representing a network client pc ip. |
| 27 | * This class is immutable. | 28 | * This class is immutable. |
| 28 | */ | 29 | */ |
| 29 | -public final class PccId { | 30 | +public final class PccId extends Identifier<IpAddress> { |
| 30 | 31 | ||
| 31 | private static final String SCHEME = "pcep"; | 32 | private static final String SCHEME = "pcep"; |
| 32 | private static final long UNKNOWN = 0; | 33 | private static final long UNKNOWN = 0; |
| 33 | - private final IpAddress ipAddress; | ||
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * Private constructor. | 36 | * Private constructor. |
| 37 | */ | 37 | */ |
| 38 | private PccId(IpAddress ipAddress) { | 38 | private PccId(IpAddress ipAddress) { |
| 39 | - this.ipAddress = ipAddress; | 39 | + super(ipAddress); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| ... | @@ -55,32 +55,7 @@ public final class PccId { | ... | @@ -55,32 +55,7 @@ public final class PccId { |
| 55 | * @return ipAddress | 55 | * @return ipAddress |
| 56 | */ | 56 | */ |
| 57 | public IpAddress ipAddress() { | 57 | public IpAddress ipAddress() { |
| 58 | - return ipAddress; | 58 | + return identifier; |
| 59 | - } | ||
| 60 | - | ||
| 61 | - /** | ||
| 62 | - * Convert the PccId value to a ':' separated hexadecimal string. | ||
| 63 | - * | ||
| 64 | - * @return the PccId value as a ':' separated hexadecimal string. | ||
| 65 | - */ | ||
| 66 | - @Override | ||
| 67 | - public String toString() { | ||
| 68 | - return ipAddress.toString(); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - @Override | ||
| 72 | - public boolean equals(Object other) { | ||
| 73 | - if (!(other instanceof PccId)) { | ||
| 74 | - return false; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - PccId otherPccid = (PccId) other; | ||
| 78 | - return Objects.equals(ipAddress, otherPccid.ipAddress); | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - @Override | ||
| 82 | - public int hashCode() { | ||
| 83 | - return Objects.hash(ipAddress); | ||
| 84 | } | 59 | } |
| 85 | 60 | ||
| 86 | /** | 61 | /** | ... | ... |
| ... | @@ -16,29 +16,24 @@ | ... | @@ -16,29 +16,24 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.pcepio.types; | 17 | package org.onosproject.pcepio.types; |
| 18 | 18 | ||
| 19 | -import java.util.Objects; | ||
| 20 | - | ||
| 21 | import org.jboss.netty.buffer.ChannelBuffer; | 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | +import org.onlab.util.Identifier; | ||
| 22 | import org.onosproject.pcepio.protocol.PcepNai; | 21 | import org.onosproject.pcepio.protocol.PcepNai; |
| 23 | 22 | ||
| 24 | -import com.google.common.base.MoreObjects; | ||
| 25 | - | ||
| 26 | /** | 23 | /** |
| 27 | * Provides Pcep Nai Ipv4 Node Id. | 24 | * Provides Pcep Nai Ipv4 Node Id. |
| 28 | */ | 25 | */ |
| 29 | -public class PcepNaiIpv4NodeId implements PcepNai { | 26 | +public class PcepNaiIpv4NodeId extends Identifier<Integer> implements PcepNai { |
| 30 | 27 | ||
| 31 | public static final byte ST_TYPE = 0x01; | 28 | public static final byte ST_TYPE = 0x01; |
| 32 | 29 | ||
| 33 | - private final int ipv4NodeId; | ||
| 34 | - | ||
| 35 | /** | 30 | /** |
| 36 | * Constructor to initialize ipv4NodeId. | 31 | * Constructor to initialize ipv4NodeId. |
| 37 | * | 32 | * |
| 38 | * @param value ipv4 node id | 33 | * @param value ipv4 node id |
| 39 | */ | 34 | */ |
| 40 | public PcepNaiIpv4NodeId(int value) { | 35 | public PcepNaiIpv4NodeId(int value) { |
| 41 | - this.ipv4NodeId = value; | 36 | + super(value); |
| 42 | } | 37 | } |
| 43 | 38 | ||
| 44 | /** | 39 | /** |
| ... | @@ -59,7 +54,7 @@ public class PcepNaiIpv4NodeId implements PcepNai { | ... | @@ -59,7 +54,7 @@ public class PcepNaiIpv4NodeId implements PcepNai { |
| 59 | @Override | 54 | @Override |
| 60 | public int write(ChannelBuffer bb) { | 55 | public int write(ChannelBuffer bb) { |
| 61 | int iLenStartIndex = bb.writerIndex(); | 56 | int iLenStartIndex = bb.writerIndex(); |
| 62 | - bb.writeInt(ipv4NodeId); | 57 | + bb.writeInt(identifier); |
| 63 | return bb.writerIndex() - iLenStartIndex; | 58 | return bb.writerIndex() - iLenStartIndex; |
| 64 | } | 59 | } |
| 65 | 60 | ||
| ... | @@ -72,28 +67,4 @@ public class PcepNaiIpv4NodeId implements PcepNai { | ... | @@ -72,28 +67,4 @@ public class PcepNaiIpv4NodeId implements PcepNai { |
| 72 | public static PcepNaiIpv4NodeId read(ChannelBuffer bb) { | 67 | public static PcepNaiIpv4NodeId read(ChannelBuffer bb) { |
| 73 | return new PcepNaiIpv4NodeId(bb.readInt()); | 68 | return new PcepNaiIpv4NodeId(bb.readInt()); |
| 74 | } | 69 | } |
| 75 | - | ||
| 76 | - @Override | ||
| 77 | - public int hashCode() { | ||
| 78 | - return Objects.hash(ipv4NodeId); | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - @Override | ||
| 82 | - public boolean equals(Object obj) { | ||
| 83 | - if (this == obj) { | ||
| 84 | - return true; | ||
| 85 | - } | ||
| 86 | - if (obj instanceof PcepNaiIpv4NodeId) { | ||
| 87 | - PcepNaiIpv4NodeId other = (PcepNaiIpv4NodeId) obj; | ||
| 88 | - return Objects.equals(this.ipv4NodeId, other.ipv4NodeId); | ||
| 89 | - } | ||
| 90 | - return false; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - @Override | ||
| 94 | - public String toString() { | ||
| 95 | - return MoreObjects.toStringHelper(getClass()) | ||
| 96 | - .add("IPv4NodeId", ipv4NodeId) | ||
| 97 | - .toString(); | ||
| 98 | - } | ||
| 99 | } | 70 | } | ... | ... |
| ... | @@ -15,20 +15,21 @@ | ... | @@ -15,20 +15,21 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onlab.packet; | 16 | package org.onlab.packet; |
| 17 | 17 | ||
| 18 | +import org.onlab.util.Identifier; | ||
| 19 | + | ||
| 18 | /** | 20 | /** |
| 19 | * The class representing a network device chassisId. | 21 | * The class representing a network device chassisId. |
| 20 | * This class is immutable. | 22 | * This class is immutable. |
| 21 | */ | 23 | */ |
| 22 | -public final class ChassisId { | 24 | +public final class ChassisId extends Identifier<Long> { |
| 23 | 25 | ||
| 24 | private static final long UNKNOWN = 0; | 26 | private static final long UNKNOWN = 0; |
| 25 | - private final long value; | ||
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | * Default constructor. | 29 | * Default constructor. |
| 29 | */ | 30 | */ |
| 30 | public ChassisId() { | 31 | public ChassisId() { |
| 31 | - this.value = ChassisId.UNKNOWN; | 32 | + super(ChassisId.UNKNOWN); |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | /** | 35 | /** |
| ... | @@ -37,7 +38,7 @@ public final class ChassisId { | ... | @@ -37,7 +38,7 @@ public final class ChassisId { |
| 37 | * @param value the value to use. | 38 | * @param value the value to use. |
| 38 | */ | 39 | */ |
| 39 | public ChassisId(long value) { | 40 | public ChassisId(long value) { |
| 40 | - this.value = value; | 41 | + super(value); |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | /** | 44 | /** |
| ... | @@ -46,7 +47,7 @@ public final class ChassisId { | ... | @@ -46,7 +47,7 @@ public final class ChassisId { |
| 46 | * @param value the value to use. | 47 | * @param value the value to use. |
| 47 | */ | 48 | */ |
| 48 | public ChassisId(String value) { | 49 | public ChassisId(String value) { |
| 49 | - this.value = Long.parseLong(value, 16); | 50 | + super(Long.parseLong(value, 16)); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | /** | 53 | /** |
| ... | @@ -55,7 +56,7 @@ public final class ChassisId { | ... | @@ -55,7 +56,7 @@ public final class ChassisId { |
| 55 | * @return the value of the chassis id. | 56 | * @return the value of the chassis id. |
| 56 | */ | 57 | */ |
| 57 | public long value() { | 58 | public long value() { |
| 58 | - return value; | 59 | + return identifier; |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | /** | 62 | /** |
| ... | @@ -65,22 +66,11 @@ public final class ChassisId { | ... | @@ -65,22 +66,11 @@ public final class ChassisId { |
| 65 | */ | 66 | */ |
| 66 | @Override | 67 | @Override |
| 67 | public String toString() { | 68 | public String toString() { |
| 68 | - return Long.toHexString(this.value); | 69 | + return Long.toHexString(identifier); |
| 69 | - } | ||
| 70 | - | ||
| 71 | - @Override | ||
| 72 | - public boolean equals(Object other) { | ||
| 73 | - if (!(other instanceof ChassisId)) { | ||
| 74 | - return false; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - ChassisId otherChassisId = (ChassisId) other; | ||
| 78 | - | ||
| 79 | - return value == otherChassisId.value; | ||
| 80 | } | 70 | } |
| 81 | 71 | ||
| 82 | @Override | 72 | @Override |
| 83 | public int hashCode() { | 73 | public int hashCode() { |
| 84 | - return Long.hashCode(value); | 74 | + return Long.hashCode(identifier); |
| 85 | } | 75 | } |
| 86 | } | 76 | } | ... | ... |
| ... | @@ -15,13 +15,12 @@ | ... | @@ -15,13 +15,12 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onlab.packet; | 16 | package org.onlab.packet; |
| 17 | 17 | ||
| 18 | +import org.onlab.util.Identifier; | ||
| 19 | + | ||
| 18 | /** | 20 | /** |
| 19 | * Representation of a VLAN ID. | 21 | * Representation of a VLAN ID. |
| 20 | */ | 22 | */ |
| 21 | -public class VlanId { | 23 | +public class VlanId extends Identifier<Short> { |
| 22 | - | ||
| 23 | - private final short value; | ||
| 24 | - | ||
| 25 | // Based on convention used elsewhere? Check and change if needed | 24 | // Based on convention used elsewhere? Check and change if needed |
| 26 | public static final short UNTAGGED = (short) 0xffff; | 25 | public static final short UNTAGGED = (short) 0xffff; |
| 27 | 26 | ||
| ... | @@ -37,11 +36,11 @@ public class VlanId { | ... | @@ -37,11 +36,11 @@ public class VlanId { |
| 37 | public static final short MAX_VLAN = 4095; | 36 | public static final short MAX_VLAN = 4095; |
| 38 | 37 | ||
| 39 | protected VlanId() { | 38 | protected VlanId() { |
| 40 | - this.value = UNTAGGED; | 39 | + super(UNTAGGED); |
| 41 | } | 40 | } |
| 42 | 41 | ||
| 43 | protected VlanId(short value) { | 42 | protected VlanId(short value) { |
| 44 | - this.value = value; | 43 | + super(value); |
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | public static VlanId vlanId() { | 46 | public static VlanId vlanId() { |
| ... | @@ -65,38 +64,15 @@ public class VlanId { | ... | @@ -65,38 +64,15 @@ public class VlanId { |
| 65 | } | 64 | } |
| 66 | 65 | ||
| 67 | public short toShort() { | 66 | public short toShort() { |
| 68 | - return this.value; | 67 | + return this.identifier; |
| 69 | - } | ||
| 70 | - | ||
| 71 | - @Override | ||
| 72 | - public boolean equals(Object obj) { | ||
| 73 | - if (this == obj) { | ||
| 74 | - return true; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - if (obj instanceof VlanId) { | ||
| 78 | - | ||
| 79 | - VlanId other = (VlanId) obj; | ||
| 80 | - | ||
| 81 | - if (this.value == other.value) { | ||
| 82 | - return true; | ||
| 83 | - } | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | - return false; | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - @Override | ||
| 90 | - public int hashCode() { | ||
| 91 | - return this.value; | ||
| 92 | } | 68 | } |
| 93 | 69 | ||
| 94 | @Override | 70 | @Override |
| 95 | public String toString() { | 71 | public String toString() { |
| 96 | - if (this.value == ANY_VALUE) { | 72 | + if (this.identifier == ANY_VALUE) { |
| 97 | return "Any"; | 73 | return "Any"; |
| 98 | } | 74 | } |
| 99 | - return String.valueOf(this.value); | 75 | + return String.valueOf(this.identifier); |
| 100 | } | 76 | } |
| 101 | } | 77 | } |
| 102 | 78 | ... | ... |
-
Please register or login to post a comment