Add short-cut path taking when the paremter type is equal to own type
Change-Id: I0edceb6630e0312ce5139d3e453a183a0cf06fd5
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/EncodableDiscreteResources.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/EncodableDiscreteResources.java
index 512b233..9edfb5f 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/EncodableDiscreteResources.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/EncodableDiscreteResources.java
@@ -87,7 +87,13 @@
@Override
public DiscreteResources difference(DiscreteResources other) {
- return of(parent, Sets.difference(values(), other.values()));
+ if (other instanceof EncodableDiscreteResources) {
+ return of(parent, Sets.difference(this.values(), other.values()));
+ } else if (other instanceof EmptyDiscreteResources) {
+ return this;
+ }
+
+ return DiscreteResources.of(Sets.difference(values(), other.values()));
}
@Override
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/GenericDiscreteResources.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/GenericDiscreteResources.java
index 1aa8bb9..4672d81 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/GenericDiscreteResources.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/GenericDiscreteResources.java
@@ -59,7 +59,13 @@
@Override
public DiscreteResources difference(DiscreteResources other) {
- return of(Sets.difference(this.values(), other.values()));
+ if (other instanceof GenericDiscreteResources) {
+ return of(Sets.difference(this.values(), other.values()));
+ } else if (other instanceof EmptyDiscreteResources) {
+ return this;
+ }
+
+ return DiscreteResources.of(Sets.difference(this.values(), other.values()));
}
@Override
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/UnifiedDiscreteResources.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/UnifiedDiscreteResources.java
index 56e6b87..b229308 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/UnifiedDiscreteResources.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/UnifiedDiscreteResources.java
@@ -67,6 +67,15 @@
@Override
public DiscreteResources difference(DiscreteResources other) {
+ if (other instanceof UnifiedDiscreteResources) {
+ UnifiedDiscreteResources cast = (UnifiedDiscreteResources) other;
+ return new UnifiedDiscreteResources(
+ this.generics.difference(cast.generics),
+ this.encodables.difference(cast.encodables));
+ } else if (other instanceof EmptyDiscreteResources) {
+ return this;
+ }
+
return of(Sets.difference(this.values(), other.values()));
}