Sho SHIMIZU

Add missing equals(), hashCode() and toString()

Change-Id: I99e313b1672369092596d8e28e08778021eb1998
......@@ -15,6 +15,7 @@
*/
package org.onosproject.store.resource.impl;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.resource.DiscreteResource;
import org.onosproject.net.resource.DiscreteResourceId;
......@@ -65,4 +66,11 @@ final class EmptyDiscreteResources implements DiscreteResources {
public Set<DiscreteResource> values() {
return ImmutableSet.of();
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("values", ImmutableSet.of())
.toString();
}
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.store.resource.impl;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import org.onosproject.net.resource.DiscreteResource;
import org.onosproject.net.resource.DiscreteResourceCodec;
......@@ -24,6 +25,7 @@ import org.onosproject.net.resource.Resources;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -125,4 +127,29 @@ final class EncodableDiscreteResources implements DiscreteResources {
Map<Class<?>, EncodedDiscreteResources> rawValues() {
return values;
}
@Override
public int hashCode() {
return Objects.hash(parent, values);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final EncodableDiscreteResources other = (EncodableDiscreteResources) obj;
return Objects.equals(this.parent, other.parent)
&& Objects.equals(this.values, other.values);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("values", values())
.toString();
}
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.store.resource.impl;
import com.google.common.base.MoreObjects;
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
......@@ -26,6 +27,7 @@ import org.onosproject.net.resource.DiscreteResourceId;
import org.onosproject.net.resource.Resources;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
......@@ -83,4 +85,30 @@ final class EncodedDiscreteResources {
boolean isEmpty() {
return rangeSet.isEmpty();
}
@Override
public int hashCode() {
return Objects.hash(rangeSet, codec);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final EncodedDiscreteResources other = (EncodedDiscreteResources) obj;
return Objects.equals(this.rangeSet, other.rangeSet)
&& Objects.equals(this.codec, other.codec);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("rangeSet", rangeSet)
.add("codec", codec)
.toString();
}
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.store.resource.impl;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import org.onosproject.net.resource.DiscreteResource;
import org.onosproject.net.resource.DiscreteResourceId;
......@@ -22,6 +23,7 @@ import org.onosproject.net.resource.Resources;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -95,4 +97,29 @@ final class UnifiedDiscreteResources implements DiscreteResources {
return Stream.concat(encodables.values().stream(), generics.values().stream())
.collect(Collectors.toCollection(LinkedHashSet::new));
}
@Override
public int hashCode() {
return Objects.hash(generics, encodables);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final UnifiedDiscreteResources other = (UnifiedDiscreteResources) obj;
return Objects.equals(this.generics, other.generics)
&& Objects.equals(this.encodables, other.encodables);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("values", values())
.toString();
}
}
......