Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

Commit 4fc83dd

Browse files
authored
[ggj][engx] fix: add hashCode() and equals() to Field (#622)
* fix: fix dep ordering in Bazel dedupe rules * feat: add a basic trie * fix: add hashCode() and equals() to Field
1 parent 31a888e commit 4fc83dd

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

  • src/main/java/com/google/api/generator/gapic/model

src/main/java/com/google/api/generator/gapic/model/Field.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.api.generator.engine.ast.TypeNode;
1818
import com.google.auto.value.AutoValue;
19+
import java.util.Objects;
1920
import javax.annotation.Nullable;
2021

2122
@AutoValue
@@ -48,6 +49,37 @@ public boolean hasResourceReference() {
4849
return type().equals(TypeNode.STRING) && resourceReference() != null;
4950
}
5051

52+
@Override
53+
public boolean equals(Object o) {
54+
if (!(o instanceof Field)) {
55+
return false;
56+
}
57+
58+
Field other = (Field) o;
59+
return name().equals(other.name())
60+
&& type().equals(other.type())
61+
&& isMessage() == other.isMessage()
62+
&& isEnum() == other.isEnum()
63+
&& isRepeated() == other.isRepeated()
64+
&& isMap() == other.isMap()
65+
&& isContainedInOneof() == other.isContainedInOneof()
66+
&& Objects.equals(resourceReference(), other.resourceReference())
67+
&& Objects.equals(description(), other.description());
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
return 17 * name().hashCode()
73+
+ 19 * type().hashCode()
74+
+ (isMessage() ? 1 : 0) * 23
75+
+ (isEnum() ? 1 : 0) * 29
76+
+ (isRepeated() ? 1 : 0) * 31
77+
+ (isMap() ? 1 : 0) * 37
78+
+ (isContainedInOneof() ? 1 : 0) * 41
79+
+ (resourceReference() == null ? 0 : resourceReference().hashCode())
80+
+ (description() == null ? 0 : description().hashCode());
81+
}
82+
5183
public abstract Builder toBuilder();
5284

5385
public static Builder builder() {

0 commit comments

Comments
 (0)