public class StringUtil
extends java.lang.Object
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
decapitalize(java.lang.String value)
Decapitalize the string by making sure the first character is lower-case.
|
static java.lang.String |
getCommonPrefix(java.util.Collection<java.lang.String> strings)
Find the longest common prefix for a collection of strings.
|
static boolean |
isEqualOrNull(java.lang.String s1,
java.lang.String s2)
Check if two strings are equal or both are null.
|
static boolean |
isEqualOrNull(java.lang.String s1,
java.lang.String s2,
boolean caseInsensitive)
Check if two strings are equal or both are null.
|
static java.lang.String |
join(java.util.Collection<?> values,
java.lang.String deliminator,
boolean skipNull)
Join a collection of values to a string, using the specified delimiator.
|
static java.lang.String |
setNotNullString(java.lang.String value,
java.lang.String name,
int maxLength)
Trim and check the length of a string.
|
static java.lang.String |
setNullableString(java.lang.String value,
java.lang.String name,
int maxLength)
Trim and check the length of a string.
|
static java.lang.String[] |
tokenize(java.lang.String s,
java.lang.String regexp,
boolean notInsideQuotes)
Tokenize a string by splitting it at positions matching the
regular expression, optionally ignoring matches that are inside
quotes.
|
static java.lang.String[] |
tokenize(java.lang.String s,
java.lang.String regexp,
boolean notInsideQuotes,
boolean removeQuotes)
Tokenize a string by splitting it at positions matching the
regular expression.
|
static java.lang.String |
trimString(java.lang.String s,
int length)
Trim a string to a maximum length.
|
static java.lang.String |
trimStringMiddle(java.lang.String s,
int length)
Trim a string to a maximum length.
|
public static java.lang.String setNullableString(java.lang.String value, java.lang.String name, int maxLength) throws StringTooLongException
value
- The string to checkname
- The name of the attribute to use if an exception is thrownmaxLength
- The maximum length of the stringStringTooLongException
- If the string is too longpublic static java.lang.String setNotNullString(java.lang.String value, java.lang.String name, int maxLength) throws InvalidUseOfNullException, StringTooLongException
value
- The string to checkname
- The name of the attribute to use if an exception is thrownmaxLength
- The maximum length of the stringStringTooLongException
- If the string is too longInvalidUseOfNullException
- If the string is nullpublic static boolean isEqualOrNull(java.lang.String s1, java.lang.String s2)
s1
- The first strings2
- The second stringpublic static boolean isEqualOrNull(java.lang.String s1, java.lang.String s2, boolean caseInsensitive)
s1
- The first strings2
- The second stringcaseInsensitive
- TRUE if the comparison should ignore case, FALSE
otherwisepublic static final java.lang.String join(java.util.Collection<?> values, java.lang.String deliminator, boolean skipNull)
values
- The values to joindeliminator
- The deliminator between the valuesskipNull
- If null values should be skipper or notpublic static final java.lang.String trimString(java.lang.String s, int length)
s
- The string to trimlength
- The maximum length of the stringpublic static final java.lang.String trimStringMiddle(java.lang.String s, int length)
s
- The string to trimlength
- The maximum length of the stringpublic static final java.lang.String[] tokenize(java.lang.String s, java.lang.String regexp, boolean notInsideQuotes)
s
- The string to tokenizeregexp
- The regular expression for matching split sitesnotInsideQuotes
- If TRUE, the regexp is not matched inside quotespublic static final java.lang.String[] tokenize(java.lang.String s, java.lang.String regexp, boolean notInsideQuotes, boolean removeQuotes)
s
- The string to tokenizeregexp
- The regular expression for matching split sitesnotInsideQuotes
- If TRUE, the regexp is not matched inside quotesremoveQuotes
- If TRUE, remove quotes from all elements before returning the
resultpublic static final java.lang.String getCommonPrefix(java.util.Collection<java.lang.String> strings)
strings
- A collection of string objectsString.startsWith(String)
returns true for all strings in the given collectionpublic static final java.lang.String decapitalize(java.lang.String value)