Committed by
Gerrit Code Review
equals for {Device,Port,Link,Host}Description
Change-Id: Ia69a469ed7b3ef183e45b3fb4d110edcbb4f3aad
Showing
6 changed files
with
104 additions
and
1 deletions
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.net; | 16 | package org.onosproject.net; |
| 17 | 17 | ||
| 18 | import static com.google.common.base.Preconditions.checkArgument; | 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | +import com.google.common.base.Objects; | ||
| 19 | 20 | ||
| 20 | /** | 21 | /** |
| 21 | * Base implementation of an annotated model description. | 22 | * Base implementation of an annotated model description. |
| ... | @@ -46,4 +47,18 @@ public abstract class AbstractDescription implements Annotated { | ... | @@ -46,4 +47,18 @@ public abstract class AbstractDescription implements Annotated { |
| 46 | return annotations; | 47 | return annotations; |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 50 | + @Override | ||
| 51 | + public int hashCode() { | ||
| 52 | + return Objects.hashCode(annotations); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public boolean equals(Object object) { | ||
| 57 | + if (object instanceof AbstractDescription) { | ||
| 58 | + AbstractDescription that = (AbstractDescription) object; | ||
| 59 | + return Objects.equal(this.annotations, that.annotations); | ||
| 60 | + } | ||
| 61 | + return false; | ||
| 62 | + } | ||
| 63 | + | ||
| 49 | } | 64 | } | ... | ... |
| ... | @@ -24,6 +24,7 @@ import java.net.URI; | ... | @@ -24,6 +24,7 @@ import java.net.URI; |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | import static org.onosproject.net.Device.Type; | 26 | import static org.onosproject.net.Device.Type; |
| 27 | +import com.google.common.base.Objects; | ||
| 27 | 28 | ||
| 28 | /** | 29 | /** |
| 29 | * Default implementation of immutable device description entity. | 30 | * Default implementation of immutable device description entity. |
| ... | @@ -132,6 +133,30 @@ public class DefaultDeviceDescription extends AbstractDescription | ... | @@ -132,6 +133,30 @@ public class DefaultDeviceDescription extends AbstractDescription |
| 132 | .toString(); | 133 | .toString(); |
| 133 | } | 134 | } |
| 134 | 135 | ||
| 136 | + @Override | ||
| 137 | + public int hashCode() { | ||
| 138 | + return Objects.hashCode(super.hashCode(), uri, type, manufacturer, | ||
| 139 | + hwVersion, swVersion, serialNumber, chassisId); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + @Override | ||
| 143 | + public boolean equals(Object object) { | ||
| 144 | + if (object instanceof DefaultDeviceDescription) { | ||
| 145 | + if (!super.equals(object)) { | ||
| 146 | + return false; | ||
| 147 | + } | ||
| 148 | + DefaultDeviceDescription that = (DefaultDeviceDescription) object; | ||
| 149 | + return Objects.equal(this.uri, that.uri) | ||
| 150 | + && Objects.equal(this.type, that.type) | ||
| 151 | + && Objects.equal(this.manufacturer, that.manufacturer) | ||
| 152 | + && Objects.equal(this.hwVersion, that.hwVersion) | ||
| 153 | + && Objects.equal(this.swVersion, that.swVersion) | ||
| 154 | + && Objects.equal(this.serialNumber, that.serialNumber) | ||
| 155 | + && Objects.equal(this.chassisId, that.chassisId); | ||
| 156 | + } | ||
| 157 | + return false; | ||
| 158 | + } | ||
| 159 | + | ||
| 135 | // default constructor for serialization | 160 | // default constructor for serialization |
| 136 | private DefaultDeviceDescription() { | 161 | private DefaultDeviceDescription() { |
| 137 | this.uri = null; | 162 | this.uri = null; | ... | ... |
| ... | @@ -21,6 +21,7 @@ import org.onosproject.net.PortNumber; | ... | @@ -21,6 +21,7 @@ import org.onosproject.net.PortNumber; |
| 21 | import org.onosproject.net.SparseAnnotations; | 21 | import org.onosproject.net.SparseAnnotations; |
| 22 | 22 | ||
| 23 | import static org.onosproject.net.Port.Type; | 23 | import static org.onosproject.net.Port.Type; |
| 24 | +import com.google.common.base.Objects; | ||
| 24 | 25 | ||
| 25 | /** | 26 | /** |
| 26 | * Default implementation of immutable port description. | 27 | * Default implementation of immutable port description. |
| ... | @@ -117,4 +118,25 @@ public class DefaultPortDescription extends AbstractDescription | ... | @@ -117,4 +118,25 @@ public class DefaultPortDescription extends AbstractDescription |
| 117 | .toString(); | 118 | .toString(); |
| 118 | } | 119 | } |
| 119 | 120 | ||
| 121 | + @Override | ||
| 122 | + public int hashCode() { | ||
| 123 | + return Objects.hashCode(super.hashCode(), number, isEnabled, type, | ||
| 124 | + portSpeed); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + @Override | ||
| 128 | + public boolean equals(Object object) { | ||
| 129 | + if (object != null && getClass() == object.getClass()) { | ||
| 130 | + if (!super.equals(object)) { | ||
| 131 | + return false; | ||
| 132 | + } | ||
| 133 | + DefaultPortDescription that = (DefaultPortDescription) object; | ||
| 134 | + return Objects.equal(this.number, that.number) | ||
| 135 | + && Objects.equal(this.isEnabled, that.isEnabled) | ||
| 136 | + && Objects.equal(this.type, that.type) | ||
| 137 | + && Objects.equal(this.portSpeed, that.portSpeed); | ||
| 138 | + } | ||
| 139 | + return false; | ||
| 140 | + } | ||
| 141 | + | ||
| 120 | } | 142 | } | ... | ... |
| ... | @@ -28,6 +28,7 @@ import org.onlab.packet.VlanId; | ... | @@ -28,6 +28,7 @@ import org.onlab.packet.VlanId; |
| 28 | import com.google.common.collect.ImmutableSet; | 28 | import com.google.common.collect.ImmutableSet; |
| 29 | 29 | ||
| 30 | import static com.google.common.base.MoreObjects.toStringHelper; | 30 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 31 | +import com.google.common.base.Objects; | ||
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| 33 | * Default implementation of an immutable host description. | 34 | * Default implementation of an immutable host description. |
| ... | @@ -119,4 +120,24 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -119,4 +120,24 @@ public class DefaultHostDescription extends AbstractDescription |
| 119 | .toString(); | 120 | .toString(); |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 123 | + @Override | ||
| 124 | + public int hashCode() { | ||
| 125 | + return Objects.hashCode(super.hashCode(), mac, vlan, location, ip); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + @Override | ||
| 129 | + public boolean equals(Object object) { | ||
| 130 | + if (object != null && getClass() == object.getClass()) { | ||
| 131 | + if (!super.equals(object)) { | ||
| 132 | + return false; | ||
| 133 | + } | ||
| 134 | + DefaultHostDescription that = (DefaultHostDescription) object; | ||
| 135 | + return Objects.equal(this.mac, that.mac) | ||
| 136 | + && Objects.equal(this.vlan, that.vlan) | ||
| 137 | + && Objects.equal(this.location, that.location) | ||
| 138 | + && Objects.equal(this.ip, that.ip); | ||
| 139 | + } | ||
| 140 | + return false; | ||
| 141 | + } | ||
| 142 | + | ||
| 122 | } | 143 | } | ... | ... |
| ... | @@ -20,6 +20,7 @@ import org.onosproject.net.AbstractDescription; | ... | @@ -20,6 +20,7 @@ import org.onosproject.net.AbstractDescription; |
| 20 | import org.onosproject.net.ConnectPoint; | 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.Link; | 21 | import org.onosproject.net.Link; |
| 22 | import org.onosproject.net.SparseAnnotations; | 22 | import org.onosproject.net.SparseAnnotations; |
| 23 | +import com.google.common.base.Objects; | ||
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | * Default implementation of immutable link description entity. | 26 | * Default implementation of immutable link description entity. |
| ... | @@ -70,4 +71,23 @@ public class DefaultLinkDescription extends AbstractDescription | ... | @@ -70,4 +71,23 @@ public class DefaultLinkDescription extends AbstractDescription |
| 70 | .add("type", type()).toString(); | 71 | .add("type", type()).toString(); |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 74 | + @Override | ||
| 75 | + public int hashCode() { | ||
| 76 | + return Objects.hashCode(super.hashCode(), src, dst, type); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public boolean equals(Object object) { | ||
| 81 | + if (object != null && getClass() == object.getClass()) { | ||
| 82 | + if (!super.equals(object)) { | ||
| 83 | + return false; | ||
| 84 | + } | ||
| 85 | + DefaultLinkDescription that = (DefaultLinkDescription) object; | ||
| 86 | + return Objects.equal(this.src, that.src) | ||
| 87 | + && Objects.equal(this.dst, that.dst) | ||
| 88 | + && Objects.equal(this.type, that.type); | ||
| 89 | + } | ||
| 90 | + return false; | ||
| 91 | + } | ||
| 92 | + | ||
| 73 | } | 93 | } | ... | ... |
| ... | @@ -415,7 +415,7 @@ public class HostLocationProviderTest { | ... | @@ -415,7 +415,7 @@ public class HostLocationProviderTest { |
| 415 | public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { | 415 | public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { |
| 416 | if (added == null) { | 416 | if (added == null) { |
| 417 | added = hostDescription; | 417 | added = hostDescription; |
| 418 | - } else if ((moved == null) && !hostDescription.equals(added)) { | 418 | + } else if ((moved == null) && hostDescription != added) { |
| 419 | moved = hostDescription; | 419 | moved = hostDescription; |
| 420 | } else { | 420 | } else { |
| 421 | spine = hostDescription; | 421 | spine = hostDescription; | ... | ... |
-
Please register or login to post a comment