diff options
Diffstat (limited to 'java/src/main/java/com/google/protobuf/UnknownFieldSet.java')
-rw-r--r-- | java/src/main/java/com/google/protobuf/UnknownFieldSet.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/java/src/main/java/com/google/protobuf/UnknownFieldSet.java b/java/src/main/java/com/google/protobuf/UnknownFieldSet.java index 445951b0..77fef323 100644 --- a/java/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/java/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -34,6 +34,7 @@ import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.TreeMap; import java.util.List; @@ -85,6 +86,20 @@ public final class UnknownFieldSet { } private Map<Integer, Field> fields; + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + return (other instanceof UnknownFieldSet) && + this.fields.equals(((UnknownFieldSet) other).fields); + } + + @Override + public int hashCode() { + return this.fields.hashCode(); + } + /** Get a map of fields in the set by number. */ public Map<Integer, Field> asMap() { return fields; @@ -540,6 +555,36 @@ public final class UnknownFieldSet { */ public List<UnknownFieldSet> getGroupList() { return group; } + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Field)) { + return false; + } + return Arrays.equals(this.getIdentityArray(), + ((Field) other).getIdentityArray()); + } + + @Override + public int hashCode() { + return Arrays.hashCode(getIdentityArray()); + } + + /** + * Returns the array of objects to be used to uniquely identify this + * {@link UnknownFieldSet.Field} instance. + */ + private Object[] getIdentityArray() { + return new Object[] { + this.varint, + this.fixed32, + this.fixed64, + this.lengthDelimited, + this.group}; + } + /** * Serializes the field, including field number, and writes it to * {@code output}. |