public class CharSetUtils extends Object
Operations on CharSet
instances.
This class handles null
input gracefully.
An exception will not be thrown for a null
input.
Each method documents its behaviour in more detail.
#ThreadSafe#
CharSet
Constructor and Description |
---|
CharSetUtils()
CharSetUtils instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
containsAny(String str,
String... set)
Takes an argument in set-syntax, see evaluateSet,
and identifies whether any of the characters are present in the specified string.
|
static int |
count(String str,
String... set)
Takes an argument in set-syntax, see evaluateSet,
and returns the number of characters present in the specified string.
|
static String |
delete(String str,
String... set)
Takes an argument in set-syntax, see evaluateSet,
and deletes any of characters present in the specified string.
|
static String |
keep(String str,
String... set)
Takes an argument in set-syntax, see evaluateSet,
and keeps any of characters present in the specified string.
|
static String |
squeeze(String str,
String... set)
Squeezes any repetitions of a character that is mentioned in the
supplied set.
|
public CharSetUtils()
CharSetUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as CharSetUtils.evaluateSet(null);
.
This constructor is public to permit tools that require a JavaBean instance to operate.
public static String squeeze(String str, String... set)
Squeezes any repetitions of a character that is mentioned in the supplied set.
CharSetUtils.squeeze(null, *) = null CharSetUtils.squeeze("", *) = "" CharSetUtils.squeeze(*, null) = * CharSetUtils.squeeze(*, "") = * CharSetUtils.squeeze("hello", "k-p") = "helo" CharSetUtils.squeeze("hello", "a-e") = "hello"
str
- the string to squeeze, may be nullset
- the character set to use for manipulation, may be nullnull
if null string inputfor set-syntax.
public static boolean containsAny(String str, String... set)
Takes an argument in set-syntax, see evaluateSet, and identifies whether any of the characters are present in the specified string.
CharSetUtils.containsAny(null, *) = false CharSetUtils.containsAny("", *) = false CharSetUtils.containsAny(*, null) = false CharSetUtils.containsAny(*, "") = false CharSetUtils.containsAny("hello", "k-p") = true CharSetUtils.containsAny("hello", "a-d") = false
str
- String to look for characters in, may be nullset
- String[] set of characters to identify, may be nullfor set-syntax.
public static int count(String str, String... set)
Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string.
CharSetUtils.count(null, *) = 0 CharSetUtils.count("", *) = 0 CharSetUtils.count(*, null) = 0 CharSetUtils.count(*, "") = 0 CharSetUtils.count("hello", "k-p") = 3 CharSetUtils.count("hello", "a-e") = 1
str
- String to count characters in, may be nullset
- String[] set of characters to count, may be nullfor set-syntax.
public static String keep(String str, String... set)
Takes an argument in set-syntax, see evaluateSet, and keeps any of characters present in the specified string.
CharSetUtils.keep(null, *) = null CharSetUtils.keep("", *) = "" CharSetUtils.keep(*, null) = "" CharSetUtils.keep(*, "") = "" CharSetUtils.keep("hello", "hl") = "hll" CharSetUtils.keep("hello", "le") = "ell"
str
- String to keep characters from, may be nullset
- String[] set of characters to keep, may be nullnull
if null string inputfor set-syntax.
public static String delete(String str, String... set)
Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string.
CharSetUtils.delete(null, *) = null CharSetUtils.delete("", *) = "" CharSetUtils.delete(*, null) = * CharSetUtils.delete(*, "") = * CharSetUtils.delete("hello", "hl") = "eo" CharSetUtils.delete("hello", "le") = "ho"
str
- String to delete characters from, may be nullset
- String[] set of characters to delete, may be nullnull
if null string inputfor set-syntax.
Copyright © 2001–2018 The Apache Software Foundation. All rights reserved.