hashCodeCache = computeHashCode();
}
return hashCodeCache;
}
/**
* Computes a hash code consistent with equals(Object).
*
* <p>For commutative operations, the operand contribution must be order-independent because
* equals(Object) considers (left, right) equal to (right, left). For non-commutative
* operations, preserve the ordered hash.
*/
private int computeHashCode() {
if (isCommutative()) {
int leftHash = left.hashCode();
int rightHash = right.hashCode();
int first = Math.min(leftHash, rightHash);
int second = Math.max(leftHash, rightHash);
return Objects.hash(operationKind, first, second);
}
return Objects.hash(operationKind, left, right);
}
Originally posted by @Copilot in #1643