Implementing hashcode and equals for JsonPrimitives as value type equality.

This commit is contained in:
Inderjeet Singh 2009-04-03 21:24:38 +00:00
parent f9b1225581
commit f418ab69a2

View File

@ -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;
}
}