Sho SHIMIZU

Add short-cut path taking when the paremter type is equal to own type

Change-Id: I0edceb6630e0312ce5139d3e453a183a0cf06fd5
......@@ -87,7 +87,13 @@ final class EncodableDiscreteResources implements DiscreteResources {
@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
......
......@@ -59,7 +59,13 @@ final class GenericDiscreteResources implements DiscreteResources {
@Override
public DiscreteResources difference(DiscreteResources other) {
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
......
......@@ -67,6 +67,15 @@ final class UnifiedDiscreteResources implements DiscreteResources {
@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()));
}
......