Skip to content

Conversation

@denvitaharen
Copy link
Contributor

@denvitaharen denvitaharen commented Dec 18, 2024

Many thanks for submitting your Pull Request ❤️!

Please make sure that your PR meets the following requirements:

  • You have read the contributors guide
  • Your code is properly formatted according to our code style
  • Pull Request title contains the target branch if not targeting main: [0.9.x] Subject
  • Pull Request contains link to the issue
  • Pull Request contains link to any dependent or related Pull Request
  • Pull Request contains description of the issue
  • Pull Request does not include fixes for issues other than the main ticket

I have added so equals and hashCode is generated to the models. It's possible to disabled it if someone doesn't want it.

@ricardozanini I created an new branch and pull request, it was easier and faster for me to do that.

The result looks like this:

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Animal model = (Animal) o;

        return Objects.equals(born, model.born) &&
        Objects.equals(deceased, model.deceased);
    }

    @Override
    public int hashCode() {
        return Objects.hash(born,
        deceased);
    }

@denvitaharen denvitaharen requested a review from a team as a code owner December 18, 2024 16:52
@denvitaharen
Copy link
Contributor Author

    /**
     * Compares this object to the specified object. The result is
     * {@code true} if and only if the argument is not
     * {@code null} and is a {@code Animal} object that
     * contains the same values as this object.
     *
     * @param   obj   the object to compare with.
     * @return  {@code true} if the objects are the same;
     *          {@code false} otherwise.
     **/
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;

        Animal model = (Animal) obj;

        return Objects.equals(born, model.born) &&
        Objects.equals(deceased, model.deceased);
    }

    /**
     * Returns a hash code for a {@code Animal}.
     *
     * @return a hash code value for a {@code Animal}.
     **/
    @Override
    public int hashCode() {
        return Objects.hash(born,
        deceased);
    }

I realized that I hadn't written any javadoc for the new methods, so I added it now. It took some inspiration from the String and Long javadoc and rewrote so it fits this in.

@mbard
Copy link

mbard commented Dec 19, 2024

Excellent, I really need equal/hashcode

Copy link
Member

@ricardozanini ricardozanini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@fjtirado fjtirado merged commit 6553a9e into quarkiverse:main Dec 23, 2024
7 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 23, 2024
…-client

Added so equals and hashcode is generated in models.
hbelmiro pushed a commit that referenced this pull request Dec 23, 2024
…-client

Added so equals and hashcode is generated in models.
@denvitaharen denvitaharen deleted the feature/add-equals-hashcode-client branch January 30, 2025 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants