-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: master
Are you sure you want to change the base?
Conversation
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 |
Hello @Cousnouf |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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! 👍
There was a problem hiding this 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
daa8c6e
to
602c964
Compare
I've addressed the comments. This version may tend to something better :) |
Add TypedEqualsBuilder class and test
602c964
to
d70d4c7
Compare
Hello all,
I've added some changes to address your comments.
It's still in a separate class as I think it's better to separate the
concept of EqualsBuilder with concrete values passed each time with append
and the concept of TypedEqualsBuilder which receive the two objects in the
construction and then calls the failable function during each appending.
Inputs welcome :)
Regards,
Marc
Le jeu. 28 sept. 2023 à 15:39, Gary Gregory ***@***.***> a
écrit :
… ***@***.**** commented on this pull request.
------------------------------
In src/main/java/org/apache/commons/lang3/builder/TypedEqualsBuilder.java
<#1114 (comment)>:
> + * <p>Typical use for the code is as follows:</p>
+ * <pre>
+ * public boolean equals(Object obj) {
+ * return new TypedEqualsBuilder<>(this)
+ * .appendBaseObject(obj)
+ * .append(TestObject::getA)
+ * .append(TestObject::getB)
+ * .isEquals();
+ * }
+ * </pre>
+ *
+ * @param <T> the type of the compared object.
+ *
+ * @SInCE 3.14.0
+ */
+public class TypedEqualsBuilder<T> extends EqualsBuilder {
It is the class type. its refering to the T class parameter which is
supported by this Builder subtype.
✅️ Thanks for pointing that out! 👍
—
Reply to this email directly, view it on GitHub
<#1114 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATRSC2QF3DIIJVO5GMIKO3X4V4ZLANCNFSM6AAAAAA5FT7FAY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This certainly requires a CLA
- There needs to be a JIRA and a clear proposal both for what problem is being solved, and how this proposal solves it.
- 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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a rewrite
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.