Bugfix and cosmetic changes to resource subsystem
- Continuous resource was always considered not available
- Support querying for child resource against Continuous
(result is no children)
- Resource equality to compare id and exact type
- Add missing information in Continuous resource toString()
- More concise String representation for ResourceId
- additional logging added during above bug investigation.
Change-Id: I58a95b95b91c246c3c5dbb136a1820f988c6fccd
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/Resource.java b/core/api/src/main/java/org/onosproject/net/newresource/Resource.java
index 72b9a57..15e4626 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/Resource.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/Resource.java
@@ -208,7 +208,11 @@
if (this == obj) {
return true;
}
- if (!(obj instanceof Resource)) {
+
+ if (obj == null) {
+ return false;
+ }
+ if (this.getClass() != obj.getClass()) {
return false;
}
final Resource that = (Resource) obj;
@@ -259,25 +263,14 @@
@Override
public int hashCode() {
- return Objects.hash(this.id(), this.value);
+ return super.hashCode();
}
+ // explicitly overriding to express that we intentionally ignore
+ // `value` in equality comparison
@Override
public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (!(obj instanceof Continuous)) {
- return false;
- }
-
- if (!super.equals(obj)) {
- return false;
- }
-
- final Continuous other = (Continuous) obj;
- return Objects.equals(this.id(), other.id());
+ return super.equals(obj);
}
/**
@@ -288,6 +281,14 @@
public double value() {
return value;
}
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("id", id())
+ .add("value", value)
+ .toString();
+ }
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceId.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceId.java
index c18e08b..6bfc3cc 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceId.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceId.java
@@ -16,7 +16,6 @@
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
@@ -95,8 +94,6 @@
@Override
public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("components", components)
- .toString();
+ return components.toString();
}
}