Committed by
Ray Milkey
[ONOS-3114] PortChainId
Change-Id: I3281996786b4a5acc43e5a97dc31051e443fbfca
Showing
3 changed files
with
13 additions
and
17 deletions
... | @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
19 | import static com.google.common.base.Preconditions.checkNotNull; | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
20 | 20 | ||
21 | import java.util.UUID; | 21 | import java.util.UUID; |
22 | - | 22 | +import java.util.Objects; |
23 | -import com.google.common.base.Objects; | ||
24 | 23 | ||
25 | /** | 24 | /** |
26 | * Representation of a Port Chain ID. | 25 | * Representation of a Port Chain ID. |
... | @@ -40,22 +39,22 @@ public final class PortChainId { | ... | @@ -40,22 +39,22 @@ public final class PortChainId { |
40 | } | 39 | } |
41 | 40 | ||
42 | /** | 41 | /** |
43 | - * Constructor to create port chain id from UUID. | 42 | + * Returns newly created port chain id object. |
44 | * | 43 | * |
45 | * @param id UUID of port chain | 44 | * @param id UUID of port chain |
46 | * @return object of port chain id | 45 | * @return object of port chain id |
47 | */ | 46 | */ |
48 | - public static PortChainId portChainId(UUID id) { | 47 | + public static PortChainId of(UUID id) { |
49 | return new PortChainId(id); | 48 | return new PortChainId(id); |
50 | } | 49 | } |
51 | 50 | ||
52 | /** | 51 | /** |
53 | - * Constructor to create port chain id from string. | 52 | + * Returns newly created port chain id object. |
54 | * | 53 | * |
55 | * @param id port chain id in string | 54 | * @param id port chain id in string |
56 | * @return object of port chain id | 55 | * @return object of port chain id |
57 | */ | 56 | */ |
58 | - public static PortChainId portChainId(String id) { | 57 | + public static PortChainId of(String id) { |
59 | return new PortChainId(UUID.fromString(id)); | 58 | return new PortChainId(UUID.fromString(id)); |
60 | } | 59 | } |
61 | 60 | ||
... | @@ -73,10 +72,9 @@ public final class PortChainId { | ... | @@ -73,10 +72,9 @@ public final class PortChainId { |
73 | if (this == obj) { | 72 | if (this == obj) { |
74 | return true; | 73 | return true; |
75 | } | 74 | } |
76 | - | 75 | + if (obj instanceof PortChainId) { |
77 | - if (obj.getClass() == this.getClass()) { | 76 | + final PortChainId other = (PortChainId) obj; |
78 | - PortChainId that = (PortChainId) obj; | 77 | + return Objects.equals(this.portChainId, other.portChainId); |
79 | - return Objects.equal(this.portChainId, that.portChainId); | ||
80 | } | 78 | } |
81 | return false; | 79 | return false; |
82 | } | 80 | } |
... | @@ -88,8 +86,6 @@ public final class PortChainId { | ... | @@ -88,8 +86,6 @@ public final class PortChainId { |
88 | 86 | ||
89 | @Override | 87 | @Override |
90 | public String toString() { | 88 | public String toString() { |
91 | - return toStringHelper(this) | 89 | + return toStringHelper(this).add("portChainId", portChainId).toString(); |
92 | - .add("portChainId", portChainId.toString()) | ||
93 | - .toString(); | ||
94 | } | 90 | } |
95 | } | 91 | } | ... | ... |
... | @@ -82,10 +82,10 @@ public class PortChainWebResource extends AbstractWebResource { | ... | @@ -82,10 +82,10 @@ public class PortChainWebResource extends AbstractWebResource { |
82 | @Produces(MediaType.APPLICATION_JSON) | 82 | @Produces(MediaType.APPLICATION_JSON) |
83 | public Response getPortPain(@PathParam("chain_id") String id) { | 83 | public Response getPortPain(@PathParam("chain_id") String id) { |
84 | 84 | ||
85 | - if (!service.exists(PortChainId.portChainId(id))) { | 85 | + if (!service.exists(PortChainId.of(id))) { |
86 | return Response.status(NOT_FOUND).entity(PORT_CHAIN_NOT_FOUND).build(); | 86 | return Response.status(NOT_FOUND).entity(PORT_CHAIN_NOT_FOUND).build(); |
87 | } | 87 | } |
88 | - PortChain portChain = nullIsNotFound(service.getPortChain(PortChainId.portChainId(id)), | 88 | + PortChain portChain = nullIsNotFound(service.getPortChain(PortChainId.of(id)), |
89 | PORT_CHAIN_NOT_FOUND); | 89 | PORT_CHAIN_NOT_FOUND); |
90 | ObjectNode result = new ObjectMapper().createObjectNode(); | 90 | ObjectNode result = new ObjectMapper().createObjectNode(); |
91 | result.set("port_chain", new PortChainCodec().encode(portChain, this)); | 91 | result.set("port_chain", new PortChainCodec().encode(portChain, this)); |
... | @@ -147,7 +147,7 @@ public class PortChainWebResource extends AbstractWebResource { | ... | @@ -147,7 +147,7 @@ public class PortChainWebResource extends AbstractWebResource { |
147 | @DELETE | 147 | @DELETE |
148 | public void deletePortPain(@PathParam("chain_id") String id) { | 148 | public void deletePortPain(@PathParam("chain_id") String id) { |
149 | log.debug("Deletes port chain by identifier {}.", id); | 149 | log.debug("Deletes port chain by identifier {}.", id); |
150 | - PortChainId portChainId = PortChainId.portChainId(id); | 150 | + PortChainId portChainId = PortChainId.of(id); |
151 | 151 | ||
152 | Boolean issuccess = nullIsNotFound(service.removePortChain(portChainId), PORT_CHAIN_NOT_FOUND); | 152 | Boolean issuccess = nullIsNotFound(service.removePortChain(portChainId), PORT_CHAIN_NOT_FOUND); |
153 | if (!issuccess) { | 153 | if (!issuccess) { | ... | ... |
... | @@ -59,7 +59,7 @@ public final class PortChainCodec extends JsonCodec<PortChain> { | ... | @@ -59,7 +59,7 @@ public final class PortChainCodec extends JsonCodec<PortChain> { |
59 | 59 | ||
60 | String id = nullIsIllegal(json.get(ID), | 60 | String id = nullIsIllegal(json.get(ID), |
61 | ID + MISSING_MEMBER_MESSAGE).asText(); | 61 | ID + MISSING_MEMBER_MESSAGE).asText(); |
62 | - resultBuilder.setId(PortChainId.portChainId(id)); | 62 | + resultBuilder.setId(PortChainId.of(id)); |
63 | 63 | ||
64 | String tenantId = nullIsIllegal(json.get(TENANT_ID), | 64 | String tenantId = nullIsIllegal(json.get(TENANT_ID), |
65 | TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); | 65 | TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); | ... | ... |
-
Please register or login to post a comment