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

Add TypedEqualsBuilder class and test #1114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Cousnouf
Copy link

@Cousnouf Cousnouf commented Sep 25, 2023

This class allows to have a more complete equals builder that takes in consideration the null and class comparison before the appended fields.
It makes the equals method more compact.

@ecki
Copy link

ecki commented Sep 27, 2023

Change looks quite good and complete. Not sure about the size, it might require a Apache contributor agreement. With this PR and Dev mail you probably don’t need an extra JIRA (or a committer can do that).

Do you have an contributors agreement on file, by any chance? https://www.apache.org/licenses/contributor-agreements.html

@garydgregory
Copy link
Member

Hello @Cousnouf
Please run mvn locally and fix issues before you push to avoid broken builds.

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

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

Needs discussion. See my comments. The main comment would be the: Why is this a new class? The class name and docs are confusing. I should not have to read a code example (thankfully in the Javadoc at least) to try to understand what this does. I may not be a native English speaker but this means nothing to me: "An extension of {@link EqualsBuilder} aimed to perform additionally the base objects and class equals checks."

import java.util.function.Function;

/**
* An extension of {@link EqualsBuilder} aimed to perform additionally the base objects and class equals checks.
Copy link
Member

Choose a reason for hiding this comment

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

Documentation needs a rework. I can't understand what this means.

}

@Override
boolean shouldLeaveEarly() {
Copy link
Member

Choose a reason for hiding this comment

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

Leave what early? This methods needs a better name IMO?

return sameReference || super.shouldLeaveEarly();
}

public TypedEqualsBuilder<T> append(Function<T, ?> extractor) {
Copy link
Member

Choose a reason for hiding this comment

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

What if I my function throws an exception? Should this use FailableFunction instead?

Copy link
Author

Choose a reason for hiding this comment

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

If the function throws a checked exception it can use FailableFunction, yes. I'll catch the Exception class (Throwable are meant to not be caught)

*
* @since 3.14.0
*/
public class TypedEqualsBuilder<T> extends EqualsBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

This is a confusing class name IMO. What is and where is the Type? It's not a Java Type or Class apparently...

Copy link

Choose a reason for hiding this comment

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

It is the class type. its refering to the T class parameter which is supported by this Builder subtype.

Copy link
Author

Choose a reason for hiding this comment

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

This equals builder is typed. We provide a type and then the field functions to build the equals method.
So the Type is a Java Class.

Copy link
Member

Choose a reason for hiding this comment

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

It is the class type. its refering to the T class parameter which is supported by this Builder subtype.

✅️ Thanks for pointing that out! 👍

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

I do not understand the point of this PR. Please file an issue in the JIRA and add documentation in this PR.

@@ -198,7 +198,7 @@ private static void unregister(final Object lhs, final Object rhs) {
* If the fields tested are equals.
Copy link
Contributor

Choose a reason for hiding this comment

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

equals --> equal

@@ -450,6 +450,15 @@ public static boolean reflectionEquals(final Object lhs, final Object rhs, final
.isEquals();
}

/**
* Indicates if an early append method leave should be done
Copy link
Contributor

Choose a reason for hiding this comment

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

unclear, rephrase

assertNotEquals(testObject1, testObject2);
assertNotEquals(testObject2, testObject1);

assertEquals(Boolean.TRUE,
Copy link
Contributor

Choose a reason for hiding this comment

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

probably use assertTrue and assertFalse, unless perhaps there's some auto-boxing detail I'm missing

Copy link
Author

@Cousnouf Cousnouf Sep 27, 2023

Choose a reason for hiding this comment

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

It was done to make the test slightly more quick to read with the syntax coloration.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, do not assume devs are using IDEs. E.g. right now I'm reading this code in Github, and it's less clear than assertTrue

Copy link
Author

Choose a reason for hiding this comment

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

GitHub has also syntax coloration. But yes let's change these asserts.

.isEquals());
}

static class TestObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

private

assertNotEquals(testObject1, testObject2);
assertNotEquals(testObject2, testObject1);

assertEquals(Boolean.TRUE,
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, do not assume devs are using IDEs. E.g. right now I'm reading this code in Github, and it's less clear than assertTrue

@Cousnouf
Copy link
Author

I've addressed the comments. This version may tend to something better :)

Add TypedEqualsBuilder class and test
@Cousnouf
Copy link
Author

Cousnouf commented Oct 2, 2023 via email

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

  1. This certainly requires a CLA
  2. There needs to be a JIRA and a clear proposal both for what problem is being solved, and how this proposal solves it.
  3. I might see what problem is being solved here — I'm not sure — but if so this is not the way to go about solving it and this is not the right API.

That is, please focus on documenting and getting agreement on the plan before writing any more code. As is, it's hard to fairly consider this since we don't understand it fully.

@@ -195,10 +195,10 @@ private static void unregister(final Object lhs, final Object rhs) {
}

/**
* If the fields tested are equals.
* If the fields tested are equal
Copy link
Contributor

Choose a reason for hiding this comment

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

missing punctuation, sentence fragment

* The default value is {@code true}.
*/
private boolean isEquals = true;
protected boolean isEquals = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

private please. Use getters/setters if needed

@@ -450,6 +450,15 @@ public static boolean reflectionEquals(final Object lhs, final Object rhs, final
.isEquals();
}

/**
* Indicates if we should interrupt the comparison during an appending.
Copy link
Contributor

Choose a reason for hiding this comment

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

third person, or second person if you must. Tech docs should never be second person plural

protected boolean interruptEqualityCheck() {
return !isEquals;
}

/**
* Tests if two {@code objects} by using reflection.
Copy link
Contributor

Choose a reason for hiding this comment

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

sentence fragment

import java.util.function.Function;

/**
* An extension of {@link EqualsBuilder} that is typed and meant to append field getter functions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a rewrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants