diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/Pair.java b/runtime/Java/src/org/antlr/v4/runtime/misc/Pair.java index 4ff0c7ef6..aa8eda9b2 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/Pair.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/Pair.java @@ -38,4 +38,31 @@ public class Pair { this.a = a; this.b = b; } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + else if (!(obj instanceof Pair)) { + return false; + } + + Pair other = (Pair)obj; + return ObjectEqualityComparator.INSTANCE.equals(a, other.a) + && ObjectEqualityComparator.INSTANCE.equals(b, other.b); + } + + @Override + public int hashCode() { + int hash = MurmurHash.initialize(); + hash = MurmurHash.update(hash, a); + hash = MurmurHash.update(hash, b); + return MurmurHash.finish(hash, 2); + } + + @Override + public String toString() { + return String.format("(%s, %s)", a, b); + } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/Triple.java b/runtime/Java/src/org/antlr/v4/runtime/misc/Triple.java index f4ff63955..ad8c216df 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/Triple.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/Triple.java @@ -41,4 +41,32 @@ public class Triple { this.c = c; } + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + else if (!(obj instanceof Triple)) { + return false; + } + + Triple other = (Triple)obj; + return ObjectEqualityComparator.INSTANCE.equals(a, other.a) + && ObjectEqualityComparator.INSTANCE.equals(b, other.b) + && ObjectEqualityComparator.INSTANCE.equals(c, other.c); + } + + @Override + public int hashCode() { + int hash = MurmurHash.initialize(); + hash = MurmurHash.update(hash, a); + hash = MurmurHash.update(hash, b); + hash = MurmurHash.update(hash, c); + return MurmurHash.finish(hash, 3); + } + + @Override + public String toString() { + return String.format("(%s, %s, %s)", a, b, c); + } }