Package com.identity4j.util
Class StringUtil
- java.lang.Object
-
- com.identity4j.util.StringUtil
-
public final class StringUtil extends Object
Provides general purpose String utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcapitalisedToKey(String name)static StringcompactClasspathString(String classpathString)Compact a classpath string by replacing any occurence of the current working directory with '.'.static StringconvertByteToString(byte[] objectGuid)static booleanequals(Collection<String> asCollection, String[] values)Compare a collection of strings to an array of strings.static StringgetAfter(String value, String match)Returns the string within this string of the first occurrence after the first specified substring match e.g.static StringgetAfterLast(String value, String match)Returns the string within this string of the first occurrence after the last specified substring match e.g.static StringgetBefore(String value, String match)Returns the string within this string of the first occurrence before the first specified substring match e.g.static StringgetBeforeLast(String value, String match)Returns the string within this string of the first occurrence before the last specified substring match e.g.static StringgetFirstItemOrNull(List<String> items)static StringgetLastToken(String string, String lastToken)static StringgetURLFilename(URL url)static StringgetValue(String[] values)static booleanisArrayNullOrEmpty(String[] values)static booleanisNullOrEmpty(String value)Test if a string isnullif it is an empty string when trimmed.static booleanisNullOrEmptyOrFirstElementBlank(String[] values)static StringnonNull(String value)Return an empty string whennull, otherwise return the string.static String[]toArray(String value, char delimiter)Tokenize the supplied value, splitting it when the supplied delimiter is encountered.static String[]toDefaultArray(String value)Tokenize the supplied value, splitting it when the ! delimiter is encountered.static List<String>toDefaultList(String value)Tokenize the supplied value, splitting it when the ! delimiter is encountered.static StringtoDefaultString(String... values)static StringtoDefaultString(Collection<String> values)Convert a collection of string values into a bang (!) delimited string.static List<String>toList(String value, char delimiter)Tokenize the supplied value, splitting it when the supplied delimiter is encountered.static List<String>toList(String value, String delimiter)Splits a String separated by a delimiter into tokens and returns them in a List.static StringtoString(String delimiter, String... values)static StringtoString(Collection<String> values, String delimiter)Convert a collection of string values into a delimited string.static Stringtrim(String value)Return an empty string whennull, otherwise return the string.static StringtrimToLength(String text, int length)static StringupperCamelCase(String value)Convert a space separated string to upper camel case.
-
-
-
Method Detail
-
isNullOrEmpty
public static boolean isNullOrEmpty(String value)
Test if a string isnullif it is an empty string when trimmed.- Parameters:
value-- Returns:
- null or trimmed blank string
-
nonNull
public static String nonNull(String value)
Return an empty string whennull, otherwise return the string.- Parameters:
value-- Returns:
- string or empty string when
null
-
trim
public static String trim(String value)
Return an empty string whennull, otherwise return the string.- Parameters:
value-- Returns:
- string or empty string when
null
-
getBefore
public static String getBefore(String value, String match)
Returns the string within this string of the first occurrence before the first specified substring match e.g. supplying something@another.com would return something when a match of @ was supplied. If the match is not found the original supplied value is returned.- Parameters:
value-match-- Returns:
- the string before the supplied match or the original string if no match is found
-
getBeforeLast
public static String getBeforeLast(String value, String match)
Returns the string within this string of the first occurrence before the last specified substring match e.g. supplying something@another.com would return something when a match of @ was supplied. If the match is not found the original supplied value is returned.- Parameters:
value-match-- Returns:
- the string before the supplied match or the original string if no match is found
-
getAfterLast
public static String getAfterLast(String value, String match)
Returns the string within this string of the first occurrence after the last specified substring match e.g. supplying something@another.com would return another.com when a match of @ was supplied. If the match is not found the original supplied value is returned.- Parameters:
value-match-- Returns:
- the string after the supplied match or the original string if no match is found
-
getAfter
public static String getAfter(String value, String match)
Returns the string within this string of the first occurrence after the first specified substring match e.g. supplying something@another.com would return another.com when a match of @ was supplied. If the match is not found the original supplied value is returned.- Parameters:
value-match-- Returns:
- the string after the supplied match or the original string if no match is found
-
toDefaultArray
public static String[] toDefaultArray(String value)
Tokenize the supplied value, splitting it when the ! delimiter is encountered. Note that if the value is null, it does not throw an exception and instead returns an empty Array.- Parameters:
value- a string to be parsed- Returns:
- the array built from the delimited value
-
toArray
public static String[] toArray(String value, char delimiter)
Tokenize the supplied value, splitting it when the supplied delimiter is encountered. Note that if the value is null, it does not throw an exception and instead returns an empty Collection.- Parameters:
value- a string to be parseddelimiter- the delimiter- Returns:
- the collection built from the delimited value
-
toDefaultList
public static List<String> toDefaultList(String value)
Tokenize the supplied value, splitting it when the ! delimiter is encountered. Note that if the value is null, it does not throw an exception and instead returns an empty Collection.- Parameters:
value- a string to be parsed- Returns:
- the collection built from the delimited value
-
toList
public static List<String> toList(String value, char delimiter)
Tokenize the supplied value, splitting it when the supplied delimiter is encountered. Note that if the value is null, it does not throw an exception and instead returns an empty Collection.- Parameters:
value- a string to be parseddelimiter- the delimiter- Returns:
- the collection built from the delimited value
-
toDefaultString
public static String toDefaultString(Collection<String> values)
Convert a collection of string values into a bang (!) delimited string.- Parameters:
values-- Returns:
- bang separated string
-
toString
public static String toString(Collection<String> values, String delimiter)
Convert a collection of string values into a delimited string.- Parameters:
values-delimiter- delimiter string- Returns:
- delimited string
-
equals
public static boolean equals(Collection<String> asCollection, String[] values)
Compare a collection of strings to an array of strings.
-
convertByteToString
public static final String convertByteToString(byte[] objectGuid)
-
upperCamelCase
public static String upperCamelCase(String value)
Convert a space separated string to upper camel case.- Parameters:
value- value- Returns:
- upper camel cased string
-
compactClasspathString
public static String compactClasspathString(String classpathString)
Compact a classpath string by replacing any occurence of the current working directory with '.'. If any of the remaining paths contain the user homes directory, that will be replaced with a '~'.- Parameters:
text- text- Returns:
- replaced text
-
isArrayNullOrEmpty
public static boolean isArrayNullOrEmpty(String[] values)
-
isNullOrEmptyOrFirstElementBlank
public static boolean isNullOrEmptyOrFirstElementBlank(String[] values)
-
-