[IgnoreCase] methods for ArrayUtils
-----------------------------------
Key: LANG-742
URL: https://issues.apache.org/jira/browse/LANG-742
Project: Commons Lang
Issue Type: New Feature
Components: lang.*
Reporter: Michael Lyons
Priority: Minor
This is a proposal for a feature addition.
On several projects, I've needed to perform case insensitive manipulation on
Arrays of Strings. My original need was just a solution for
containsIgnoreCase(String[], String) and indexOfIgnoreCase(String[], String).
In an effort to keep things simple, I created this class which implements 8
[IgnoreCase] methods that could be a benefit to Commons Lang users.
StringArrayUtils extends ArrayUtils, it provides case insensitive manipulation
on an Array of Strings.
The new methods provided in the class are:
containsIgnoreCase(String[] array, String stringToFind)
indexOfIgnoreCase(String[] array, String stringToFind)
indexOfIgnoreCase(String[] array, String stringToFind, int startIndex)
isEqualsIgnoreCase(String[] array1, String[] array2)
lastIndexOfIgnoreCase(String[] array, String stringToFind)
lastIndexOfIgnoreCase(String[] array, String stringToFind, int startIndex)
removeElementIgnoreCase(String[] array, String element)
removeElementsIgnoreCase(String[] array, String... values)
These eight methods cover the functional pattern provided in ArrayUtils. Any
comparison in ArrayUtils based on obj1.equals(obj2) now has an equivalent
str1.equalsIgnoreCase(str2) in StringArrayUtils.
I've included a test case and have made efforts to match your coding convention
and style. Thanks in advance for your time and consideration. I'd be happy to
follow up with any changes or edits if you think this is something that might
be included in a future version of Commons Lang.
...Mike
Ps. I understand that handling a special case for the String's
equalsIgnoreCase(...) may be a slippery slope - which has been intentionally
avoided. I have also considered overloading the above eight methods with a
Comparator parameter, but requiring a user to pass in a not-null,
case-insensitive comparator didn't seem as straight forward as the above
solution.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira