For some collection-like AAS type classes the equals method does not work as expected, e.g.
Property property1 = new DefaultProperty.Builder()
.idShort("property1")
.build();
Property property2 = new DefaultProperty.Builder()
.idShort("property2")
.build();
SubmodelElementCollection smc1 = new DefaultSubmodelElementCollection.Builder()
.value(List.of(property1, property2))
.build();
SubmodelElementCollection smc2 = new DefaultSubmodelElementCollection.Builder()
.value(List.of(property2, property1))
.build();
// expected: true, actual: false
boolean equals = Objects.equals(smc1, smc2);
returns false although SubmodelElementCollection is defined to not be ordered. Same goes for Submodel class.
For SubmodelElementList this issue is more complex as it has the ordered property.
Property property1 = new DefaultProperty.Builder()
.idShort("property1")
.build();
Property property2 = new DefaultProperty.Builder()
.idShort("property2")
.build();
SubmodelElementList smc1 = new DefaultSubmodelElementList.Builder()
.value(List.of(property1, property2))
.build();
SubmodelElementList smc2 = new DefaultSubmodelElementList.Builder()
.value(List.of(property2, property1))
.build();
smc1.setOrderRelevant(false);
smc2.setOrderRelevant(false);
// expected: true, actual: false
boolean equalsWithoutOrder = Objects.equals(smc1, smc2);
smc1.setOrderRelevant(true);
// expected: false, actual: false
boolean equalsWithOrderOneElement = Objects.equals(smc1, smc2);
smc2.setOrderRelevant(true);
// expected: false, actual: false
boolean equalsWithOrder = Objects.equals(smc1, smc2);
All .equals calls return false in this example, whereas equalsWithoutOrder should be true as order should be ignored.
This behavior is not compliant with the current specification.
However, there is a discussion if the specification should be updated to ensure order in such collections (admin-shell-io/aas-specs-metamodel#248).
Before any release we should make sure that we are compliant to the specification.
For some collection-like AAS type classes the
equalsmethod does not work as expected, e.g.returns false although
SubmodelElementCollectionis defined to not be ordered. Same goes forSubmodelclass.For
SubmodelElementListthis issue is more complex as it has theorderedproperty.All
.equalscalls return false in this example, whereasequalsWithoutOrdershould be true as order should be ignored.This behavior is not compliant with the current specification.
However, there is a discussion if the specification should be updated to ensure order in such collections (admin-shell-io/aas-specs-metamodel#248).
Before any release we should make sure that we are compliant to the specification.