[
https://issues.apache.org/jira/browse/LANG-1666?focusedWorklogId=641103&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-641103
]
ASF GitHub Bot logged work on LANG-1666:
----------------------------------------
Author: ASF GitHub Bot
Created on: 24/Aug/21 13:58
Start Date: 24/Aug/21 13:58
Worklog Time Spent: 10m
Work Description: garydgregory commented on a change in pull request #782:
URL: https://github.com/apache/commons-lang/pull/782#discussion_r694877354
##########
File path: src/main/java/org/apache/commons/lang3/ObjectUtils.java
##########
@@ -634,6 +634,35 @@ public static boolean equals(final Object object1, final
Object object2) {
return object1.equals(object2);
}
+ /**
+ * <p>Compares given {@code object} to a vararg of {@code
searchObjects}</p>
+ *
+ * <pre>
+ * ObjectUtils.equalsAny(null) = false
+ * ObjectUtils.equalsAny(null, null, null) = true
+ * ObjectUtils.equalsAny("", "") = true
+ * ObjectUtils.equalsAny(Boolean.TRUE, null) = false
+ * ObjectUtils.equalsAny(Boolean.TRUE, "true") = false
+ * ObjectUtils.equalsAny(Boolean.TRUE, Boolean.TRUE) = true
+ * ObjectUtils.equalsAny(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE) = true
+ * </pre>
+ *
+ * @param object to compare, may be {@code null}
+ * @param searchObjects a vararg of objects, may be {@code null}.
+ * @return {@code true} if {@code object} is equal to any of the {@code
searchObjects}.
+ */
+ public static boolean equalsAny(final Object object, final Object...
searchObjects) {
+ if (ArrayUtils.isEmpty(searchObjects)) {
Review comment:
Or just `searchObjects== null ? false :
Stream.of(searchObjects).anyMatch(e -> Objects.equals(object, e));`
-1 anyway since this duplicated the functionality in
`ArrayUtils.contains(Object[], Object)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 641103)
Time Spent: 0.5h (was: 20m)
> Add ObjectUtils.equalsAny
> -------------------------
>
> Key: LANG-1666
> URL: https://issues.apache.org/jira/browse/LANG-1666
> Project: Commons Lang
> Issue Type: New Feature
> Reporter: Felix Hagemans
> Priority: Major
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> I think an {{equalsAny}} utility method would be a nice simple addition to
> the ObjectUtils class. For example:
> {code:java}if (valueA.equals(someObject.getSomeGetter()) ||
> valueB.equals(someObject.getSomeGetter()) { ... }{code}
> could be written a lot cleaner:
> {code:java}if (ObjectUtils.equalsAny(someObject.getSomeGetter(), valueA,
> valueB) { ... }{code}
> It would work similar to the already existing StringUtils.equalsAny method.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)