[ 
https://issues.apache.org/jira/browse/LANG-1495?focusedWorklogId=334719&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-334719
 ]

ASF GitHub Bot logged work on LANG-1495:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 28/Oct/19 02:58
            Start Date: 28/Oct/19 02:58
    Worklog Time Spent: 10m 
      Work Description: vlcheong commented on pull request #475: LANG-1495 
Update EnumUtils.java
URL: https://github.com/apache/commons-lang/pull/475
 
 
   Add Overloading Methods getEnum and getEnumIgnoreCase To EnumUtils
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 334719)
    Remaining Estimate: 0h
            Time Spent: 10m

> Add Overloading Methods To EnumUtils
> ------------------------------------
>
>                 Key: LANG-1495
>                 URL: https://issues.apache.org/jira/browse/LANG-1495
>             Project: Commons Lang
>          Issue Type: Improvement
>            Reporter: Cheong Voon Leong
>            Priority: Trivial
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> I would like to add 2 overloading methods to EnumUtils, getEnum and 
> getEnumIgnoreCase.
> Instead of returning null, if not found. In my opinion I think allowing user 
> to set a default result is a better approach or return an Optional.
>   
> {noformat}
> public static <E extends Enum<E>> E getEnum(final Class<E> enumClass, final 
> String enumName) {
>  return getEnum(enumClass, enumName, null);
>  }
> public static <E extends Enum<E>> E getEnum(final Class<E> enumClass, final 
> String enumName, E defaultEnum) {
>  if (enumName == null) {
>  return defaultEnum;
>  }
>  try {
>  return Enum.valueOf(enumClass, enumName);
>  } catch (final IllegalArgumentException ex) {
>  return defaultEnum;
>  }
>  }
> {noformat}
>   
>  
> {code:java}
> public static <E extends Enum<E>> E getEnumIgnoreCase(final Class<E> 
> enumClass, final String enumName) {
>  return getEnumIgnoreCase(enumClass, enumName, null);
>  }
> public static <E extends Enum<E>> E getEnumIgnoreCase(final Class<E> 
> enumClass, final String enumName, E defaultEnum) {
>  if (enumName == null || !enumClass.isEnum()) {
>  return defaultEnum;
>  }
>  for (final E each : enumClass.getEnumConstants()) {
>  if (each.name().equalsIgnoreCase(enumName)) {
>  return each;
>  }
>  }
>  return defaultEnum;
>  }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to