Add missing equals(), hashCode() and toString()
Change-Id: I99e313b1672369092596d8e28e08778021eb1998
Showing
4 changed files
with
90 additions
and
0 deletions
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.store.resource.impl; | 16 | package org.onosproject.store.resource.impl; |
| 17 | 17 | ||
| 18 | +import com.google.common.base.MoreObjects; | ||
| 18 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
| 19 | import org.onosproject.net.resource.DiscreteResource; | 20 | import org.onosproject.net.resource.DiscreteResource; |
| 20 | import org.onosproject.net.resource.DiscreteResourceId; | 21 | import org.onosproject.net.resource.DiscreteResourceId; |
| ... | @@ -65,4 +66,11 @@ final class EmptyDiscreteResources implements DiscreteResources { | ... | @@ -65,4 +66,11 @@ final class EmptyDiscreteResources implements DiscreteResources { |
| 65 | public Set<DiscreteResource> values() { | 66 | public Set<DiscreteResource> values() { |
| 66 | return ImmutableSet.of(); | 67 | return ImmutableSet.of(); |
| 67 | } | 68 | } |
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public String toString() { | ||
| 72 | + return MoreObjects.toStringHelper(this) | ||
| 73 | + .add("values", ImmutableSet.of()) | ||
| 74 | + .toString(); | ||
| 75 | + } | ||
| 68 | } | 76 | } | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.store.resource.impl; | 16 | package org.onosproject.store.resource.impl; |
| 17 | 17 | ||
| 18 | +import com.google.common.base.MoreObjects; | ||
| 18 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
| 19 | import org.onosproject.net.resource.DiscreteResource; | 20 | import org.onosproject.net.resource.DiscreteResource; |
| 20 | import org.onosproject.net.resource.DiscreteResourceCodec; | 21 | import org.onosproject.net.resource.DiscreteResourceCodec; |
| ... | @@ -24,6 +25,7 @@ import org.onosproject.net.resource.Resources; | ... | @@ -24,6 +25,7 @@ import org.onosproject.net.resource.Resources; |
| 24 | import java.util.LinkedHashMap; | 25 | import java.util.LinkedHashMap; |
| 25 | import java.util.LinkedHashSet; | 26 | import java.util.LinkedHashSet; |
| 26 | import java.util.Map; | 27 | import java.util.Map; |
| 28 | +import java.util.Objects; | ||
| 27 | import java.util.Optional; | 29 | import java.util.Optional; |
| 28 | import java.util.Set; | 30 | import java.util.Set; |
| 29 | import java.util.stream.Collectors; | 31 | import java.util.stream.Collectors; |
| ... | @@ -125,4 +127,29 @@ final class EncodableDiscreteResources implements DiscreteResources { | ... | @@ -125,4 +127,29 @@ final class EncodableDiscreteResources implements DiscreteResources { |
| 125 | Map<Class<?>, EncodedDiscreteResources> rawValues() { | 127 | Map<Class<?>, EncodedDiscreteResources> rawValues() { |
| 126 | return values; | 128 | return values; |
| 127 | } | 129 | } |
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public int hashCode() { | ||
| 133 | + return Objects.hash(parent, values); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + @Override | ||
| 137 | + public boolean equals(Object obj) { | ||
| 138 | + if (this == obj) { | ||
| 139 | + return true; | ||
| 140 | + } | ||
| 141 | + if (obj == null || getClass() != obj.getClass()) { | ||
| 142 | + return false; | ||
| 143 | + } | ||
| 144 | + final EncodableDiscreteResources other = (EncodableDiscreteResources) obj; | ||
| 145 | + return Objects.equals(this.parent, other.parent) | ||
| 146 | + && Objects.equals(this.values, other.values); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + @Override | ||
| 150 | + public String toString() { | ||
| 151 | + return MoreObjects.toStringHelper(this) | ||
| 152 | + .add("values", values()) | ||
| 153 | + .toString(); | ||
| 154 | + } | ||
| 128 | } | 155 | } | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.store.resource.impl; | 16 | package org.onosproject.store.resource.impl; |
| 17 | 17 | ||
| 18 | +import com.google.common.base.MoreObjects; | ||
| 18 | import com.google.common.collect.DiscreteDomain; | 19 | import com.google.common.collect.DiscreteDomain; |
| 19 | import com.google.common.collect.Range; | 20 | import com.google.common.collect.Range; |
| 20 | import com.google.common.collect.RangeSet; | 21 | import com.google.common.collect.RangeSet; |
| ... | @@ -26,6 +27,7 @@ import org.onosproject.net.resource.DiscreteResourceId; | ... | @@ -26,6 +27,7 @@ import org.onosproject.net.resource.DiscreteResourceId; |
| 26 | import org.onosproject.net.resource.Resources; | 27 | import org.onosproject.net.resource.Resources; |
| 27 | 28 | ||
| 28 | import java.util.LinkedHashSet; | 29 | import java.util.LinkedHashSet; |
| 30 | +import java.util.Objects; | ||
| 29 | import java.util.Set; | 31 | import java.util.Set; |
| 30 | import java.util.stream.Collectors; | 32 | import java.util.stream.Collectors; |
| 31 | import java.util.stream.IntStream; | 33 | import java.util.stream.IntStream; |
| ... | @@ -83,4 +85,30 @@ final class EncodedDiscreteResources { | ... | @@ -83,4 +85,30 @@ final class EncodedDiscreteResources { |
| 83 | boolean isEmpty() { | 85 | boolean isEmpty() { |
| 84 | return rangeSet.isEmpty(); | 86 | return rangeSet.isEmpty(); |
| 85 | } | 87 | } |
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public int hashCode() { | ||
| 91 | + return Objects.hash(rangeSet, codec); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public boolean equals(Object obj) { | ||
| 96 | + if (this == obj) { | ||
| 97 | + return true; | ||
| 98 | + } | ||
| 99 | + if (obj == null || getClass() != obj.getClass()) { | ||
| 100 | + return false; | ||
| 101 | + } | ||
| 102 | + final EncodedDiscreteResources other = (EncodedDiscreteResources) obj; | ||
| 103 | + return Objects.equals(this.rangeSet, other.rangeSet) | ||
| 104 | + && Objects.equals(this.codec, other.codec); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Override | ||
| 108 | + public String toString() { | ||
| 109 | + return MoreObjects.toStringHelper(this) | ||
| 110 | + .add("rangeSet", rangeSet) | ||
| 111 | + .add("codec", codec) | ||
| 112 | + .toString(); | ||
| 113 | + } | ||
| 86 | } | 114 | } | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.store.resource.impl; | 16 | package org.onosproject.store.resource.impl; |
| 17 | 17 | ||
| 18 | +import com.google.common.base.MoreObjects; | ||
| 18 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
| 19 | import org.onosproject.net.resource.DiscreteResource; | 20 | import org.onosproject.net.resource.DiscreteResource; |
| 20 | import org.onosproject.net.resource.DiscreteResourceId; | 21 | import org.onosproject.net.resource.DiscreteResourceId; |
| ... | @@ -22,6 +23,7 @@ import org.onosproject.net.resource.Resources; | ... | @@ -22,6 +23,7 @@ import org.onosproject.net.resource.Resources; |
| 22 | 23 | ||
| 23 | import java.util.LinkedHashSet; | 24 | import java.util.LinkedHashSet; |
| 24 | import java.util.Map; | 25 | import java.util.Map; |
| 26 | +import java.util.Objects; | ||
| 25 | import java.util.Optional; | 27 | import java.util.Optional; |
| 26 | import java.util.Set; | 28 | import java.util.Set; |
| 27 | import java.util.stream.Collectors; | 29 | import java.util.stream.Collectors; |
| ... | @@ -95,4 +97,29 @@ final class UnifiedDiscreteResources implements DiscreteResources { | ... | @@ -95,4 +97,29 @@ final class UnifiedDiscreteResources implements DiscreteResources { |
| 95 | return Stream.concat(encodables.values().stream(), generics.values().stream()) | 97 | return Stream.concat(encodables.values().stream(), generics.values().stream()) |
| 96 | .collect(Collectors.toCollection(LinkedHashSet::new)); | 98 | .collect(Collectors.toCollection(LinkedHashSet::new)); |
| 97 | } | 99 | } |
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public int hashCode() { | ||
| 103 | + return Objects.hash(generics, encodables); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public boolean equals(Object obj) { | ||
| 108 | + if (this == obj) { | ||
| 109 | + return true; | ||
| 110 | + } | ||
| 111 | + if (obj == null || getClass() != obj.getClass()) { | ||
| 112 | + return false; | ||
| 113 | + } | ||
| 114 | + final UnifiedDiscreteResources other = (UnifiedDiscreteResources) obj; | ||
| 115 | + return Objects.equals(this.generics, other.generics) | ||
| 116 | + && Objects.equals(this.encodables, other.encodables); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 120 | + public String toString() { | ||
| 121 | + return MoreObjects.toStringHelper(this) | ||
| 122 | + .add("values", values()) | ||
| 123 | + .toString(); | ||
| 124 | + } | ||
| 98 | } | 125 | } | ... | ... |
-
Please register or login to post a comment