From f418ab69a271ff60429e32f75389b2c62fe2674a Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Fri, 3 Apr 2009 21:24:38 +0000 Subject: [PATCH] Implementing hashcode and equals for JsonPrimitives as value type equality. --- .../java/com/google/gson/JsonPrimitive.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gson/src/main/java/com/google/gson/JsonPrimitive.java b/gson/src/main/java/com/google/gson/JsonPrimitive.java index 253814b4..e5e55680 100644 --- a/gson/src/main/java/com/google/gson/JsonPrimitive.java +++ b/gson/src/main/java/com/google/gson/JsonPrimitive.java @@ -330,4 +330,21 @@ public final class JsonPrimitive extends JsonElement { } return false; } + + @Override + public int hashCode() { + return (value == null) ? 31 : value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + JsonPrimitive other = (JsonPrimitive)obj; + if (value == null) { + if (other.value != null) return false; + } else if (!value.equals(other.value)) return false; + return true; + } }