public class StringUtil
extends java.lang.Object
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
aliasCase(java.lang.String value)
This method converts a String into alias case.
|
static java.lang.String |
braceConcatenate(java.lang.String open,
java.lang.String join,
java.lang.String close,
java.lang.Object... clauses)
This method concatenates the given clauses separated by the given join string, prefixed with the given open string and post fixed with close string
|
static java.lang.String |
camelCase(java.lang.String value)
This method converts a String to camel case
Camel case has an upper case initial character for each word in the input string and separates the words with a single white space
|
static java.lang.String |
classCase(java.lang.String value)
This method converts a string to class case.
|
static java.lang.String |
concatenate(java.lang.String join,
java.lang.Object... clauses)
This method concatenates the given clauses separated by the given join.
|
static boolean |
containsChar(java.lang.String s,
char c)
This static method returns true if the given string contains the given char
|
static java.lang.String |
indexToString(int i)
This static method converts the given integer value in to a base26 string with a - z having values 0 - 25 respectively
|
static java.lang.String |
initialLowerCase(java.lang.String input)
This method returns the given String with a lower case initial character
|
static java.lang.String |
initialUpperCase(java.lang.String input)
The method returns the given String with its initial character in upper case
|
static boolean |
isSet(java.lang.String value)
This method checks whether the string is not null and has no white space charaters
|
static java.lang.String |
kebabCase(java.lang.String value)
This method converts a string to kebab case
Kebab case is all in lower case with words separated by a hyphen '-'
|
static java.lang.String |
lastChar(java.lang.String string)
This method returns the last character of a string
|
static java.lang.String |
nvl(java.lang.String checkValue,
java.lang.String valueIfNull)
This method converts null values
|
static java.lang.String |
plural(java.lang.String singular)
This method returns the plural of the given singular string
|
static java.lang.String |
random(int length)
This method generates a random String of the given length
|
static java.lang.String |
random(java.lang.Integer minLength,
java.lang.Integer maxLength,
java.lang.String saltChars)
This method returns a random String in the given length range from the given set of characters
|
static java.lang.String |
random(java.lang.Integer length,
java.lang.String saltChars)
This method generates a random String of the given length from the given set of characters
|
static java.lang.String |
random(int minLength,
int maxLength)
This method generates a String of within the length range specified
|
static void |
registerTypeConverter(TypeConverter<?,java.lang.String> converter)
This method registers with this static utility an instance of a String TypeConverter to convert an instance of the convertible class
into a String value
|
static java.lang.String |
replaceAll(java.lang.String input,
java.lang.String match,
java.lang.Object... replacements)
This method replaces each occurrence of the match string with the replacements in the given order.
|
static java.lang.String |
safeChars()
Get the set of safe characters
|
static void |
safeChars(java.lang.String newSafeChars)
Set the safe characters
|
static java.lang.String |
safeWord(java.lang.String word)
This method ensures that only safe characters exist in the word.
|
static java.lang.String |
saltChars()
Get the set of characters from which to build random strings
|
static void |
saltChars(java.lang.String newSaltChars)
Set the characters from which to build random strings
|
static java.lang.String |
splitCamelCase(java.lang.String camelCase)
This method splits the given camel case string into words
|
static java.lang.String |
staticCase(java.lang.String value)
This method converts a string to static case
Static case is all in upper case with words separated by a single underscore '_'
|
static int |
stringToIndex(java.lang.String index)
This static method converts the given string into an index value in a base26 manner with a - z having values 0 - 25 respectively
Non alpha numeric values are stripped from the string and it is converted to lower case
|
static java.lang.Boolean |
toBoolean(java.lang.String v)
This method converts the given string into a Boolean value
|
static java.util.Date |
toDate(java.lang.String v)
This method converts the given string into a Date value
|
static java.util.Date |
toDate(java.lang.String v,
DateUtil.DateFormat format)
This method converts the given string into a Date value
|
static java.util.Date |
toDate(java.lang.String v,
java.text.SimpleDateFormat formatter)
This method converts the given string into a Date value
|
static java.util.Date |
toDate(java.lang.String v,
java.lang.String format)
This method converts the given string into a Date value
|
static java.lang.Double |
toDouble(java.lang.String v)
This method converts the given string into a Double value
|
static java.lang.Float |
toFloat(java.lang.String v)
This method converts the given string into a Float value
|
static java.lang.Integer |
toInteger(java.lang.String v)
This method converts the given string into a Integer value
|
static java.lang.Long |
toLong(java.lang.String v)
This method converts the given string into a Long value
|
static java.lang.String |
toString(java.lang.Object v)
This method converts the given object into a String value
Static utility methods convert Strings, Integers, Longs, Floats, Doubles, Dates and Booleans into String values
If the given object is not one of the above types then a type converter must have been registered with this static utility
in order for the given object to be converted into a String value
If no type converter has been registered for the class of the given object then a null is returned
|
static java.lang.String |
toString(java.lang.String v)
This method converts the given string into a String value
|
static java.lang.String |
trim(javax.persistence.criteria.CriteriaBuilder.Trimspec trimSpec,
char trimChar,
java.lang.String s)
This static method trims the leading and/or trailing chars from the given string according to the given trim spec.
|
static java.lang.String |
verySafeChars()
Get the set of safe characters
|
static void |
verySafeChars(java.lang.String newVerySafeChars)
Set the very safe characters
|
static java.lang.String |
verySafeWord(java.lang.String word)
This method ensures that only safe characters exist in the word.
|
static java.lang.String[] |
words(java.lang.String value)
This method splits a String into words on any whitespace characters
|
public static java.lang.String saltChars()
public static void saltChars(java.lang.String newSaltChars)
newSaltChars
- The new set of characters from which to build random stringspublic static java.lang.String safeChars()
public static void safeChars(java.lang.String newSafeChars)
newSafeChars
- The new set of safe characterspublic static java.lang.String verySafeChars()
public static void verySafeChars(java.lang.String newVerySafeChars)
newVerySafeChars
- The new set of safe characterspublic static void registerTypeConverter(TypeConverter<?,java.lang.String> converter)
converter
- The String TypeConverter instancepublic static java.lang.String toString(java.lang.Object v)
v
- The object to convert into a String valuepublic static java.lang.Integer toInteger(java.lang.String v)
v
- The String to convertpublic static java.lang.Long toLong(java.lang.String v)
v
- The String to convertpublic static java.lang.Float toFloat(java.lang.String v)
v
- The String to convertpublic static java.lang.Double toDouble(java.lang.String v)
v
- The String to convertpublic static java.lang.Boolean toBoolean(java.lang.String v)
v
- The String to convertpublic static java.util.Date toDate(java.lang.String v)
v
- The String to convertpublic static java.util.Date toDate(java.lang.String v, DateUtil.DateFormat format)
v
- The String to convertformat
- The requested data formatpublic static java.util.Date toDate(java.lang.String v, java.text.SimpleDateFormat formatter)
v
- The String to convertformatter
- The date formatter to convert the Datepublic static java.util.Date toDate(java.lang.String v, java.lang.String format)
v
- The String to convertformat
- A String representing the format of the required datepublic static java.lang.String toString(java.lang.String v)
v
- The String to convertpublic static java.lang.String random(int length)
length
- The desired length of the random stringpublic static java.lang.String random(int minLength, int maxLength)
minLength
- The minimum length of the StringmaxLength
- The maximum length of the Stringpublic static java.lang.String random(java.lang.Integer length, java.lang.String saltChars)
length
- The desired length of the random stringsaltChars
- The set of characters from which to build the random Stringpublic static java.lang.String random(java.lang.Integer minLength, java.lang.Integer maxLength, java.lang.String saltChars)
minLength
- The minimum length of the stringmaxLength
- The maximum length of the stringsaltChars
- The set of characters from which to build the stringpublic static java.lang.String initialLowerCase(java.lang.String input)
input
- the Stringpublic static java.lang.String initialUpperCase(java.lang.String input)
input
- The Stringpublic static boolean isSet(java.lang.String value)
value
- The string to checkpublic static java.lang.String[] words(java.lang.String value)
value
- The string to split into wordspublic static java.lang.String safeWord(java.lang.String word)
word
- The word to make safepublic static java.lang.String verySafeWord(java.lang.String word)
word
- The word to make safepublic static java.lang.String aliasCase(java.lang.String value)
value
- The string to convert to alias casepublic static java.lang.String camelCase(java.lang.String value)
value
- The String to convert to Camel casepublic static java.lang.String classCase(java.lang.String value)
value
- The string to convert to class casepublic static java.lang.String staticCase(java.lang.String value)
value
- The string to convert to static casepublic static java.lang.String kebabCase(java.lang.String value)
value
- The string to convert to kebab casepublic static java.lang.String nvl(java.lang.String checkValue, java.lang.String valueIfNull)
checkValue
- The value to check for nullvalueIfNull
- The value to return if the value to check is nullpublic static java.lang.String replaceAll(java.lang.String input, java.lang.String match, java.lang.Object... replacements)
input
- The string in which to replace the match stringsmatch
- The string to matchreplacements
- An array of objects with which to replace the match stringspublic static java.lang.String concatenate(java.lang.String join, java.lang.Object... clauses)
join
- The string to join the clauses togetherclauses
- An array of object clauses to concatenate togetherpublic static java.lang.String braceConcatenate(java.lang.String open, java.lang.String join, java.lang.String close, java.lang.Object... clauses)
open
- The opening string e.g '{'join
- The joining string e.g. ', 'close
- The closing string e.g. '}'clauses
- The objects to concatenate together using the result of StingUtil.toString(Object) to convert to a Stringpublic static java.lang.String lastChar(java.lang.String string)
string
- The string to testpublic static java.lang.String plural(java.lang.String singular)
singular
- The singular name for which the plural variant is requiredpublic static java.lang.String splitCamelCase(java.lang.String camelCase)
camelCase
- A string in camel casepublic static int stringToIndex(java.lang.String index)
index
- The string to convert to an index valuepublic static java.lang.String indexToString(int i)
i
- The integer value to convertpublic static java.lang.String trim(javax.persistence.criteria.CriteriaBuilder.Trimspec trimSpec, char trimChar, java.lang.String s)
trimSpec
- Whether to trim leading, trailing of bothtrimChar
- The character to trim from the strings
- The String to trimpublic static boolean containsChar(java.lang.String s, char c)
s
- The string to testc
- The char to search for