You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (Jira)" <ji...@apache.org> on 2023/12/08 01:31:00 UTC

[jira] [Closed] (LANG-1639) Find enum using a predicate

     [ https://issues.apache.org/jira/browse/LANG-1639?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb closed LANG-1639.
----------------------
    Resolution: Won't Do

With the advent of Java8, it's possible to do this with not much code, for example:

Arrays.stream(enumClass.getEnumConstants()).filter(predicate).findFirst() [1]


[1] https://github.com/apache/commons-lang/pull/696#discussion_r1418285696

 

 

> Find enum using a predicate
> ---------------------------
>
>                 Key: LANG-1639
>                 URL: https://issues.apache.org/jira/browse/LANG-1639
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.enums.*
>            Reporter: Bernhard Bonigl
>            Priority: Major
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> `EnumUtils` supports finding an enum based on its name. However in my experience it's often required to find an enum mapped by another value related to the enum. To use a very simple example: Mapping a string input to an enum, where the string does not match the enum name.
> I propose adding a `getEnumByPredicate` method, that returns the first found enum value matching a given predicate. Could also be expanded to return a list of all matching values.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)