Add EnumUtils.equalsAny - #1278
Conversation
|
Similar to (null checks not included): EnumSet.of(searchEnums[0], searchEnums).contains(testEnum)This code would leverage the optimised EnumSet code for any Enum that has less than 64 members (as internally it uses bit flags in a long). |
|
How is this any different from If we do anything, I could see using a solution like @aherbert points out. The disadvantage is that it creates an new |
Using this approach results in longer, less readable code, as there is no vararg parameter. Also,
This is certainly an option, but it has two disadvantages:
|
|
What can I do to move this issue forward? |
|
Hello @mfg92
You need to gather positive consensus from the community, which I do not see ATM. |
| @SafeVarargs | ||
| public static <E> boolean equalsAny(E testEnum, E... searchEnums) { | ||
| if (ArrayUtils.isNotEmpty(searchEnums)) { | ||
| for (final E searchEnum : searchEnums) { |
There was a problem hiding this comment.
Hello,
I think it would be good to add a contains method in ArraysUtils the reuse it here, since you are basically doing a search in the array.
|
Hello @mfg92 @Test
public void testContainsAnyEnum() {
assertTrue(ArrayUtils.containsAny(ElementType.values(), ElementType.ANNOTATION_TYPE));
assertFalse(ArrayUtils.containsAny(ElementType.values(), (ElementType) null));
}? |
|
Closing: No reply in over 3 weeks. |
Added
EnumUtils.equalsAnysimilar toStringUtils.equalsAny. This can help to have shorter, easier to read code.Usage example:
If desired, I can also implement an
EnumUtils.equalsNone.