Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow subclass in equals in Default implementations #248

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mhrimaz
Copy link

@mhrimaz mhrimaz commented Feb 11, 2024

The current implementation of equals function 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 #50

Furthermore, the motivation behind allowing custom subclasses should be explained, and such implementation considerations should be explained.

@twebermartins twebermartins added the V.1.1.0 Final Release V.1.1.0 incl. additional features label Feb 13, 2024
@twebermartins
Copy link
Contributor

twebermartins commented Nov 19, 2024

Is this still active?

@mhrimaz
Copy link
Author

mhrimaz commented Nov 19, 2024

@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.
In any case the issue still remains, but it is not something critical. You can see here an example test case:
https://github.com/eclipse-aas4j/aas4j/blob/fefa728bae84d8686c08af2553ca4f2cd6ee9cfd/dataformat-core/src/test/java/org/eclipse/digitaltwin/aas4j/v3/model/ModelTest.java

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();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V.1.1.0 Final Release V.1.1.0 incl. additional features
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

2 participants