You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Loic Guibert (JIRA)" <ji...@apache.org> on 2015/11/06 15:00:29 UTC

[jira] [Closed] (LANG-704) New methods for StringUtils class: equalsAny and equalsAnyIgnoreCase

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

Loic Guibert closed LANG-704.
-----------------------------
    Resolution: Duplicate

Resolved by https://issues.apache.org/jira/browse/LANG-1169.
Pull request #109 merged
https://github.com/apache/commons-lang/pull/109

> New methods for StringUtils class: equalsAny and equalsAnyIgnoreCase
> --------------------------------------------------------------------
>
>                 Key: LANG-704
>                 URL: https://issues.apache.org/jira/browse/LANG-704
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: N/A - it is a feature request.
>            Reporter: Rafal Glowinski
>            Priority: Minor
>              Labels: StringUtils
>             Fix For: Review Patch
>
>         Attachments: StringUtils.java.patch, StringUtilsTest.java.patch
>
>
> It would be very good if the StringUtils class provided 2 methods for testing String equality with more than one value at a time. 
> Methods could be written as follows:
> {code:title=StringUtils.java|borderStyle=solid}
>     /**
>      * Verifies if the tested string is equal with any of the provided strings.
>      * This method is null safe and case sensitive.
>      * 
>      * @param str Tested string
>      * @param any Strings to be tested against.
>      * @return true if tested string is equal to any of the provided strings. false otherwise.
>      */
>     public static boolean equalsWithAny(String str, String... any) {
>         if (str == null) {
>             return false;
>         }
>         
>         if (any == null) {
>             return false;
>         }
>         
>         for (String s : any) {
>             if (str.equals(s)) {
>                 return true;
>             }
>         }
>         
>         return false;
>     }
>     
>     /**
>      * Verifies if the tested string is equal with any of the provided strings.
>      * This method is null safe and case insensitive.
>      * 
>      * @param str Tested string
>      * @param any Strings to be tested against.
>      * @return true if tested string is equal to any of the provided strings. false otherwise.
>      */    
>     public static boolean equalsWithAnyIgnoreCase(String str, String... any) {
>         if (str == null) {
>             return false;
>         }
>         
>         if (any == null) {
>             return false;
>         }
>         
>         for (String s : any) {
>             if (str.equalsIgnoreCase(s)) {
>                 return true;
>             }
>         }
>         
>         return false;
>     }
> {code}



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