HIGUCHI Yuta
Committed by Gerrit Code Review

equals for {Device,Port,Link,Host}Description

Change-Id: Ia69a469ed7b3ef183e45b3fb4d110edcbb4f3aad
......@@ -16,6 +16,7 @@
package org.onosproject.net;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Objects;
/**
* Base implementation of an annotated model description.
......@@ -46,4 +47,18 @@ public abstract class AbstractDescription implements Annotated {
return annotations;
}
@Override
public int hashCode() {
return Objects.hashCode(annotations);
}
@Override
public boolean equals(Object object) {
if (object instanceof AbstractDescription) {
AbstractDescription that = (AbstractDescription) object;
return Objects.equal(this.annotations, that.annotations);
}
return false;
}
}
......
......@@ -24,6 +24,7 @@ import java.net.URI;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.Device.Type;
import com.google.common.base.Objects;
/**
* Default implementation of immutable device description entity.
......@@ -132,6 +133,30 @@ public class DefaultDeviceDescription extends AbstractDescription
.toString();
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), uri, type, manufacturer,
hwVersion, swVersion, serialNumber, chassisId);
}
@Override
public boolean equals(Object object) {
if (object instanceof DefaultDeviceDescription) {
if (!super.equals(object)) {
return false;
}
DefaultDeviceDescription that = (DefaultDeviceDescription) object;
return Objects.equal(this.uri, that.uri)
&& Objects.equal(this.type, that.type)
&& Objects.equal(this.manufacturer, that.manufacturer)
&& Objects.equal(this.hwVersion, that.hwVersion)
&& Objects.equal(this.swVersion, that.swVersion)
&& Objects.equal(this.serialNumber, that.serialNumber)
&& Objects.equal(this.chassisId, that.chassisId);
}
return false;
}
// default constructor for serialization
private DefaultDeviceDescription() {
this.uri = null;
......
......@@ -21,6 +21,7 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
import static org.onosproject.net.Port.Type;
import com.google.common.base.Objects;
/**
* Default implementation of immutable port description.
......@@ -117,4 +118,25 @@ public class DefaultPortDescription extends AbstractDescription
.toString();
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), number, isEnabled, type,
portSpeed);
}
@Override
public boolean equals(Object object) {
if (object != null && getClass() == object.getClass()) {
if (!super.equals(object)) {
return false;
}
DefaultPortDescription that = (DefaultPortDescription) object;
return Objects.equal(this.number, that.number)
&& Objects.equal(this.isEnabled, that.isEnabled)
&& Objects.equal(this.type, that.type)
&& Objects.equal(this.portSpeed, that.portSpeed);
}
return false;
}
}
......
......@@ -28,6 +28,7 @@ import org.onlab.packet.VlanId;
import com.google.common.collect.ImmutableSet;
import static com.google.common.base.MoreObjects.toStringHelper;
import com.google.common.base.Objects;
/**
* Default implementation of an immutable host description.
......@@ -119,4 +120,24 @@ public class DefaultHostDescription extends AbstractDescription
.toString();
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), mac, vlan, location, ip);
}
@Override
public boolean equals(Object object) {
if (object != null && getClass() == object.getClass()) {
if (!super.equals(object)) {
return false;
}
DefaultHostDescription that = (DefaultHostDescription) object;
return Objects.equal(this.mac, that.mac)
&& Objects.equal(this.vlan, that.vlan)
&& Objects.equal(this.location, that.location)
&& Objects.equal(this.ip, that.ip);
}
return false;
}
}
......
......@@ -20,6 +20,7 @@ import org.onosproject.net.AbstractDescription;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.SparseAnnotations;
import com.google.common.base.Objects;
/**
* Default implementation of immutable link description entity.
......@@ -70,4 +71,23 @@ public class DefaultLinkDescription extends AbstractDescription
.add("type", type()).toString();
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), src, dst, type);
}
@Override
public boolean equals(Object object) {
if (object != null && getClass() == object.getClass()) {
if (!super.equals(object)) {
return false;
}
DefaultLinkDescription that = (DefaultLinkDescription) object;
return Objects.equal(this.src, that.src)
&& Objects.equal(this.dst, that.dst)
&& Objects.equal(this.type, that.type);
}
return false;
}
}
......
......@@ -415,7 +415,7 @@ public class HostLocationProviderTest {
public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) {
if (added == null) {
added = hostDescription;
} else if ((moved == null) && !hostDescription.equals(added)) {
} else if ((moved == null) && hostDescription != added) {
moved = hostDescription;
} else {
spine = hostDescription;
......