static ValueConstraint @Nullable [] withConstraint(ValueConstraint[] constraints, int index, ValueConstraint constraint) {
    if (constraints[index] == constraint) return constraints;

    ValueConstraint negated = constraint.negate();
    if (negated != constraint && constraints[index] == negated) {
      return null;
    }

    ValueConstraint[] copy = constraints.clone();
    copy[index] = constraint;
    return copy;
  }
static ValueConstraint @Nullable [] withConstraint(ValueConstraint[] constraints, int index, ValueConstraint constraint)