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 { ...@@ -87,7 +87,13 @@ final class EncodableDiscreteResources implements DiscreteResources {
87 87
88 @Override 88 @Override
89 public DiscreteResources difference(DiscreteResources other) { 89 public DiscreteResources difference(DiscreteResources other) {
90 - return of(parent, Sets.difference(values(), other.values())); 90 + if (other instanceof EncodableDiscreteResources) {
91 + return of(parent, Sets.difference(this.values(), other.values()));
92 + } else if (other instanceof EmptyDiscreteResources) {
93 + return this;
94 + }
95 +
96 + return DiscreteResources.of(Sets.difference(values(), other.values()));
91 } 97 }
92 98
93 @Override 99 @Override
......
...@@ -59,7 +59,13 @@ final class GenericDiscreteResources implements DiscreteResources { ...@@ -59,7 +59,13 @@ final class GenericDiscreteResources implements DiscreteResources {
59 59
60 @Override 60 @Override
61 public DiscreteResources difference(DiscreteResources other) { 61 public DiscreteResources difference(DiscreteResources other) {
62 + if (other instanceof GenericDiscreteResources) {
62 return of(Sets.difference(this.values(), other.values())); 63 return of(Sets.difference(this.values(), other.values()));
64 + } else if (other instanceof EmptyDiscreteResources) {
65 + return this;
66 + }
67 +
68 + return DiscreteResources.of(Sets.difference(this.values(), other.values()));
63 } 69 }
64 70
65 @Override 71 @Override
......
...@@ -67,6 +67,15 @@ final class UnifiedDiscreteResources implements DiscreteResources { ...@@ -67,6 +67,15 @@ final class UnifiedDiscreteResources implements DiscreteResources {
67 67
68 @Override 68 @Override
69 public DiscreteResources difference(DiscreteResources other) { 69 public DiscreteResources difference(DiscreteResources other) {
70 + if (other instanceof UnifiedDiscreteResources) {
71 + UnifiedDiscreteResources cast = (UnifiedDiscreteResources) other;
72 + return new UnifiedDiscreteResources(
73 + this.generics.difference(cast.generics),
74 + this.encodables.difference(cast.encodables));
75 + } else if (other instanceof EmptyDiscreteResources) {
76 + return this;
77 + }
78 +
70 return of(Sets.difference(this.values(), other.values())); 79 return of(Sets.difference(this.values(), other.values()));
71 } 80 }
72 81
......