commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephan Knitelius (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-974) New StringUtils Method defaulfNotIn(String, String, List<String>)
Date Thu, 16 Oct 2014 08:46:34 GMT

    [ https://issues.apache.org/jira/browse/LANG-974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14173540#comment-14173540
] 

Stephan Knitelius commented on LANG-974:
----------------------------------------

In our particular case we have a set of legal values and any other
value has to be defaulted to a standard value.

For example:

defaultIfNotIn("a","invalid","a","b") returns a
defaultIfNotIn("c","invalid","a","b") returns invalid




> New StringUtils Method defaulfNotIn(String, String, List<String>)
> -----------------------------------------------------------------
>
>                 Key: LANG-974
>                 URL: https://issues.apache.org/jira/browse/LANG-974
>             Project: Commons Lang
>          Issue Type: Wish
>          Components: lang.*
>    Affects Versions: 3.2.1
>            Reporter: Stephan Knitelius
>            Priority: Minor
>             Fix For: Review Patch
>
>
> Example use case:
> If a Method expects values that should only consist of a certain set such as "0" and
"1", and any Invalid String should be defaulted to "0".
> Possible Solution:
> {code}
>   public static String defaultIfNotIn(final String str, final String defaultString, String...
validStrings) {
>     if (str == null) {
>       return defaultString;
>     }
>     for (final String validString : validStrings) {
>       if (validString.equals(str)) {
>         return str;
>       }
>     }
>     return defaultString;
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message