use of org.neo4j.values.Equality in project neo4j by neo4j.
the class MapValue method ternaryEquals.
@Override
public Equality ternaryEquals(AnyValue other) {
assert other != null : "null values are not supported, use NoValue.NO_VALUE instead";
if (other == NO_VALUE) {
return Equality.UNDEFINED;
} else if (!(other instanceof MapValue)) {
return Equality.FALSE;
}
MapValue otherMap = (MapValue) other;
int size = size();
if (size != otherMap.size()) {
return Equality.FALSE;
}
String[] thisKeys = StreamSupport.stream(keySet().spliterator(), false).toArray(String[]::new);
Arrays.sort(thisKeys, String::compareTo);
String[] thatKeys = StreamSupport.stream(otherMap.keySet().spliterator(), false).toArray(String[]::new);
Arrays.sort(thatKeys, String::compareTo);
for (int i = 0; i < size; i++) {
if (thisKeys[i].compareTo(thatKeys[i]) != 0) {
return Equality.FALSE;
}
}
Equality equalityResult = Equality.TRUE;
for (int i = 0; i < size; i++) {
String key = thisKeys[i];
AnyValue thisValue = get(key);
AnyValue otherValue = otherMap.get(key);
Equality equality = thisValue.ternaryEquals(otherValue);
if (equality == Equality.UNDEFINED) {
equalityResult = Equality.UNDEFINED;
} else if (equality == Equality.FALSE) {
return Equality.FALSE;
}
}
return equalityResult;
}