Allow subclass in equals in Default implementations#248
Open
mhrimaz wants to merge 4 commits into
Open
Conversation
Wrong hashCode logic Make equals logic generic Initialize List objects
Contributor
|
Is this still active? |
Author
|
@twebermartins probably the changes that I applied are on the codes generated automatically. So I assume the correct logic should be applied in the code generator. package org.eclipse.digitaltwin.aas4j.v3.model;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.CustomSubProperty;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty;
import org.junit.Test;
public class ModelTest {
void fillProperty(Property object) {
object.setIdShort("test");
object.setValueType(DataTypeDefXsd.STRING);
}
@Test
public void testPropertyEqualityWithSubclass() {
Property defaultProperty = new DefaultProperty();
Property customProperty = new CustomSubProperty();
fillProperty(customProperty);
fillProperty(defaultProperty);
//object should be equal to itself
assert defaultProperty.equals(defaultProperty);
//defaultProperty should be equal with customProperty
assert defaultProperty.equals(customProperty);
assert customProperty.equals(customProperty);
assert customProperty.equals(defaultProperty);
//hashCode implementation should be consistent
assert customProperty.hashCode() == defaultProperty.hashCode();
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current implementation of
equalsfunction is too restrict and does not allow comparing different subclasses of an entity to be comparable. This PR solves this. However, it does not solve the ordering of collections mentioned in #50Furthermore, the motivation behind allowing custom subclasses should be explained, and such implementation considerations should be explained.