Top Description Constructors Methods
org.apache.commons.lang3

public Class CharSetUtils

extends Object
Class Inheritance
Imports
org.apache.commons.lang3.stream.Streams

Operations on CharSet instances.

This class handles null input gracefully. An exception will not be thrown for a null input. Each method documents its behavior in more detail.

#ThreadSafe#

Since
1.0
See Also
CharSet

Constructor Summary

AccessConstructor and Description
public
CharSetUtils()
Deprecated TODO Make private in 4.0.

CharSetUtils instances should NOT be constructed in standard programming.

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

whether or not the characters in the set are in the primary string
containsAny
(final String
String to look for characters in, may be null
str
,
final String...
String[] set of characters to identify, may be null
set
)

Takes an argument in set-syntax, see evaluateSet, and identifies whether any of the characters are present in the specified string.

public static int

Returns:

the character count, zero if null string input
count
(final String
String to count characters in, may be null
str
,
final String...
String[] set of characters to count, may be null
set
)

Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string.

private static boolean

Returns:

whether or not the String is empty
deepEmpty
(final String[]
String[] whose elements are being checked for emptiness
strings
)

Determines whether or not all the Strings in an array are empty or not.

public static String

Returns:

the modified String, null if null string input
delete
(final String
String to delete characters from, may be null
str
,
final String...
String[] set of characters to delete, may be null
set
)

Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string.

public static String

Returns:

the modified String, null if null string input
keep
(final String
String to keep characters from, may be null
str
,
final String...
String[] set of characters to keep, may be null
set
)

Takes an argument in set-syntax, see evaluateSet, and keeps any of characters present in the specified string.

private static String

Returns:

the modified String, not null
modify
(final String
String to modify characters within
str
,
final String[]
String[] set of characters to modify
set
,
final boolean
whether to evaluate on match, or non-match
expect
)

Implements delete and keep.

public static String

Returns:

the modified String, null if null string input
squeeze
(final String
the string to squeeze, may be null
str
,
final String...
the character set to use for manipulation, may be null
set
)

Squeezes any repetitions of a character that is mentioned in the supplied set.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CharSetUtilsback to summary
public CharSetUtils()

Deprecated

TODO Make private in 4.0.

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.

Annotations
@Deprecated

Method Detail

containsAnyback to summary
public static boolean containsAny(final String str, final 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
Parameters
str:String

String to look for characters in, may be null

set:String[]

String[] set of characters to identify, may be null

Returns:boolean

whether or not the characters in the set are in the primary string

Since
3.2
See Also
{@link CharSet#getInstance(String...)} for set-syntax.
countback to summary
public static int count(final String str, final 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
Parameters
str:String

String to count characters in, may be null

set:String[]

String[] set of characters to count, may be null

Returns:int

the character count, zero if null string input

See Also
{@link CharSet#getInstance(String...)} for set-syntax.
deepEmptyback to summary
private static boolean deepEmpty(final String[] strings)

Determines whether or not all the Strings in an array are empty or not.

Parameters
strings:String[]

String[] whose elements are being checked for emptiness

Returns:boolean

whether or not the String is empty

deleteback to summary
public static String delete(final String str, final 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"
Parameters
str:String

String to delete characters from, may be null

set:String[]

String[] set of characters to delete, may be null

Returns:String

the modified String, null if null string input

See Also
{@link CharSet#getInstance(String...)} for set-syntax.
keepback to summary
public static String keep(final String str, final 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"
Parameters
str:String

String to keep characters from, may be null

set:String[]

String[] set of characters to keep, may be null

Returns:String

the modified String, null if null string input

Since
2.0
See Also
{@link CharSet#getInstance(String...)} for set-syntax.
modifyback to summary
private static String modify(final String str, final String[] set, final boolean expect)

Implements delete and keep.

Parameters
str:String

String to modify characters within

set:String[]

String[] set of characters to modify

expect:boolean

whether to evaluate on match, or non-match

Returns:String

the modified String, not null

squeezeback to summary
public static String squeeze(final String str, final 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"
Parameters
str:String

the string to squeeze, may be null

set:String[]

the character set to use for manipulation, may be null

Returns:String

the modified String, null if null string input

See Also
{@link CharSet#getInstance(String...)} for set-syntax.