add hashCode to primitives
This commit is contained in:
parent
2e8e123ec4
commit
b0d8a072aa
@ -20,6 +20,9 @@ public final class BoolValue extends PrimitiveValue {
|
||||
return env.get(BOOL_PROTO);
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
return Boolean.hashCode(value);
|
||||
}
|
||||
@Override public boolean equals(Object other) {
|
||||
if (other == this) return true;
|
||||
else if (other instanceof BoolValue bool) return value == bool.value;
|
||||
|
@ -36,6 +36,9 @@ public final class StringValue extends PrimitiveValue {
|
||||
}
|
||||
@Override public String toString(Environment ext) { return value; }
|
||||
|
||||
@Override public int hashCode() {
|
||||
return value.hashCode();
|
||||
}
|
||||
@Override public boolean equals(Object other) {
|
||||
if (this == other) return true;
|
||||
else if (other instanceof StringValue val) return value.length() == val.value.length() && value.equals(val.value);
|
||||
|
@ -23,7 +23,8 @@ public final class VoidValue extends PrimitiveValue {
|
||||
@Override public ObjectValue getPrototype(Environment env) { return null; }
|
||||
|
||||
@Override public Member getOwnMember(Environment env, KeyCache key) {
|
||||
throw EngineException.ofError(String.format("Cannot read properties of %s (reading '%s')", name, key.toString(env)));
|
||||
if (key.isSymbol()) throw EngineException.ofError(String.format("Cannot read properties of %s (reading '%s')", name, key.toSymbol().toString()));
|
||||
else throw EngineException.ofError(String.format("Cannot read properties of %s (reading '%s')", name, key.toString(env)));
|
||||
}
|
||||
|
||||
@Override public List<String> toReadableLines(Environment env, HashSet<ObjectValue> passed) {
|
||||
|
@ -24,6 +24,9 @@ public final class DoubleValue extends NumberValue {
|
||||
|
||||
@Override public String toString() { return JSON.stringify(JSONElement.number(value)); }
|
||||
|
||||
@Override public int hashCode() {
|
||||
return Double.hashCode(value);
|
||||
}
|
||||
@Override public boolean equals(Object other) {
|
||||
if (this == other) return true;
|
||||
else if (other instanceof NumberValue val) return value == val.getDouble();
|
||||
|
@ -26,6 +26,9 @@ public final class IntValue extends NumberValue {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override public int hashCode() {
|
||||
return Long.hashCode(value);
|
||||
}
|
||||
@Override public String toString() { return value + ""; }
|
||||
@Override public boolean equals(Object other) {
|
||||
if (this == other) return true;
|
||||
|
Loading…
Reference in New Issue
Block a user