Committed by
Gerrit Code Review
Equals and Hash code fix for byte array.
Change-Id: I643dd22f285d153752107273fadb77248bf83589
Showing
1 changed file
with
19 additions
and
4 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.iptopology.api; | ... | @@ -17,6 +17,7 @@ package org.onosproject.iptopology.api; |
17 | 17 | ||
18 | import static com.google.common.base.MoreObjects.toStringHelper; | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
19 | 19 | ||
20 | +import java.util.Arrays; | ||
20 | import java.util.Objects; | 21 | import java.util.Objects; |
21 | 22 | ||
22 | /** | 23 | /** |
... | @@ -53,7 +54,7 @@ public class IsoNodeId implements RouteIdentifier { | ... | @@ -53,7 +54,7 @@ public class IsoNodeId implements RouteIdentifier { |
53 | 54 | ||
54 | @Override | 55 | @Override |
55 | public int hashCode() { | 56 | public int hashCode() { |
56 | - return Objects.hash(isoNodeId, type); | 57 | + return Objects.hash(Arrays.hashCode(isoNodeId), type); |
57 | } | 58 | } |
58 | 59 | ||
59 | @Override | 60 | @Override |
... | @@ -64,15 +65,29 @@ public class IsoNodeId implements RouteIdentifier { | ... | @@ -64,15 +65,29 @@ public class IsoNodeId implements RouteIdentifier { |
64 | 65 | ||
65 | if (obj instanceof IsoNodeId) { | 66 | if (obj instanceof IsoNodeId) { |
66 | IsoNodeId other = (IsoNodeId) obj; | 67 | IsoNodeId other = (IsoNodeId) obj; |
67 | - return Objects.equals(isoNodeId, other.isoNodeId) && Objects.equals(type, other.type); | 68 | + return Arrays.equals(isoNodeId, other.isoNodeId) && Objects.equals(type, other.type); |
68 | } | 69 | } |
69 | return false; | 70 | return false; |
70 | } | 71 | } |
71 | 72 | ||
73 | + /* | ||
74 | + * Get iso node ID in specified string format. | ||
75 | + */ | ||
76 | + private String isoNodeIdString() { | ||
77 | + if (isoNodeId != null) { | ||
78 | + int p1 = (int) isoNodeId[0] << 8 | (int) isoNodeId[1]; | ||
79 | + int p2 = (int) isoNodeId[2] << 8 | (int) isoNodeId[3]; | ||
80 | + int p3 = (int) isoNodeId[4] << 8 | (int) isoNodeId[5]; | ||
81 | + | ||
82 | + return String.format("%1$d.%2$d.%3$d", p1, p2, p3); | ||
83 | + } | ||
84 | + return null; | ||
85 | + } | ||
86 | + | ||
72 | @Override | 87 | @Override |
73 | public String toString() { | 88 | public String toString() { |
74 | - return toStringHelper(this) | 89 | + return toStringHelper(this).omitNullValues() |
75 | - .add("isoNodeId", isoNodeId) | 90 | + .add("isoNodeId", isoNodeIdString()) |
76 | .add("type", type) | 91 | .add("type", type) |
77 | .toString(); | 92 | .toString(); |
78 | } | 93 | } | ... | ... |
-
Please register or login to post a comment