Skip to content

.equals methods for collection-like elements #50

Description

@mjacoby

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.

Metadata

Metadata

Assignees

Labels

V.1.1.0Final Release V.1.1.0 incl. additional featuresblockedAwaiting feedback from IDTA or AAS Specs WG so that we can proceedbugSomething isn't working

Type

No type

Projects

Status
📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions