Value class does not correctly implement equals
As the value in the Value
class can be Object
for
initialValueMeasured
initialValueOrdered
measured
ordered
defaultValueMeasured
and an Object
can also be an array like int[]
for a ODS sequence, the equals
method MUST use Object.deepEquals
to compare thoses values.
Can be tested with a test added to ValueTypeTest
@org.junit.Test
public void testEqualsIntegerSequence() {
int[] ints = new int[] { 1, 2, 3 };
Value first = ValueType.INTEGER_SEQUENCE.create("Ids", ints);
Value second = ValueType.INTEGER_SEQUENCE.create("Ids", ints);
assertThat(first).isEqualTo(second);
}
This test fails with out a fix.
A fix would most probably be and updated equals
method in the Value
class.
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof Value)) {
return false;
}
Value val = (Value) other;
return Objects.equals(this.valueType, val.valueType) && Objects.equals(this.name, val.name)
&& Objects.equals(this.unit, val.unit)
&& Objects.equals(this.initialValidMeasured, val.initialValidMeasured)
&& Objects.deepEquals(this.validMeasured, val.validMeasured)
&& Objects.equals(this.validOrdered, val.validOrdered)
&& Objects.deepEquals(this.measured, val.measured) && Objects.deepEquals(this.ordered, val.ordered)
&& Objects.equals(this.valueClass, val.valueClass)
&& Objects.deepEquals(this.initialValueMeasured, val.initialValueMeasured)
&& Objects.equals(this.initialValidOrdered, val.initialValidOrdered)
&& Objects.deepEquals(this.initialValueOrdered, val.initialValueOrdered)
&& Objects.equals(this.enumerationName, val.enumerationName)
&& Objects.deepEquals(this.defaultValueMeasured, val.defaultValueMeasured);
}