Sho SHIMIZU

Rename NonEncodableDiscreteResources to GenericDiscreteResources

Change-Id: Ib610895b3e2251af1ae5b1cae2b9b8f378a8d920
......@@ -74,7 +74,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
.register(KryoNamespaces.API)
.register(UnifiedDiscreteResources.class)
.register(new EncodableDiscreteResourcesSerializer(), EncodableDiscreteResources.class)
.register(NonEncodableDiscreteResources.class)
.register(GenericDiscreteResources.class)
.register(EmptyDiscreteResources.class)
.register(ContinuousResourceAllocation.class)
.build());
......
......@@ -27,7 +27,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
final class NonEncodableDiscreteResources implements DiscreteResources {
final class GenericDiscreteResources implements DiscreteResources {
private final Set<DiscreteResource> values;
static DiscreteResources of(Set<DiscreteResource> resources) {
......@@ -35,15 +35,15 @@ final class NonEncodableDiscreteResources implements DiscreteResources {
return DiscreteResources.empty();
}
return new NonEncodableDiscreteResources(resources);
return new GenericDiscreteResources(resources);
}
private NonEncodableDiscreteResources(Set<DiscreteResource> values) {
private GenericDiscreteResources(Set<DiscreteResource> values) {
this.values = values;
}
// for serializer
private NonEncodableDiscreteResources() {
private GenericDiscreteResources() {
this.values = null;
}
......@@ -59,7 +59,7 @@ final class NonEncodableDiscreteResources implements DiscreteResources {
@Override
public DiscreteResources difference(DiscreteResources other) {
return new NonEncodableDiscreteResources(Sets.difference(this.values, other.values()));
return new GenericDiscreteResources(Sets.difference(this.values, other.values()));
}
@Override
......@@ -77,7 +77,7 @@ final class NonEncodableDiscreteResources implements DiscreteResources {
public DiscreteResources add(DiscreteResources other) {
Set<DiscreteResource> newValues = new LinkedHashSet<>(this.values);
newValues.addAll(other.values());
return new NonEncodableDiscreteResources(newValues);
return new GenericDiscreteResources(newValues);
}
// returns a new instance, not mutate the current instance
......@@ -85,7 +85,7 @@ final class NonEncodableDiscreteResources implements DiscreteResources {
public DiscreteResources remove(List<DiscreteResource> removed) {
Set<DiscreteResource> newValues = new LinkedHashSet<>(this.values);
newValues.removeAll(removed);
return new NonEncodableDiscreteResources(newValues);
return new GenericDiscreteResources(newValues);
}
@Override
......@@ -108,7 +108,7 @@ final class NonEncodableDiscreteResources implements DiscreteResources {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final NonEncodableDiscreteResources other = (NonEncodableDiscreteResources) obj;
final GenericDiscreteResources other = (GenericDiscreteResources) obj;
return Objects.equals(this.values, other.values);
}
......
......@@ -33,7 +33,7 @@ import java.util.stream.Stream;
* and those that can't encoded as integer.
*/
final class UnifiedDiscreteResources implements DiscreteResources {
private final DiscreteResources nonEncodables;
private final DiscreteResources generics;
private final DiscreteResources encodables;
private static final Codecs CODECS = Codecs.getInstance();
......@@ -45,13 +45,13 @@ final class UnifiedDiscreteResources implements DiscreteResources {
Map<Boolean, Set<DiscreteResource>> partitioned = resources.stream()
.collect(Collectors.partitioningBy(CODECS::isEncodable, Collectors.toCollection(LinkedHashSet::new)));
return new UnifiedDiscreteResources(
NonEncodableDiscreteResources.of(partitioned.get(false)),
GenericDiscreteResources.of(partitioned.get(false)),
EncodableDiscreteResources.of(partitioned.get(true))
);
}
private UnifiedDiscreteResources(DiscreteResources nonEncodables, DiscreteResources encodables) {
this.nonEncodables = nonEncodables;
private UnifiedDiscreteResources(DiscreteResources generics, DiscreteResources encodables) {
this.generics = generics;
this.encodables = encodables;
}
......@@ -61,7 +61,7 @@ final class UnifiedDiscreteResources implements DiscreteResources {
return encodables.lookup(id);
}
return nonEncodables.lookup(id);
return generics.lookup(id);
}
@Override
......@@ -71,14 +71,14 @@ final class UnifiedDiscreteResources implements DiscreteResources {
@Override
public boolean isEmpty() {
return nonEncodables.isEmpty() && encodables.isEmpty();
return generics.isEmpty() && encodables.isEmpty();
}
@Override
public boolean containsAny(List<DiscreteResource> other) {
Map<Boolean, List<DiscreteResource>> partitioned = other.stream()
.collect(Collectors.partitioningBy(CODECS::isEncodable));
return nonEncodables.containsAny(partitioned.get(false)) || encodables.containsAny(partitioned.get(true));
return generics.containsAny(partitioned.get(false)) || encodables.containsAny(partitioned.get(true));
}
@Override
......@@ -93,7 +93,7 @@ final class UnifiedDiscreteResources implements DiscreteResources {
@Override
public Set<DiscreteResource> values() {
return Stream.concat(encodables.values().stream(), nonEncodables.values().stream())
return Stream.concat(encodables.values().stream(), generics.values().stream())
.collect(Collectors.toCollection(LinkedHashSet::new));
}
}
......