Refactor StringUtils#endsWithAny()
- Refactor to use Strings - Gains a case-insensitive implementation
This commit is contained in:
parent
317b364347
commit
e4c03c5e38
|
@ -1711,17 +1711,11 @@ public class StringUtils {
|
|||
* @return {@code true} if the input {@code sequence} is {@code null} AND no {@code searchStrings} are provided, or
|
||||
* the input {@code sequence} ends in any of the provided case-sensitive {@code searchStrings}.
|
||||
* @since 3.0
|
||||
* @deprecated Use {@link Strings#endsWithAny(CharSequence, CharSequence...) Strings.CS.endsWithAny(CharSequence, CharSequence...)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean endsWithAny(final CharSequence sequence, final CharSequence... searchStrings) {
|
||||
if (isEmpty(sequence) || ArrayUtils.isEmpty(searchStrings)) {
|
||||
return false;
|
||||
}
|
||||
for (final CharSequence searchString : searchStrings) {
|
||||
if (Strings.CS.endsWith(sequence, searchString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return Strings.CS.endsWithAny(sequence, searchStrings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -597,6 +597,42 @@ public abstract class Strings {
|
|||
return CharSequenceUtils.regionMatches(str, ignoreCase, str.length() - sufLen, suffix, 0, sufLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a CharSequence ends with any of the provided case-sensitive suffixes.
|
||||
*
|
||||
* <p>
|
||||
* Case-sensitive examples
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.endsWithAny(null, null) = false
|
||||
* StringUtils.endsWithAny(null, new String[] {"abc"}) = false
|
||||
* StringUtils.endsWithAny("abcxyz", null) = false
|
||||
* StringUtils.endsWithAny("abcxyz", new String[] {""}) = true
|
||||
* StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}) = true
|
||||
* StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
|
||||
* StringUtils.endsWithAny("abcXYZ", "def", "XYZ") = true
|
||||
* StringUtils.endsWithAny("abcXYZ", "def", "xyz") = false
|
||||
* </pre>
|
||||
*
|
||||
* @param sequence the CharSequence to check, may be null
|
||||
* @param searchStrings the case-sensitive CharSequences to find, may be empty or contain {@code null}
|
||||
* @see StringUtils#endsWith(CharSequence, CharSequence)
|
||||
* @return {@code true} if the input {@code sequence} is {@code null} AND no {@code searchStrings} are provided, or the input {@code sequence} ends in any
|
||||
* of the provided case-sensitive {@code searchStrings}.
|
||||
*/
|
||||
public boolean endsWithAny(final CharSequence sequence, final CharSequence... searchStrings) {
|
||||
if (StringUtils.isEmpty(sequence) || ArrayUtils.isEmpty(searchStrings)) {
|
||||
return false;
|
||||
}
|
||||
for (final CharSequence searchString : searchStrings) {
|
||||
if (endsWith(sequence, searchString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two CharSequences, returning {@code true} if they represent equal sequences of characters.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue