Class GrouperUtilElSafe
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
string format of datesstatic final String
string format of datesstatic final String
format including minutes and seconds: yyyy/MM/dd HH:mm:ssstatic final String
format including minutes and seconds: yyyyMMdd HH:mm:ssstatic final int
The name says it all.static final String
The empty String""
.static final Object[]
An empty immutableObject
array.static final String[]
An empty immutableString
array.static final int
Represents a failed index search.static final String
static final int
special number when a number is not foundstatic final long
The number of bytes in a gigabyte.static final long
The number of bytes in a kilobyte.static final long
The number of bytes in a megabyte.static final String
string format of dates for file namesstatic final String
format on screen of config for milestone: yyyy/MM/dd HH:mm:ss.SSSstatic final String
format on screen of config for milestone: yyyyMMdd HH:mm:ss.SSS -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
abbreviate
(String str, int maxWidth) Abbreviates a String using ellipses.static String
abbreviate
(String str, int offset, int maxWidth) Abbreviates a String using ellipses.static <T> void
addIfNotThere
(Collection<T> list, Collection<T> listToAdd) add each element of listToAdd if it is not already in liststatic void
append
(StringBuilder result, String separatorIfResultNotEmpty, String stringToAppend) append and maybe put a separator in therestatic boolean
appendIfNotBlank
(StringBuilder result, Object theStringOrArrayOrList) if theString is not blank, apppend it to the result, and if appending,static boolean
appendIfNotBlank
(StringBuilder result, String prefix, Object theStringOrArrayOrList) if theString is not Blank, apppend it to the result, and if appending, add a prefix (if not null)static boolean
appendIfNotBlank
(StringBuilder result, String prefix, Object theStringOrArrayOrList, String suffix) if theString is not Blank, apppend it to the result, and if appending, add a prefix and suffix (if not null)static boolean
appendIfNotBlank
(StringBuilder result, String prefix, String prefixIfNotBlank, Object theStringOrArrayOrList, String suffix) if theString is not Blank, apppend it to the result, and if appending, add a prefix and suffix (if not null)static String
appendIfNotBlankString
(String string, String separator, String suffix) append a string to another string if both not blank, with separator.static boolean
appendIfNotEmpty
(StringBuilder result, Object theStringOrArrayOrList) if theString is not empty, apppend it to the result, and if appending,static boolean
appendIfNotEmpty
(StringBuilder result, String prefix, Object theStringOrArrayOrList) if theString is not empty, apppend it to the result, and if appending, add a prefix (if not null)static boolean
appendIfNotEmpty
(StringBuilder result, String prefix, Object theStringOrArrayOrList, String suffix) if theString is not empty, apppend it to the result, and if appending, add a prefix and suffix (if not null)static boolean
appendIfNotEmpty
(StringBuilder result, String prefix, String prefixIfNotEmpty, Object theStringOrArrayOrList, String suffix) if theString is not empty, apppend it to the result, and if appending, add a prefix and suffix (if not null)static String
appendPrefixIfStringNotBlank
(String prefix, String separator, String string) append a prefix to another string if both not blank.static String
return the arg after the argBefore, or null if not there, or exception if argBefore is not foundstatic <T> T
arrayPopOne
(T[] array) Return the zero element of the array, if it exists, null if the array is empty.static void
If false, throw an assertException, and give a reasonstatic <T> List<T>
batchList
(Collection<T> collection, int batchSize, int batchIndex) retrieve a batch by 0 index.static int
batchNumberOfBatches
(int count, int batchSize) Deprecated.use batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne)static int
batchNumberOfBatches
(int count, int batchSize, boolean haveAtLeastOne) If batching this is the number of batchesstatic int
batchNumberOfBatches
(Collection<?> collection, int batchSize) Deprecated.use batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne)static int
batchNumberOfBatches
(Collection<?> collection, int batchSize, boolean haveAtLeastOne) If batching this is the number of batches, will return at least 1static BigDecimal
bigDecimalObjectValue
(Object input) Convert an object to a byte, allow nullsstatic Boolean
booleanObjectValue
(Object object) get the Boolean value for an objectstatic boolean
booleanValue
(Object object) get the boolean value for an object, cant be null or blankstatic boolean
booleanValue
(Object object, boolean defaultBoolean) get the boolean value for an objectstatic String
byteCountToDisplaySize
(long size) Returns a human-readable version of the file size (original is in bytes).static Byte
byteObjectValue
(Object input) Convert an object to a byte, allow nullsstatic byte
convert an object to a bytestatic String
capitalize
(String str) Capitalizes a String changing the first letter to title case as perCharacter.toTitleCase(char)
.static String
capitalize
(String str, char... delimiters) Capitalizes all the delimiter separated words in a String.static String
capitalizeFully
(String str) Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.static String
capitalizeFully
(String str, char... delimiters) Converts all the delimiter separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.static boolean
characterMatchesRegex
(Character character, String regex) static Character
charObjectValue
(Object input) get the Character wrapper value for the inputstatic char
convert an object to a charstatic String
classesString
(Object object) print the simple names of a list of classesstatic String
null safe classname method, gets the unenhanced namestatic String
classNameCollection
(Object object) null safe classname method, max out at 20static boolean
collectionContains
(Collection<Object> collection, Object object) static <T> T
collectionPopOne
(Collection<T> collection, boolean exceptionIfMoreThanOne) Return the zero element of the list, if it exists, null if the list is empty.static String
collectionToString
(Collection collection) convert a set to a string (comma separate)static int
compare
(Comparable first, Comparable second) compare null safestatic String
concat two stringsstatic String
concat stringsstatic String
concat stringsstatic String
concat stringsstatic boolean
Checks if the object is in the given array.static boolean
Checks if String contains a search character, handlingnull
.static boolean
Checks if String contains a search String, handlingnull
.static String
convertLongToChar
(long theLong) this method takes a long (less than 62) and converts it to a 1 character string (a-z, A-Z, 0-9)static String
convertLongToCharSmall
(long theLong) this method takes a long (less than 36) and converts it to a 1 character string (A-Z, 0-9)static String
convertLongToString
(long theLong) convert a long to a string by converting it to base 62 (26 lower, 26 upper, 10 digits)static String
convertLongToStringSmall
(long theLong) convert a long to a string by converting it to base 36 (26 upper, 10 digits)static String
convertMillisToFriendlyString
(Integer duration) convert millis to friendly stringstatic String
convertMillisToFriendlyString
(Long duration) convert millis to friendly stringstatic Long
dateLongValue
(String date) convert a string date into a long date (e.g.static String
dateStringValue
(Long theDate) date object to a string:static String
dateStringValue
(Date date) date object to a string:static String
dateToString
(Date date) convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23static Date
Convert an object to a java.util.Date.static String
defaultIfBlank
(String string, String defaultStringIfBlank) return the string or the other if the first is blankstatic String
defaultIfEmpty
(String str, String defaultStr) Returns either the passed in String, or if the String is empty ornull
, the value ofdefaultStr
.static <T> T
defaultIfNull
(T theValue, T defaultIfTheValueIsNull) genericized method to see if first is null, if so then return second, else first.static String
defaultString
(String str) Returns either the passed in String, or if the String isnull
, an empty String ("").static String
defaultString
(String str, String defaultStr) Returns either the passed in String, or if the String isnull
, the value ofdefaultStr
.static Double
doubleObjectValue
(Object input, boolean allowNullBlank) get the Double value of an objectstatic double
doubleValue
(Object input) get the double value of an objectstatic double
doubleValueNoError
(Object input) get the double value of an object, do not throw an exception if there is an errorstatic String
encryptSha
(String plaintext) encrypt a message to SHAstatic boolean
Compares two objects for equality, where either one or both objects may benull
.static boolean
null safe string comparestatic boolean
equalsIgnoreCase
(String str1, String str2) equalsignorecasestatic String
escapeUrlDecode
(String string) unescape url chars (e.g.static String
escapeUrlEncode
(String string) escape url chars (e.g.static String
extensionFromName
(String name) get the extension from name.static Float
floatObjectValue
(Object input, boolean allowNullBlank) get the Float value of an objectstatic float
floatValue
(Object input) get the float value of an objectstatic float
floatValueNoError
(Object input) get the float value of an object, do not throw an exception if there is an errorstatic String
formatNumberWithCommas
(Long number) static Object
Get a specific index of an array or collection (note for collections and iterating, it is more efficient to get an iterator and iteratestatic Throwable
Introspects theThrowable
to obtain the cause.static Throwable
Introspects theThrowable
to obtain the cause.static Stem
Returns the first existing parent stem of a given name.static String
Return a string that combines the standard and daylight timezones of the server into one string separated by a slash that can be used in an input description to inform the user of the server timezone.static String
getFullStackTrace
(Throwable throwable) A way to get the entire nested stack-trace of an throwable.static Long
getMaxLongValue
(Long... values) static Long
getMinLongValue
(Long... values) static Throwable[]
getThrowables
(Throwable throwable) Returns the list ofThrowable
objects in the exception chain.static String
hostname()
Hostname of serverstatic char
incrementChar
(char theChar) increment a character (A-Z then 0-9)static char[]
incrementStringInt
(char[] string) Increment a string with A-Z and 0-9 (no lower case so case insensitive apps like windows IE will still work)static String
this method will indent xml or json.static int
Find the index of the given object in the array.static int
Find the index of the given object in the array starting at the given index.static Integer
intObjectValue
(Object input, boolean allowNullBlank) get the Integer value of an objectstatic int
convert an object to a intstatic int
convert an object to a intstatic int
intValueNoError
(Object input) get the int value of an object, do not throw an exception if there is an errorstatic int
get the ip addres integer from a string ip addressstatic boolean
ipOnNetwork
(String ipString, String networkIpString, int mask) see if an ip address is on a networkstatic boolean
ipOnNetworks
(String ipString, String networkIpStrings) see if an ip address is on a networkstatic int
ipReadyForAnd
(int ip, int maskLength) get the ip address after putting 1's where the subnet mask is notstatic boolean
isAscii
(char input) is ascii charstatic boolean
See if the input is null or if string, if it is empty or blank (whitespace)static boolean
Checks if a String is whitespace, empty ("") or null.static boolean
Checks if a String is empty ("") or null.static boolean
isNestedThrowable
(Throwable throwable) Checks whether thisThrowable
class can store a cause.static boolean
isNotBlank
(String str) static boolean
see if a class is a scalar (not bean, not array or list, etc)static boolean
Checks if the Throwable class has agetCause
method.static Iterator
null safe iterator getter if the type if collectionstatic String
Joins the elements of the provided array into a single String containing the provided list of elements.static String
Joins the elements of the provided array into a single String containing the provided list of elements.static String
Joins the elements of the provided array into a single String containing the provided list of elements.static String
Joins the elements of the providedIterator
into a single String containing the provided elements.static String
Joins the elements of the providedIterator
into a single String containing the provided elements.static String
Left pad a String with spaces (' ').static String
Left pad a String with a specified character.static String
Left pad a String with a specified String.static int
Null safe array length or mapstatic int
lengthAscii
(String input) find the length of ascii chars (non ascii are counted as two)static <T> T
listPopOne
(List<T> list) Return the zero element of the list, if it exists, null if the list is empty.static Long
longObjectValue
(Object input, boolean allowNullBlank) get the Long value of an objectstatic long
convert an object to a longstatic long
convert an object to a longstatic long
longValueNoError
(Object input) get the long value of an object, do not throw an exception if there is an errorstatic String
mapToString
(Map map) convert a set to a string (comma separate)static String
MapToString
(Map map) Deprecated.use mapToString(map)static int
convert a month string to an int (1 indexed).static Object
If array, get the element based on index, if Collection, get it based on iterator.static <T> Collection<T>
nonNull
(Collection<T> list) make sure a collection is non null.static <T> List<T>
make sure a list is non null.static <K,
V> Map<K, V> make sure it is non null, if null, then give new mapstatic <T> Set<T>
make sure a list is non null.static <T> T[]
make sure a array is non null.static String
take out accented chars with grouperUtil.normalize("NFD", groupAttribute).replaceAll("\\p{M}", "")static String
normalizeEmailAddresses
(String emailAddresses) take email addresses from a textarea and turn them into semi separatedstatic boolean
nullOrBlank
(Object object) is an object null or blankstatic long
packInts
(int first, int second) pack two ints into a long.static String
parentStemNameFromName
(String name) get the parent stem name from name.static String
parentStemNameFromName
(String name, boolean nullForRoot) get the parent stem name from name.static String
prefixOrSuffix
(String startString, String separator, boolean isPrefix) get the prefix or suffix of a string based on a separatorstatic Object
Remove the iterator or indexstatic Object
Remove the iterator or indexstatic String
Repeat a Stringrepeat
times to form a new String.static void
replace a string or strings from a string, and put the output in a string buffer.static void
replace a string or strings from a string, and put the output in a string bufferstatic void
replace
(StringBuffer outBuffer, String text, Object searchFor, Object replaceWith) replace a string or strings from a string, and put the output in a string buffer.static void
replace
(StringBuffer outBuffer, String text, Object searchFor, Object replaceWith, boolean recurse) replace a string or strings from a string, and put the output in a string bufferstatic String
replace a string or strings from a string, and put the output in a string buffer.static String
replace a string or strings from a string, and put the output in a string bufferstatic String
replace a string or strings from a string, and put the output in a string bufferstatic String
Replaces all occurrences of a String within another String.static String
Replaces a String with another String inside a larger String, for the firstmax
values of the search String.static String
replaceWhitespaceWithSpace
(String input) replace all whitespace with spacestatic String
Right pad a String with spaces (' ').static String
Right pad a String with a specified character.static String
Right pad a String with a specified String.static <T> T
Return the zero element of the set, if it exists, null if the list is empty.static <T> Set<T>
setShorten
(Set<T> theSet, int maxSize) shorten a set if it is too longstatic String
setToString
(Set set) convert a set to a string (comma separate)static Short
shortObjectValue
(Object input) get the Short value of an object.static short
shortValue
(Object input) convert an object to a shortstatic void
sleep
(long millis) sleep, if interrupted, throw runtimestatic void
sleepWithStdoutCountdown
(int seconds) static String[]
Splits the provided text into an array, using whitespace as the separator.static String[]
Splits the provided text into an array, separator specified.static String[]
Splits the provided text into an array, separators specified.static String[]
Splits the provided text into an array with a maximum length, separators specified.static String[]
splitByWholeSeparator
(String str, String separator) Splits the provided text into an array, separator string specified.static String[]
splitByWholeSeparator
(String str, String separator, int max) Splits the provided text into an array, separator string specified.static String[]
Splits the provided text into an array, using whitespace as the separator, preserving all tokens, including empty tokens created by adjacent separators.static String[]
splitPreserveAllTokens
(String str, char separatorChar) Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators.static String[]
splitPreserveAllTokens
(String str, String separatorChars) Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.static String[]
splitPreserveAllTokens
(String str, String separatorChars, int max) Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.static String[]
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)static String[]
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)splitTrimCommas
(String input, String commaSeparatedAttributes, String regexAllowedChars, String replaceChar) split by commas.splitTrimCurlyColons
(String input, String commaSeparatedAttributes, String regexAllowedChars, String replaceChar) split by curly colons.splitTrimToList
(String input, String separator) split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)splitTrimToSet
(String input, String separator) split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)static int
stringLength
(String string) string lengthstatic Date
stringToDate
(String dateString) convert a string to a date using the standard web service pattern Note that HH is 0-23static Date
stringToDate2
(String input) take as input: yyyy/mm/dd yyyy-mm-dd dd-mon-yyyy yyyy/mm/dd hh:mm:ss dd-mon-yyyy hh:mm:ss yyyy/mm/dd hh:mm:ss.SSS dd-mon-yyyy hh:mm:ss.SSSstatic Timestamp
stringToTimestamp
(String input) convert a string to timestamp based on the following formats: yyyyMMdd yyyy/MM/dd yyyy/MM/dd HH:mm:ss yyyy/MM/dd HH:mm:ss.SSS yyyy/MM/dd HH:mm:ss.SSSSSSstatic String
stringValue
(Object input) convert an object to a stringstatic String
stringValue
(Date date) convert a date to the standard string yyyymmddstatic String
Strips any of a set of characters from the end of a String.static String
stripLastSlashIfExists
(String input) strip the last slash (/ or \) from a string if it existsstatic String
stripStart
(String str, String stripChars) Strips any of a set of characters from the start of a String.static String
stripSuffix
(String string, String suffix) strip the suffix offstatic boolean
subjectHasAttribute
(Subject subject, String attributeName) see if a subject has an attributestatic String
subjectToString
(Subject subject) convert a subject to string safelystatic String
substringAfter
(String str, String separator) Gets the substring after the first occurrence of a separator.static String
substringAfterLast
(String str, String separator) Gets the substring after the last occurrence of a separator.static String
substringBefore
(String str, String separator) Gets the substring before the first occurrence of a separator.static String
substringBeforeLast
(String str, String separator) Gets the substring before the last occurrence of a separator.static String
suffixAfterChar
(String input, char theChar) return the suffix after a char.static String
timestampToFileString
(Date timestamp) Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSSstatic String
timestampToString
(Date timestamp) Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSSstatic Object
Convert a list to an array with the type of the first element e.g.static <T> T[]
toArray
(Collection collection, Class<T> theClass) convert a list into an array of type of theClassstatic <T> List<T>
toList
(T... objects) return a list of objects from varargs.toListObject
(Object... objects) return a list of objects from varargs.static String
toLowerCase
(String input) null safe to lower methodturn some strings into a mapstatic <T> Set<T>
toSet
(T... objects) return a set of objects from varargs.static <T> Set<T>
toSetObject
(T object) return a set of stringstatic String
toString
(Collection<Source> sources) convert a collection of sources to a stringstatic String
toStringForLog
(Object object) print out various types of objectsstatic String
toStringForLog
(Object object, int maxChars) print out various types of objectstoStringObjectMap
(Object... stringObjects) turn some strings into a mapstatic String
toStringSafe
(Object object) fail safe toString for Exception blocks, and include the stack if there is a problem with toString()static Timestamp
toTimestamp
(Object input) Convert a string or object to a timestamp (could be string, date, timestamp, etc) yyyymmdd or yyyy/MM/dd or yyyy/MM/dd HH:mm:ss or yyyy/MM/dd HH:mm:ss.SSS or yyyy/MM/dd HH:mm:ss.SSSSSSstatic String
toUpperCase
(String input) null safe to upper methodstatic String
trim whitespace from stringstatic String
trimToEmpty
(String str) trim to empty, convert null to emptystatic String
truncateAscii
(String input, int requiredLength) find the length of ascii chars (non ascii are counted as two)static Class
unenhanceClass
(Class theClass) if a class is enhanced, get the unenhanced versionstatic String
uniqueId()
get a unique string identifier based on the current time, this is not globally unique, just unique for as long as this server is running...static int
unpackInt
(long theLong, boolean isFirst) take a longstatic boolean
validEmail
(String email) static String
Convert an XML string to HTML to display on the screenstatic String
Convert an XML string to HTML to display on the screen
-
Field Details
-
LOG_ERROR
- See Also:
-
ONE_KB
public static final long ONE_KBThe number of bytes in a kilobyte.- See Also:
-
ONE_MB
public static final long ONE_MBThe number of bytes in a megabyte.- See Also:
-
ONE_GB
public static final long ONE_GBThe number of bytes in a gigabyte.- See Also:
-
DATE_FORMAT
string format of dates- See Also:
-
TIMESTAMP_FILE_FORMAT
string format of dates for file names- See Also:
-
DATE_FORMAT2
string format of dates- See Also:
-
DATE_MINUTES_SECONDS_FORMAT
format including minutes and seconds: yyyy/MM/dd HH:mm:ss- See Also:
-
DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
format including minutes and seconds: yyyyMMdd HH:mm:ss- See Also:
-
TIMESTAMP_FORMAT
format on screen of config for milestone: yyyy/MM/dd HH:mm:ss.SSS- See Also:
-
TIMESTAMP_NO_SLASH_FORMAT
format on screen of config for milestone: yyyyMMdd HH:mm:ss.SSS- See Also:
-
NOT_FOUND
public static final int NOT_FOUNDspecial number when a number is not found- See Also:
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe name says it all.- See Also:
-
EMPTY_STRING_ARRAY
An empty immutableString
array. -
EMPTY_OBJECT_ARRAY
An empty immutableObject
array. -
EMPTY
The empty String""
.- Since:
- 2.0
- See Also:
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUNDRepresents a failed index search.- Since:
- 2.1
- See Also:
-
-
Constructor Details
-
GrouperUtilElSafe
public GrouperUtilElSafe()
-
-
Method Details
-
collectionContains
- Parameters:
collection
-object
-- Returns:
- true if the collection contains this object
-
normalize
take out accented chars with grouperUtil.normalize("NFD", groupAttribute).replaceAll("\\p{M}", "")- Parameters:
form
-text
-- Returns:
- the normalized string
-
toUpperCase
null safe to upper method- Parameters:
input
-- Returns:
- upper
-
toLowerCase
null safe to lower method- Parameters:
input
-- Returns:
- lower
-
normalizeEmailAddresses
take email addresses from a textarea and turn them into semi separated- Parameters:
emailAddresses
- can be whitespace, comma, or semi separated- Returns:
- the email addresses semi separated
-
validEmail
- Parameters:
email
-- Returns:
- true if valid, false if not
-
subjectHasAttribute
see if a subject has an attribute- Parameters:
subject
-attributeName
-- Returns:
- true if the subject has an attribute
-
setShorten
shorten a set if it is too long- Type Parameters:
T
-- Parameters:
theSet
-maxSize
-- Returns:
- the new set
-
formatNumberWithCommas
- Parameters:
number
- e.g. 12345678- Returns:
- the string, e.g. 12,345,678
-
compare
compare null safe- Parameters:
first
-second
-- Returns:
- 0 for equal, 1 for greater, -1 for less
-
toMap
turn some strings into a map- Parameters:
strings
-- Returns:
- the map (never null)
-
toStringObjectMap
turn some strings into a map- Parameters:
stringObjects
- is an array of String,Object,String,Object etc where the Strings are the key, and the Object is the value- Returns:
- the map (never null)
-
convertMillisToFriendlyString
convert millis to friendly string- Parameters:
duration
-- Returns:
- the friendly string
-
convertMillisToFriendlyString
convert millis to friendly string- Parameters:
duration
-- Returns:
- the friendly string
-
argAfter
return the arg after the argBefore, or null if not there, or exception if argBefore is not found- Parameters:
args
-argBefore
-- Returns:
- the arg
-
append
public static void append(StringBuilder result, String separatorIfResultNotEmpty, String stringToAppend) append and maybe put a separator in there- Parameters:
result
-separatorIfResultNotEmpty
-stringToAppend
-
-
byteCountToDisplaySize
Returns a human-readable version of the file size (original is in bytes).- Parameters:
size
- The number of bytes.- Returns:
- A human-readable display value (includes units).
-
suffixAfterChar
return the suffix after a char. If the char doesnt exist, just return the string- Parameters:
input
- stringtheChar
- char- Returns:
- new string
-
sleep
public static void sleep(long millis) sleep, if interrupted, throw runtime- Parameters:
millis
-
-
sleepWithStdoutCountdown
public static void sleepWithStdoutCountdown(int seconds) - Parameters:
seconds
-
-
encryptSha
encrypt a message to SHA- Parameters:
plaintext
-- Returns:
- the hash
-
uniqueId
get a unique string identifier based on the current time, this is not globally unique, just unique for as long as this server is running...- Returns:
- String
-
nonNull
make sure a array is non null. If null, then return an empty array.- Type Parameters:
T
-- Parameters:
array
-theClass
- to make array from- Returns:
- the list or empty list if null
-
stripSuffix
strip the suffix off- Parameters:
string
-suffix
-- Returns:
- the string without the suffix
-
prefixOrSuffix
get the prefix or suffix of a string based on a separator- Parameters:
startString
- is the string to start withseparator
- is the separator to split onisPrefix
- if thre prefix or suffix should be returned- Returns:
- the prefix or suffix, if the separator isnt there, return the original string
-
indent
this method will indent xml or json. this is for logging or documentations purposes only and should not be used for a production use (since it is not 100% tested or compliant with all constructs like xml CDATA For xml, assumes elements either have text or sub elements, not both. No cdata, nothing fancy. If the input is <a><b><c>hey</c><d><e>there</e></d></b></a> It would output: <a> <b> <c>hey</c> <d> <e>there</e> </d> </b> </a> For , if the input is: {"a":{"b\"b":{"c\\":"d"},"e":"f","g":["h":"i"]}} It would output: { "a":{ "b\"b":{ "c\\":"d" }, "e":"f", "g":[ "h":"i" ] } }
- Parameters:
string
-failIfTypeNotFound
-- Returns:
- the indented string, 2 spaces per line
-
extensionFromName
get the extension from name. if name is a:b:c, name is c- Parameters:
name
-- Returns:
- the name
-
parentStemNameFromName
get the parent stem name from name. if already a root stem then just return null. e.g. if the name is a:b:c then the return value is a:b- Parameters:
name
-- Returns:
- the parent stem name or null if none
-
parentStemNameFromName
get the parent stem name from name. if already a root stem then just return null. e.g. if the name is a:b:c then the return value is a:b- Parameters:
name
-nullForRoot
- null for root, otherwise colon- Returns:
- the parent stem name or null if none
-
defaultIfBlank
return the string or the other if the first is blank- Parameters:
string
-defaultStringIfBlank
-- Returns:
- the string or the default one
-
defaultIfNull
public static <T> T defaultIfNull(T theValue, T defaultIfTheValueIsNull) genericized method to see if first is null, if so then return second, else first.- Type Parameters:
T
-- Parameters:
theValue
- first inputdefaultIfTheValueIsNull
- second input- Returns:
- the first if not null, second if no
-
addIfNotThere
add each element of listToAdd if it is not already in list- Type Parameters:
T
-- Parameters:
list
- to add tolistToAdd
- each element will be added to list, or null if none
-
collectionToString
convert a set to a string (comma separate)- Parameters:
collection
-- Returns:
- the String
-
setToString
convert a set to a string (comma separate)- Parameters:
set
-- Returns:
- the String
-
MapToString
Deprecated.use mapToString(map)convert a set to a string (comma separate)- Parameters:
map
-- Returns:
- the String
-
mapToString
convert a set to a string (comma separate)- Parameters:
map
-- Returns:
- the String
-
toStringForLog
print out various types of objects- Parameters:
object
-- Returns:
- the string value
-
toStringForLog
print out various types of objects- Parameters:
object
-maxChars
- is the max chars that should be returned (abbreviate if longer), or -1 for any amount- Returns:
- the string value
-
batchNumberOfBatches
public static int batchNumberOfBatches(int count, int batchSize, boolean haveAtLeastOne) If batching this is the number of batches- Parameters:
count
- is size of setbatchSize
-haveAtLeastOne
- is true if there should be at least one run even if the collection is empty (e.g. for queries based on other things)- Returns:
- the number of batches
-
batchNumberOfBatches
Deprecated.use batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne)If batching this is the number of batches. Will return at least 1- Parameters:
count
- is size of setbatchSize
-- Returns:
- the number of batches
-
batchNumberOfBatches
Deprecated.use batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne)If batching this is the number of batches, will return at least 1- Parameters:
collection
-batchSize
-- Returns:
- the number of batches
-
batchNumberOfBatches
public static int batchNumberOfBatches(Collection<?> collection, int batchSize, boolean haveAtLeastOne) If batching this is the number of batches, will return at least 1- Parameters:
collection
-batchSize
-haveAtLeastOne
- is true if there should be at least one run even if the collection is empty (e.g. for queries based on other things)- Returns:
- the number of batches
-
batchList
retrieve a batch by 0 index. Will return an array of size batchSize or the remainder. the array will be full of elements. Note, this requires an ordered input (so use linkedhashset not hashset if doing sets)- Type Parameters:
T
- template type- Parameters:
collection
-batchSize
-batchIndex
-- Returns:
- the list This never returns null, only empty list
-
splitTrim
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)- Parameters:
input
- is the delimited input to split and trimseparator
- is what to split on- Returns:
- the array of items after split and trimmed, or null if input is null. will be trimmed to empty
-
splitTrimToList
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)- Parameters:
input
- is the delimited input to split and trimseparator
- is what to split on- Returns:
- the list of items after split and trimmed, or null if input is null. will be trimmed to empty
-
splitTrimToSet
split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)- Parameters:
input
- is the delimited input to split and trimseparator
- is what to split on- Returns:
- the set of items after split and trimmed, or null if input is null. will be trimmed to empty
-
splitTrim
public static String[] splitTrim(String input, String separator, boolean treatAdjacentSeparatorsAsOne) split a string based on a separator into an array, and trim each entry (see the Commons Util trim() for more details)- Parameters:
input
- is the delimited input to split and trimseparator
- is what to split ontreatAdjacentSeparatorsAsOne
-- Returns:
- the array of items after split and trimmed, or null if input is null. will be trimmed to empty
-
escapeUrlEncode
escape url chars (e.g. a # is %23)- Parameters:
string
- input- Returns:
- the encoded string
-
escapeUrlDecode
unescape url chars (e.g. a space is %20)- Parameters:
string
- input- Returns:
- the encoded string
-
nonNull
make sure a list is non null. If null, then return an empty list- Type Parameters:
T
-- Parameters:
list
-- Returns:
- the list or empty list if null
-
nonNull
make sure a collection is non null. If null, then return an empty list- Type Parameters:
T
-- Parameters:
list
-- Returns:
- the list or empty list if null
-
nonNull
make sure a list is non null. If null, then return an empty set- Type Parameters:
T
-- Parameters:
set
-- Returns:
- the set or empty set if null
-
nonNull
make sure it is non null, if null, then give new map- Type Parameters:
K
- key of mapV
- value of map- Parameters:
map
- is map- Returns:
- set non null
-
toList
return a list of objects from varargs. Though if there is one object, and it is a list, return it.- Type Parameters:
T
- template type of the objects- Parameters:
objects
-- Returns:
- the list or null if objects is null
-
toListObject
return a list of objects from varargs. Though if there is one object, and it is a list, return it.- Type Parameters:
T
- template type of the objects- Parameters:
objects
-- Returns:
- the list or null if objects is null
-
toSet
return a set of objects from varargs.- Type Parameters:
T
- template type of the objects- Parameters:
objects
-- Returns:
- the set
-
toSetObject
return a set of string- Type Parameters:
T
- template type of the objects- Parameters:
object
-- Returns:
- the set
-
assertion
If false, throw an assertException, and give a reason- Parameters:
isTrue
-reason
-
-
iterator
null safe iterator getter if the type if collection- Parameters:
collection
-- Returns:
- the iterator
-
length
Null safe array length or map- Parameters:
arrayOrCollection
-- Returns:
- the length of the array (0 for null)
-
next
If array, get the element based on index, if Collection, get it based on iterator.- Parameters:
arrayOrCollection
-iterator
-index
-- Returns:
- the object
-
remove
Remove the iterator or index- Parameters:
arrayOrCollection
-index
-- Returns:
- the object list or new array
-
remove
Remove the iterator or index- Parameters:
arrayOrCollection
-iterator
-index
-- Returns:
- the object list or new array
-
classesString
print the simple names of a list of classes- Parameters:
object
-- Returns:
- the simple names
-
classNameCollection
null safe classname method, max out at 20- Parameters:
object
-- Returns:
- the classname
-
className
null safe classname method, gets the unenhanced name- Parameters:
object
-- Returns:
- the classname
-
toArray
Convert a list to an array with the type of the first element e.g. if it is a list of Person objects, then the array is Person[]- Parameters:
objectOrArrayOrCollection
- is a list- Returns:
- the array of objects with type of the first element in the list
-
toArray
convert a list into an array of type of theClass- Type Parameters:
T
- is the type of the array- Parameters:
collection
- list to converttheClass
- type of array to return- Returns:
- array of type theClass[] filled with the objects from list
-
replace
replace a string or strings from a string, and put the output in a string buffer. This does not recurse- Parameters:
text
- string to look insearchFor
- string array to search forreplaceWith
- string array to replace with- Returns:
- the string
-
replace
replace a string or strings from a string, and put the output in a string buffer- Parameters:
text
- string to look insearchFor
- string array to search forreplaceWith
- string array to replace withrecurse
- if true then do multiple replaces (on the replacements)- Returns:
- the string
-
replace
public static String replace(String text, Object searchFor, Object replaceWith, boolean recurse, boolean removeIfFound) replace a string or strings from a string, and put the output in a string buffer- Parameters:
text
- string to look insearchFor
- string array to search forreplaceWith
- string array to replace withrecurse
- if true then do multiple replaces (on the replacements)removeIfFound
- true if removing from searchFor and replaceWith if found- Returns:
- the string
-
replace
Replaces all occurrences of a String within another String.
A
null
reference passed to this method is a no-op.replace(null, *, *) = null replace("", *, *) = "" replace("any", null, *) = "any" replace("any", *, null) = "any" replace("any", "", *) = "any" replace("aba", "a", null) = "aba" replace("aba", "a", "") = "b" replace("aba", "a", "z") = "zbz"
- Parameters:
text
- text to search and replace in, may be nullrepl
- the String to search for, may be nullwith
- the String to replace with, may be null- Returns:
- the text with any replacements processed,
null
if null String input - See Also:
-
replace
Replaces a String with another String inside a larger String, for the first
max
values of the search String.A
null
reference passed to this method is a no-op.replace(null, *, *, *) = null replace("", *, *, *) = "" replace("any", null, *, *) = "any" replace("any", *, null, *) = "any" replace("any", "", *, *) = "any" replace("any", *, *, 0) = "any" replace("abaa", "a", null, -1) = "abaa" replace("abaa", "a", "", -1) = "b" replace("abaa", "a", "z", 0) = "abaa" replace("abaa", "a", "z", 1) = "zbaa" replace("abaa", "a", "z", 2) = "zbza" replace("abaa", "a", "z", -1) = "zbzz"
- Parameters:
text
- text to search and replace in, may be nullrepl
- the String to search for, may be nullwith
- the String to replace with, may be nullmax
- maximum number of values to replace, or-1
if no maximum- Returns:
- the text with any replacements processed,
null
if null String input
-
isEmpty
Checks if a String is empty ("") or null.
isEmpty(null) = true isEmpty("") = true isEmpty(" ") = false isEmpty("bob") = false isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
- Parameters:
str
- the String to check, may be null- Returns:
true
if the String is empty or null
-
replace
public static void replace(StringBuffer outBuffer, String text, Object searchFor, Object replaceWith) replace a string or strings from a string, and put the output in a string buffer. This does not recurse- Parameters:
outBuffer
- stringbuffer to write totext
- string to look insearchFor
- string array to search forreplaceWith
- string array to replace with
-
replace
public static void replace(StringBuffer outBuffer, String text, Object searchFor, Object replaceWith, boolean recurse) replace a string or strings from a string, and put the output in a string buffer- Parameters:
outBuffer
- stringbuffer to write totext
- string to look insearchFor
- string array to search forreplaceWith
- string array to replace withrecurse
- if true then do multiple replaces (on the replacements)
-
replace
replace a string or strings from a string, and put the output in a string buffer. This does not recurse- Parameters:
outWriter
- writer to write totext
- string to look insearchFor
- string array to search forreplaceWith
- string array to replace with
-
replace
public static void replace(Writer outWriter, String text, Object searchFor, Object replaceWith, boolean recurse) replace a string or strings from a string, and put the output in a string buffer- Parameters:
outWriter
- writer to write totext
- string to look insearchFor
- string array to search forreplaceWith
- string array to replace withrecurse
- if true then do multiple replaces (on the replacements)
-
packInts
public static long packInts(int first, int second) pack two ints into a long. Note: the first is held in the left bits, the second is held in the right bits- Parameters:
first
- is first intsecond
- is second int- Returns:
- the long which has two ints in there
-
unpackInt
public static int unpackInt(long theLong, boolean isFirst) take a long- Parameters:
theLong
- to unpackisFirst
- true for first, false for second- Returns:
- one of the packed ints, first or second
-
toString
convert a collection of sources to a string- Parameters:
sources
-- Returns:
- the string
-
toStringSafe
fail safe toString for Exception blocks, and include the stack if there is a problem with toString()- Parameters:
object
-- Returns:
- the toStringSafe string
-
booleanValue
get the boolean value for an object, cant be null or blank- Parameters:
object
-- Returns:
- the boolean
-
booleanValue
get the boolean value for an object- Parameters:
object
-defaultBoolean
- if object is null or empty- Returns:
- the boolean
-
booleanObjectValue
get the Boolean value for an object- Parameters:
object
-- Returns:
- the Boolean or null if null or empty
-
nullOrBlank
is an object null or blank- Parameters:
object
-- Returns:
- true if null or blank
-
dateLongValue
convert a string date into a long date (e.g. for xml export)- Parameters:
date
-- Returns:
- the long or null if the date was null or blank
-
dateStringValue
date object to a string:- Parameters:
date
-- Returns:
- the long or null if the date was null or blank
-
dateStringValue
date object to a string:- Parameters:
theDate
-- Returns:
- the long or null if the date was null or blank
-
dateValue
Convert an object to a java.util.Date. allows, dates, null, blank, yyyymmdd or yyyymmdd hh24:mm:ss or yyyy/MM/dd HH:mm:ss.SSS
- Parameters:
inputObject
- is the String or Date to convert- Returns:
- the Date
-
stringToDate2
take as input: yyyy/mm/dd yyyy-mm-dd dd-mon-yyyy yyyy/mm/dd hh:mm:ss dd-mon-yyyy hh:mm:ss yyyy/mm/dd hh:mm:ss.SSS dd-mon-yyyy hh:mm:ss.SSS- Parameters:
input
-- Returns:
- the date
-
monthInt
convert a month string to an int (1 indexed). e.g. if input is feb or Feb or february or February return 2- Parameters:
mon
-- Returns:
- the month
-
isBlank
See if the input is null or if string, if it is empty or blank (whitespace)- Parameters:
input
-- Returns:
- true if blank
-
isScalar
see if a class is a scalar (not bean, not array or list, etc)- Parameters:
type
-- Returns:
- true if scalar
-
toTimestamp
Convert a string or object to a timestamp (could be string, date, timestamp, etc) yyyymmdd or yyyy/MM/dd or yyyy/MM/dd HH:mm:ss or yyyy/MM/dd HH:mm:ss.SSS or yyyy/MM/dd HH:mm:ss.SSSSSS
- Parameters:
input
-- Returns:
- the timestamp
- Throws:
RuntimeException
- if invalid format
-
stringValue
convert an object to a string- Parameters:
input
- is the object to convert- Returns:
- the String conversion of the object
-
timestampToString
Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSS- Parameters:
timestamp
-- Returns:
- the string representation
-
timestampToFileString
Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSS- Parameters:
timestamp
-- Returns:
- the string representation
-
stringValue
convert a date to the standard string yyyymmdd- Parameters:
date
-- Returns:
- the string value
-
stringToTimestamp
convert a string to timestamp based on the following formats: yyyyMMdd yyyy/MM/dd yyyy/MM/dd HH:mm:ss yyyy/MM/dd HH:mm:ss.SSS yyyy/MM/dd HH:mm:ss.SSSSSS
- Parameters:
input
-- Returns:
- the timestamp object
-
bigDecimalObjectValue
Convert an object to a byte, allow nulls- Parameters:
input
-- Returns:
- the boolean object value
-
byteObjectValue
Convert an object to a byte, allow nulls- Parameters:
input
-- Returns:
- the boolean object value
-
byteValue
convert an object to a byte- Parameters:
input
-- Returns:
- the byte
-
doubleObjectValue
get the Double value of an object- Parameters:
input
- is a number or StringallowNullBlank
- used to default to false, if true, return null if nul inputted- Returns:
- the Double equivalent
-
doubleValue
get the double value of an object- Parameters:
input
- is a number or String- Returns:
- the double equivalent
-
doubleValueNoError
get the double value of an object, do not throw an exception if there is an error- Parameters:
input
- is a number or String- Returns:
- the double equivalent
-
floatObjectValue
get the Float value of an object- Parameters:
input
- is a number or StringallowNullBlank
- true if allow null or blank- Returns:
- the Float equivalent
-
floatValue
get the float value of an object- Parameters:
input
- is a number or String- Returns:
- the float equivalent
-
floatValueNoError
get the float value of an object, do not throw an exception if there is an error- Parameters:
input
- is a number or String- Returns:
- the float equivalent
-
intObjectValue
get the Integer value of an object- Parameters:
input
- is a number or StringallowNullBlank
- true if convert null or blank to null- Returns:
- the Integer equivalent
-
intValue
convert an object to a int- Parameters:
input
-- Returns:
- the number
-
intValue
convert an object to a int- Parameters:
input
-valueIfNull
- is if the input is null or empty, return this value- Returns:
- the number
-
intValueNoError
get the int value of an object, do not throw an exception if there is an error- Parameters:
input
- is a number or String- Returns:
- the int equivalent
-
longObjectValue
get the Long value of an object- Parameters:
input
- is a number or StringallowNullBlank
- true if null or blank converts to null- Returns:
- the Long equivalent
-
longValue
convert an object to a long- Parameters:
input
-- Returns:
- the number
-
longValue
convert an object to a long- Parameters:
input
-valueIfNull
- is if the input is null or empty, return this value- Returns:
- the number
-
longValueNoError
get the long value of an object, do not throw an exception if there is an error- Parameters:
input
- is a number or String- Returns:
- the long equivalent
-
shortObjectValue
get the Short value of an object. converts null or blank to null- Parameters:
input
- is a number or String- Returns:
- the Long equivalent
-
shortValue
convert an object to a short- Parameters:
input
-- Returns:
- the number
-
charObjectValue
get the Character wrapper value for the input- Parameters:
input
- allow null, return null- Returns:
- the Character object wrapper
-
charValue
convert an object to a char- Parameters:
input
-- Returns:
- the number
-
replaceWhitespaceWithSpace
replace all whitespace with space- Parameters:
input
-- Returns:
- the string
-
convertLongToChar
this method takes a long (less than 62) and converts it to a 1 character string (a-z, A-Z, 0-9)- Parameters:
theLong
- is the long (less than 62) to convert to a 1 character string- Returns:
- a one character string
-
convertLongToCharSmall
this method takes a long (less than 36) and converts it to a 1 character string (A-Z, 0-9)- Parameters:
theLong
- is the long (less than 36) to convert to a 1 character string- Returns:
- a one character string
-
convertLongToString
convert a long to a string by converting it to base 62 (26 lower, 26 upper, 10 digits)- Parameters:
theLong
- is the long to convert- Returns:
- the String conversion of this
-
convertLongToStringSmall
convert a long to a string by converting it to base 36 (26 upper, 10 digits)- Parameters:
theLong
- is the long to convert- Returns:
- the String conversion of this
-
incrementChar
public static char incrementChar(char theChar) increment a character (A-Z then 0-9)- Parameters:
theChar
-- Returns:
- the value
-
incrementStringInt
public static char[] incrementStringInt(char[] string) Increment a string with A-Z and 0-9 (no lower case so case insensitive apps like windows IE will still work)- Parameters:
string
-- Returns:
- the value
-
isAscii
public static boolean isAscii(char input) is ascii char- Parameters:
input
-- Returns:
- true if ascii
-
lengthAscii
find the length of ascii chars (non ascii are counted as two)- Parameters:
input
-- Returns:
- the length of ascii chars
-
stringLength
string length- Parameters:
string
-- Returns:
- string length
-
truncateAscii
find the length of ascii chars (non ascii are counted as two)- Parameters:
input
- is the string to operate onrequiredLength
- length we need the string to be- Returns:
- the length of ascii chars
-
subjectToString
convert a subject to string safely- Parameters:
subject
-- Returns:
- the string value of subject (might be null)
-
equals
null safe string compare- Parameters:
first
-second
-- Returns:
- true if equal
-
isBlank
Checks if a String is whitespace, empty ("") or null.
isBlank(null) = true isBlank("") = true isBlank(" ") = true isBlank("bob") = false isBlank(" bob ") = false
- Parameters:
str
- the String to check, may be null- Returns:
true
if the String is null, empty or whitespace- Since:
- 2.0
-
isNotBlank
- Parameters:
str
-- Returns:
- true if not blank
-
trim
trim whitespace from string- Parameters:
str
-- Returns:
- trimmed string
-
equalsIgnoreCase
equalsignorecase- Parameters:
str1
-str2
-- Returns:
- true if the strings are equal ignore case
-
trimToEmpty
trim to empty, convert null to empty- Parameters:
str
-- Returns:
- trimmed
-
abbreviate
Abbreviates a String using ellipses. This will turn "Now is the time for all good men" into "Now is the time for..."
Specifically:
- If
str
is less thanmaxWidth
characters long, return it. - Else abbreviate it to
(substring(str, 0, max-3) + "...")
. - If
maxWidth
is less than4
, throw anIllegalArgumentException
. - In no case will it return a String of length greater than
maxWidth
.
StringUtils.abbreviate(null, *) = null StringUtils.abbreviate("", 4) = "" StringUtils.abbreviate("abcdefg", 6) = "abc..." StringUtils.abbreviate("abcdefg", 7) = "abcdefg" StringUtils.abbreviate("abcdefg", 8) = "abcdefg" StringUtils.abbreviate("abcdefg", 4) = "a..." StringUtils.abbreviate("abcdefg", 3) = IllegalArgumentException
- Parameters:
str
- the String to check, may be nullmaxWidth
- maximum length of result String, must be at least 4- Returns:
- abbreviated String,
null
if null String input - Throws:
IllegalArgumentException
- if the width is too small- Since:
- 2.0
- If
-
abbreviate
Abbreviates a String using ellipses. This will turn "Now is the time for all good men" into "...is the time for..."
Works like
abbreviate(String, int)
, but allows you to specify a "left edge" offset. Note that this left edge is not necessarily going to be the leftmost character in the result, or the first character following the ellipses, but it will appear somewhere in the result.In no case will it return a String of length greater than
maxWidth
.StringUtils.abbreviate(null, *, *) = null StringUtils.abbreviate("", 0, 4) = "" StringUtils.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..." StringUtils.abbreviate("abcdefghijklmno", 0, 10) = "abcdefg..." StringUtils.abbreviate("abcdefghijklmno", 1, 10) = "abcdefg..." StringUtils.abbreviate("abcdefghijklmno", 4, 10) = "abcdefg..." StringUtils.abbreviate("abcdefghijklmno", 5, 10) = "...fghi..." StringUtils.abbreviate("abcdefghijklmno", 6, 10) = "...ghij..." StringUtils.abbreviate("abcdefghijklmno", 8, 10) = "...ijklmno" StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno" StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno" StringUtils.abbreviate("abcdefghij", 0, 3) = IllegalArgumentException StringUtils.abbreviate("abcdefghij", 5, 6) = IllegalArgumentException
- Parameters:
str
- the String to check, may be nulloffset
- left edge of source StringmaxWidth
- maximum length of result String, must be at least 4- Returns:
- abbreviated String,
null
if null String input - Throws:
IllegalArgumentException
- if the width is too small- Since:
- 2.0
-
split
Splits the provided text into an array, using whitespace as the separator. Whitespace is defined by
Character.isWhitespace(char)
.The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A
null
input String returnsnull
.StringUtils.split(null) = null StringUtils.split("") = [] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split(" abc ") = ["abc"]
- Parameters:
str
- the String to parse, may be null- Returns:
- an array of parsed Strings,
null
if null String input
-
split
Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A
null
input String returnsnull
.StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("a.b.c", '.') = ["a", "b", "c"] StringUtils.split("a..b.c", '.') = ["a", "b", "c"] StringUtils.split("a:b:c", '.') = ["a:b:c"] StringUtils.split("a\tb\nc", null) = ["a", "b", "c"] StringUtils.split("a b c", ' ') = ["a", "b", "c"]
- Parameters:
str
- the String to parse, may be nullseparatorChar
- the character used as the delimiter,null
splits on whitespace- Returns:
- an array of parsed Strings,
null
if null String input - Since:
- 2.0
-
split
Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A
null
input String returnsnull
. Anull
separatorChars splits on whitespace.StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("abc def", null) = ["abc", "def"] StringUtils.split("abc def", " ") = ["abc", "def"] StringUtils.split("abc def", " ") = ["abc", "def"] StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
- Parameters:
str
- the String to parse, may be nullseparatorChars
- the characters used as the delimiters,null
splits on whitespace- Returns:
- an array of parsed Strings,
null
if null String input
-
split
Splits the provided text into an array with a maximum length, separators specified.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A
null
input String returnsnull
. Anull
separatorChars splits on whitespace.If more than
max
delimited substrings are found, the last returned string includes all characters after the firstmax - 1
returned strings (including separator characters).StringUtils.split(null, *, *) = null StringUtils.split("", *, *) = [] StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
- Parameters:
str
- the String to parse, may be nullseparatorChars
- the characters used as the delimiters,null
splits on whitespacemax
- the maximum number of elements to include in the array. A zero or negative value implies no limit- Returns:
- an array of parsed Strings,
null
if null String input
-
splitByWholeSeparator
Splits the provided text into an array, separator string specified.
The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.
A
null
input String returnsnull
. Anull
separator splits on whitespace.StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("ab de fg", null) = ["ab", "de", "fg"] StringUtils.split("ab de fg", null) = ["ab", "de", "fg"] StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"] StringUtils.split("abstemiouslyaeiouyabstemiously", "aeiouy") = ["bst", "m", "sl", "bst", "m", "sl"] StringUtils.split("abstemiouslyaeiouyabstemiously", "aeiouy") = ["abstemiously", "abstemiously"]
- Parameters:
str
- the String to parse, may be nullseparator
- String containing the String to be used as a delimiter,null
splits on whitespace- Returns:
- an array of parsed Strings,
null
if null String was input
-
splitByWholeSeparator
Splits the provided text into an array, separator string specified. Returns a maximum of
max
substrings.The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.
A
null
input String returnsnull
. Anull
separator splits on whitespace.StringUtils.splitByWholeSeparator(null, *, *) = null StringUtils.splitByWholeSeparator("", *, *) = [] StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"] StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"] StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2) = ["ab", "cd"] StringUtils.splitByWholeSeparator("abstemiouslyaeiouyabstemiously", "aeiouy", 2) = ["bst", "m"] StringUtils.splitByWholeSeparator("abstemiouslyaeiouyabstemiously", "aeiouy", 2) = ["abstemiously", "abstemiously"]
- Parameters:
str
- the String to parse, may be nullseparator
- String containing the String to be used as a delimiter,null
splits on whitespacemax
- the maximum number of elements to include in the returned array. A zero or negative value implies no limit.- Returns:
- an array of parsed Strings,
null
if null String was input
-
splitPreserveAllTokens
Splits the provided text into an array, using whitespace as the separator, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer. Whitespace is defined by
Character.isWhitespace(char)
.The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A
null
input String returnsnull
.StringUtils.splitPreserveAllTokens(null) = null StringUtils.splitPreserveAllTokens("") = [] StringUtils.splitPreserveAllTokens("abc def") = ["abc", "def"] StringUtils.splitPreserveAllTokens("abc def") = ["abc", "", "def"] StringUtils.splitPreserveAllTokens(" abc ") = ["", "abc", ""]
- Parameters:
str
- the String to parse, may benull
- Returns:
- an array of parsed Strings,
null
if null String input - Since:
- 2.1
-
splitPreserveAllTokens
Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A
null
input String returnsnull
.StringUtils.splitPreserveAllTokens(null, *) = null StringUtils.splitPreserveAllTokens("", *) = [] StringUtils.splitPreserveAllTokens("a.b.c", '.') = ["a", "b", "c"] StringUtils.splitPreserveAllTokens("a..b.c", '.') = ["a", "b", "c"] StringUtils.splitPreserveAllTokens("a:b:c", '.') = ["a:b:c"] StringUtils.splitPreserveAllTokens("a\tb\nc", null) = ["a", "b", "c"] StringUtils.splitPreserveAllTokens("a b c", ' ') = ["a", "b", "c"] StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", ""] StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", "", ""] StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", a", "b", "c"] StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", "", a", "b", "c"] StringUtils.splitPreserveAllTokens(" a b c ", ' ') = ["", a", "b", "c", ""]
- Parameters:
str
- the String to parse, may benull
separatorChar
- the character used as the delimiter,null
splits on whitespace- Returns:
- an array of parsed Strings,
null
if null String input - Since:
- 2.1
-
splitPreserveAllTokens
Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A
null
input String returnsnull
. Anull
separatorChars splits on whitespace.StringUtils.splitPreserveAllTokens(null, *) = null StringUtils.splitPreserveAllTokens("", *) = [] StringUtils.splitPreserveAllTokens("abc def", null) = ["abc", "def"] StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "def"] StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "", def"] StringUtils.splitPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"] StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":") = ["ab", "cd", "ef", ""] StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""] StringUtils.splitPreserveAllTokens("ab::cd:ef", ":") = ["ab", "", cd", "ef"] StringUtils.splitPreserveAllTokens(":cd:ef", ":") = ["", cd", "ef"] StringUtils.splitPreserveAllTokens("::cd:ef", ":") = ["", "", cd", "ef"] StringUtils.splitPreserveAllTokens(":cd:ef:", ":") = ["", cd", "ef", ""]
- Parameters:
str
- the String to parse, may benull
separatorChars
- the characters used as the delimiters,null
splits on whitespace- Returns:
- an array of parsed Strings,
null
if null String input - Since:
- 2.1
-
splitPreserveAllTokens
Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. Adjacent separators are treated as one separator.
A
null
input String returnsnull
. Anull
separatorChars splits on whitespace.If more than
max
delimited substrings are found, the last returned string includes all characters after the firstmax - 1
returned strings (including separator characters).StringUtils.splitPreserveAllTokens(null, *, *) = null StringUtils.splitPreserveAllTokens("", *, *) = [] StringUtils.splitPreserveAllTokens("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.splitPreserveAllTokens("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] StringUtils.splitPreserveAllTokens("ab de fg", null, 2) = ["ab", " de fg"] StringUtils.splitPreserveAllTokens("ab de fg", null, 3) = ["ab", "", " de fg"] StringUtils.splitPreserveAllTokens("ab de fg", null, 4) = ["ab", "", "", "de fg"]
- Parameters:
str
- the String to parse, may benull
separatorChars
- the characters used as the delimiters,null
splits on whitespacemax
- the maximum number of elements to include in the array. A zero or negative value implies no limit- Returns:
- an array of parsed Strings,
null
if null String input - Since:
- 2.1
-
join
Joins the elements of the provided array into a single String containing the provided list of elements.
No separator is added to the joined String. Null objects or empty strings within the array are represented by empty strings.
StringUtils.join(null) = null StringUtils.join([]) = "" StringUtils.join([null]) = "" StringUtils.join(["a", "b", "c"]) = "abc" StringUtils.join([null, "", "a"]) = "a"
- Parameters:
array
- the array of values to join together, may be null- Returns:
- the joined String,
null
if null array input - Since:
- 2.0
-
join
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.
StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], ';') = "a;b;c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join([null, "", "a"], ';') = ";;a"
- Parameters:
array
- the array of values to join together, may be nullseparator
- the separator character to use- Returns:
- the joined String,
null
if null array input - Since:
- 2.0
-
join
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. A
null
separator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], "--") = "a--b--c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join(["a", "b", "c"], "") = "abc" StringUtils.join([null, "", "a"], ',') = ",,a"
- Parameters:
array
- the array of values to join together, may be nullseparator
- the separator character to use, null treated as ""- Returns:
- the joined String,
null
if null array input
-
join
Joins the elements of the provided
Iterator
into a single String containing the provided elements.No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.
See the examples here:
join(Object[],char)
.- Parameters:
iterator
- theIterator
of values to join together, may be nullseparator
- the separator character to use- Returns:
- the joined String,
null
if null iterator input - Since:
- 2.0
-
join
Joins the elements of the provided
Iterator
into a single String containing the provided elements.No delimiter is added before or after the list. A
null
separator is the same as an empty String ("").See the examples here:
join(Object[],String)
.- Parameters:
iterator
- theIterator
of values to join together, may be nullseparator
- the separator character to use, null treated as ""- Returns:
- the joined String,
null
if null iterator input
-
defaultString
Returns either the passed in String, or if the String is
null
, an empty String ("").StringUtils.defaultString(null) = "" StringUtils.defaultString("") = "" StringUtils.defaultString("bat") = "bat"
- Parameters:
str
- the String to check, may be null- Returns:
- the passed in String, or the empty String if it
was
null
- See Also:
-
defaultString
Returns either the passed in String, or if the String is
null
, the value ofdefaultStr
.StringUtils.defaultString(null, "NULL") = "NULL" StringUtils.defaultString("", "NULL") = "" StringUtils.defaultString("bat", "NULL") = "bat"
- Parameters:
str
- the String to check, may be nulldefaultStr
- the default String to return if the input isnull
, may be null- Returns:
- the passed in String, or the default if it was
null
- See Also:
-
defaultIfEmpty
Returns either the passed in String, or if the String is empty or
null
, the value ofdefaultStr
.StringUtils.defaultIfEmpty(null, "NULL") = "NULL" StringUtils.defaultIfEmpty("", "NULL") = "NULL" StringUtils.defaultIfEmpty("bat", "NULL") = "bat"
- Parameters:
str
- the String to check, may be nulldefaultStr
- the default String to return if the input is empty ("") ornull
, may be null- Returns:
- the passed in String, or the default
-
capitalize
Capitalizes a String changing the first letter to title case as per
ACharacter.toTitleCase(char)
. No other letters are changed.null
input String returnsnull
.StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt"
- Parameters:
str
- the String to capitalize, may be null- Returns:
- the capitalized String,
null
if null String input - Since:
- 2.0
-
capitalizeFully
Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.
Whitespace is defined by
Character.isWhitespace(char)
. Anull
input String returnsnull
. Capitalization uses the Unicode title case, normally equivalent to upper case.WordUtils.capitalizeFully(null) = null WordUtils.capitalizeFully("") = "" WordUtils.capitalizeFully("i am FINE") = "I Am Fine"
- Parameters:
str
- the String to capitalize, may be null- Returns:
- capitalized String,
null
if null String input
-
capitalizeFully
Converts all the delimiter separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.
The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be capitalized.
A
null
input String returnsnull
. Capitalization uses the Unicode title case, normally equivalent to upper case.WordUtils.capitalizeFully(null, *) = null WordUtils.capitalizeFully("", *) = "" WordUtils.capitalizeFully(*, null) = * WordUtils.capitalizeFully(*, new char[0]) = * WordUtils.capitalizeFully("i aM.fine", {'.'}) = "I am.Fine"
- Parameters:
str
- the String to capitalize, may be nulldelimiters
- set of characters to determine capitalization, null means whitespace- Returns:
- capitalized String,
null
if null String input - Since:
- 2.1
-
capitalize
Capitalizes all the delimiter separated words in a String. Only the first letter of each word is changed. To convert the rest of each word to lowercase at the same time, use
capitalizeFully(String, char[])
.The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be capitalized.
A
null
input String returnsnull
. Capitalization uses the Unicode title case, normally equivalent to upper case.WordUtils.capitalize(null, *) = null WordUtils.capitalize("", *) = "" WordUtils.capitalize(*, new char[0]) = * WordUtils.capitalize("i am fine", null) = "I Am Fine" WordUtils.capitalize("i aM.fine", {'.'}) = "I aM.Fine"
- Parameters:
str
- the String to capitalize, may be nulldelimiters
- set of characters to determine capitalization, null means whitespace- Returns:
- capitalized String,
null
if null String input - Since:
- 2.1
- See Also:
-
contains
Checks if String contains a search character, handling
null
. This method usesString.indexOf(int)
.A
null
or empty ("") String will returnfalse
.StringUtils.contains(null, *) = false StringUtils.contains("", *) = false StringUtils.contains("abc", 'a') = true StringUtils.contains("abc", 'z') = false
- Parameters:
str
- the String to check, may be nullsearchChar
- the character to find- Returns:
- true if the String contains the search character,
false if not or
null
string input - Since:
- 2.0
-
contains
Checks if String contains a search String, handling
null
. This method usesString.indexOf(int)
.A
null
String will returnfalse
.StringUtils.contains(null, *) = false StringUtils.contains(*, null) = false StringUtils.contains("", "") = true StringUtils.contains("abc", "") = true StringUtils.contains("abc", "a") = true StringUtils.contains("abc", "z") = false
- Parameters:
str
- the String to check, may be nullsearchStr
- the String to find, may be null- Returns:
- true if the String contains the search String,
false if not or
null
string input - Since:
- 2.0
-
equals
Compares two objects for equality, where either one or both objects may be
null
.ObjectUtils.equals(null, null) = true ObjectUtils.equals(null, "") = false ObjectUtils.equals("", null) = false ObjectUtils.equals("", "") = true ObjectUtils.equals(Boolean.TRUE, null) = false ObjectUtils.equals(Boolean.TRUE, "true") = false ObjectUtils.equals(Boolean.TRUE, Boolean.TRUE) = true ObjectUtils.equals(Boolean.TRUE, Boolean.FALSE) = false
- Parameters:
object1
- the first object, may benull
object2
- the second object, may benull
- Returns:
true
if the values of both objects are the same
-
stripLastSlashIfExists
strip the last slash (/ or \) from a string if it exists- Parameters:
input
-- Returns:
- input - the last / or \
-
stripStart
Strips any of a set of characters from the start of a String.
A
null
input String returnsnull
. An empty string ("") input returns the empty string.If the stripChars String is
null
, whitespace is stripped as defined byCharacter.isWhitespace(char)
.StringUtils.stripStart(null, *) = null StringUtils.stripStart("", *) = "" StringUtils.stripStart("abc", "") = "abc" StringUtils.stripStart("abc", null) = "abc" StringUtils.stripStart(" abc", null) = "abc" StringUtils.stripStart("abc ", null) = "abc " StringUtils.stripStart(" abc ", null) = "abc " StringUtils.stripStart("yxabc ", "xyz") = "abc "
- Parameters:
str
- the String to remove characters from, may be nullstripChars
- the characters to remove, null treated as whitespace- Returns:
- the stripped String,
null
if null String input
-
stripEnd
Strips any of a set of characters from the end of a String.
A
null
input String returnsnull
. An empty string ("") input returns the empty string.If the stripChars String is
null
, whitespace is stripped as defined byCharacter.isWhitespace(char)
.StringUtils.stripEnd(null, *) = null StringUtils.stripEnd("", *) = "" StringUtils.stripEnd("abc", "") = "abc" StringUtils.stripEnd("abc", null) = "abc" StringUtils.stripEnd(" abc", null) = " abc" StringUtils.stripEnd("abc ", null) = "abc" StringUtils.stripEnd(" abc ", null) = " abc" StringUtils.stripEnd(" abcyx", "xyz") = " abc"
- Parameters:
str
- the String to remove characters from, may be nullstripChars
- the characters to remove, null treated as whitespace- Returns:
- the stripped String,
null
if null String input
-
repeat
Repeat a String
repeat
times to form a new String.StringUtils.repeat(null, 2) = null StringUtils.repeat("", 0) = "" StringUtils.repeat("", 2) = "" StringUtils.repeat("a", 3) = "aaa" StringUtils.repeat("ab", 2) = "abab" StringUtils.repeat("a", -2) = ""
- Parameters:
str
- the String to repeat, may be nullrepeat
- number of times to repeat str, negative treated as zero- Returns:
- a new String consisting of the original String repeated,
null
if null String input
-
rightPad
Right pad a String with spaces (' ').
The String is padded to the size of
size
.StringUtils.rightPad(null, *) = null StringUtils.rightPad("", 3) = " " StringUtils.rightPad("bat", 3) = "bat" StringUtils.rightPad("bat", 5) = "bat " StringUtils.rightPad("bat", 1) = "bat" StringUtils.rightPad("bat", -1) = "bat"
- Parameters:
str
- the String to pad out, may be nullsize
- the size to pad to- Returns:
- right padded String or original String if no padding is necessary,
null
if null String input
-
rightPad
Right pad a String with a specified character.
The String is padded to the size of
size
.StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, 'z') = "zzz" StringUtils.rightPad("bat", 3, 'z') = "bat" StringUtils.rightPad("bat", 5, 'z') = "batzz" StringUtils.rightPad("bat", 1, 'z') = "bat" StringUtils.rightPad("bat", -1, 'z') = "bat"
- Parameters:
str
- the String to pad out, may be nullsize
- the size to pad topadChar
- the character to pad with- Returns:
- right padded String or original String if no padding is necessary,
null
if null String input - Since:
- 2.0
-
rightPad
Right pad a String with a specified String.
The String is padded to the size of
size
.StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, "z") = "zzz" StringUtils.rightPad("bat", 3, "yz") = "bat" StringUtils.rightPad("bat", 5, "yz") = "batyz" StringUtils.rightPad("bat", 8, "yz") = "batyzyzy" StringUtils.rightPad("bat", 1, "yz") = "bat" StringUtils.rightPad("bat", -1, "yz") = "bat" StringUtils.rightPad("bat", 5, null) = "bat " StringUtils.rightPad("bat", 5, "") = "bat "
- Parameters:
str
- the String to pad out, may be nullsize
- the size to pad topadStr
- the String to pad with, null or empty treated as single space- Returns:
- right padded String or original String if no padding is necessary,
null
if null String input
-
leftPad
Left pad a String with spaces (' ').
The String is padded to the size of
size
.
StringUtils.leftPad(null, *) = null StringUtils.leftPad("", 3) = " " StringUtils.leftPad("bat", 3) = "bat" StringUtils.leftPad("bat", 5) = " bat" StringUtils.leftPad("bat", 1) = "bat" StringUtils.leftPad("bat", -1) = "bat"
- Parameters:
str
- the String to pad out, may be nullsize
- the size to pad to- Returns:
- left padded String or original String if no padding is necessary,
null
if null String input
-
leftPad
Left pad a String with a specified character.
Pad to a size of
size
.StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, 'z') = "zzz" StringUtils.leftPad("bat", 3, 'z') = "bat" StringUtils.leftPad("bat", 5, 'z') = "zzbat" StringUtils.leftPad("bat", 1, 'z') = "bat" StringUtils.leftPad("bat", -1, 'z') = "bat"
- Parameters:
str
- the String to pad out, may be nullsize
- the size to pad topadChar
- the character to pad with- Returns:
- left padded String or original String if no padding is necessary,
null
if null String input - Since:
- 2.0
-
leftPad
Left pad a String with a specified String.
Pad to a size of
size
.StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, "z") = "zzz" StringUtils.leftPad("bat", 3, "yz") = "bat" StringUtils.leftPad("bat", 5, "yz") = "yzbat" StringUtils.leftPad("bat", 8, "yz") = "yzyzybat" StringUtils.leftPad("bat", 1, "yz") = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null) = " bat" StringUtils.leftPad("bat", 5, "") = " bat"
- Parameters:
str
- the String to pad out, may be nullsize
- the size to pad topadStr
- the String to pad with, null or empty treated as single space- Returns:
- left padded String or original String if no padding is necessary,
null
if null String input
-
substringBefore
Gets the substring before the first occurrence of a separator. The separator is not returned.
A
null
string input will returnnull
. An empty ("") string input will return the empty string. Anull
separator will return the input string.StringUtils.substringBefore(null, *) = null StringUtils.substringBefore("", *) = "" StringUtils.substringBefore("abc", "a") = "" StringUtils.substringBefore("abcba", "b") = "a" StringUtils.substringBefore("abc", "c") = "ab" StringUtils.substringBefore("abc", "d") = "abc" StringUtils.substringBefore("abc", "") = "" StringUtils.substringBefore("abc", null) = "abc"
- Parameters:
str
- the String to get a substring from, may be nullseparator
- the String to search for, may be null- Returns:
- the substring before the first occurrence of the separator,
null
if null String input - Since:
- 2.0
-
substringAfter
Gets the substring after the first occurrence of a separator. The separator is not returned.
A
null
string input will returnnull
. An empty ("") string input will return the empty string. Anull
separator will return the empty string if the input string is notnull
.StringUtils.substringAfter(null, *) = null StringUtils.substringAfter("", *) = "" StringUtils.substringAfter(*, null) = "" StringUtils.substringAfter("abc", "a") = "bc" StringUtils.substringAfter("abcba", "b") = "cba" StringUtils.substringAfter("abc", "c") = "" StringUtils.substringAfter("abc", "d") = "" StringUtils.substringAfter("abc", "") = "abc"
- Parameters:
str
- the String to get a substring from, may be nullseparator
- the String to search for, may be null- Returns:
- the substring after the first occurrence of the separator,
null
if null String input - Since:
- 2.0
-
substringBeforeLast
Gets the substring before the last occurrence of a separator. The separator is not returned.
A
null
string input will returnnull
. An empty ("") string input will return the empty string. An empty ornull
separator will return the input string.StringUtils.substringBeforeLast(null, *) = null StringUtils.substringBeforeLast("", *) = "" StringUtils.substringBeforeLast("abcba", "b") = "abc" StringUtils.substringBeforeLast("abc", "c") = "ab" StringUtils.substringBeforeLast("a", "a") = "" StringUtils.substringBeforeLast("a", "z") = "a" StringUtils.substringBeforeLast("a", null) = "a" StringUtils.substringBeforeLast("a", "") = "a"
- Parameters:
str
- the String to get a substring from, may be nullseparator
- the String to search for, may be null- Returns:
- the substring before the last occurrence of the separator,
null
if null String input - Since:
- 2.0
-
substringAfterLast
Gets the substring after the last occurrence of a separator. The separator is not returned.
A
null
string input will returnnull
. An empty ("") string input will return the empty string. An empty ornull
separator will return the empty string if the input string is notnull
.StringUtils.substringAfterLast(null, *) = null StringUtils.substringAfterLast("", *) = "" StringUtils.substringAfterLast(*, "") = "" StringUtils.substringAfterLast(*, null) = "" StringUtils.substringAfterLast("abc", "a") = "bc" StringUtils.substringAfterLast("abcba", "b") = "a" StringUtils.substringAfterLast("abc", "c") = "" StringUtils.substringAfterLast("a", "a") = "" StringUtils.substringAfterLast("a", "z") = ""
- Parameters:
str
- the String to get a substring from, may be nullseparator
- the String to search for, may be null- Returns:
- the substring after the last occurrence of the separator,
null
if null String input - Since:
- 2.0
-
getFirstParentStemOfName
Returns the first existing parent stem of a given name. So if the following stems exist: i2 i2:test And you run getFirstParentStemOfName("i2:test:mystem:mygroup"), you will get back the stem for i2:test. If you run getFirstParentStemOfName("test1:test2"), you will get back the root stem.- Parameters:
name
-- Returns:
- Stem
-
listPopOne
Return the zero element of the list, if it exists, null if the list is empty. If there is more than one element in the list, an exception is thrown.- Type Parameters:
T
-- Parameters:
list
- is the container of objects to get the first of.- Returns:
- the first object, null, or exception.
-
setPopOne
Return the zero element of the set, if it exists, null if the list is empty. If there is more than one element in the list, an exception is thrown.- Type Parameters:
T
-- Parameters:
set
- is the container of objects to get the first of.- Returns:
- the first object, null, or exception.
-
collectionPopOne
Return the zero element of the list, if it exists, null if the list is empty. If there is more than one element in the list, an exception is thrown.- Type Parameters:
T
-- Parameters:
collection
- is the container of objects to get the first of.exceptionIfMoreThanOne
- will throw exception if there is more than one item in list- Returns:
- the first object, null, or exception.
-
xmlEscape
Convert an XML string to HTML to display on the screen- Parameters:
input
- is the XML to convertisEscape
- true to escape chars, false to unescape- Returns:
- the HTML converted string
-
xmlEscape
Convert an XML string to HTML to display on the screen- Parameters:
input
- is the XML to convertisEscape
- true to escape chars, false to unescape- Returns:
- the HTML converted string
-
appendIfNotBlank
if theString is not blank, apppend it to the result, and if appending,- Parameters:
result
- to append to add a prefix and suffix (if not null)theStringOrArrayOrList
- is a string, array, list, or set of strings- Returns:
- true if something appended, false if not
-
appendIfNotBlankString
append a string to another string if both not blank, with separator. trim to empty everything
- Parameters:
string
-separator
-suffix
-- Returns:
- the resulting string or blank if nothing
-
appendPrefixIfStringNotBlank
append a prefix to another string if both not blank. trim to empty everything except separator i.e. appendPrefixIfStringNotBlank("[]", " - ", "a") returns [] - a i.e. appendPrefixIfStringNotBlank("", " - ", "a") returns a i.e. appendPrefixIfStringNotBlank("[]", " - ", "") returns "" i.e. appendPrefixIfStringNotBlank("", " - ", "") returns ""
- Parameters:
prefix
-separator
-string
-- Returns:
- the resulting string or blank if nothing
-
appendIfNotBlank
public static boolean appendIfNotBlank(StringBuilder result, String prefix, Object theStringOrArrayOrList) if theString is not Blank, apppend it to the result, and if appending, add a prefix (if not null)- Parameters:
result
- to append toprefix
-theStringOrArrayOrList
- is a string, array, list, or set of strings- Returns:
- true if something appended, false if not
-
appendIfNotBlank
public static boolean appendIfNotBlank(StringBuilder result, String prefix, Object theStringOrArrayOrList, String suffix) if theString is not Blank, apppend it to the result, and if appending, add a prefix and suffix (if not null)- Parameters:
result
- to append to, assumed to be not nullprefix
-theStringOrArrayOrList
- is a string, array, list, or set of stringssuffix
-- Returns:
- true if anything appended, false if not
-
appendIfNotBlank
public static boolean appendIfNotBlank(StringBuilder result, String prefix, String prefixIfNotBlank, Object theStringOrArrayOrList, String suffix) if theString is not Blank, apppend it to the result, and if appending, add a prefix and suffix (if not null)- Parameters:
result
- to append to, assumed to be not nullprefix
- prepend this prefix always (when a result not empty). Will be after the other prefixprefixIfNotBlank
- prepend this prefix if the result is not emptytheStringOrArrayOrList
- is a string, array, list, or set of stringssuffix
-- Returns:
- true if anything appended, false if not
-
appendIfNotEmpty
if theString is not empty, apppend it to the result, and if appending,- Parameters:
result
- to append to add a prefix and suffix (if not null)theStringOrArrayOrList
- is a string, array, list, or set of strings- Returns:
- true if something appended, false if not
-
appendIfNotEmpty
public static boolean appendIfNotEmpty(StringBuilder result, String prefix, Object theStringOrArrayOrList) if theString is not empty, apppend it to the result, and if appending, add a prefix (if not null)- Parameters:
result
- to append toprefix
-theStringOrArrayOrList
- is a string, array, list, or set of strings- Returns:
- true if something appended, false if not
-
appendIfNotEmpty
public static boolean appendIfNotEmpty(StringBuilder result, String prefix, Object theStringOrArrayOrList, String suffix) if theString is not empty, apppend it to the result, and if appending, add a prefix and suffix (if not null)- Parameters:
result
- to append to, assumed to be not nullprefix
-theStringOrArrayOrList
- is a string, array, list, or set of stringssuffix
-- Returns:
- true if anything appended, false if not
-
appendIfNotEmpty
public static boolean appendIfNotEmpty(StringBuilder result, String prefix, String prefixIfNotEmpty, Object theStringOrArrayOrList, String suffix) if theString is not empty, apppend it to the result, and if appending, add a prefix and suffix (if not null)- Parameters:
result
- to append to, assumed to be not nullprefix
- prepend this prefix always (when a result not empty). Will be after the other prefixprefixIfNotEmpty
- prepend this prefix if the result is not emptytheStringOrArrayOrList
- is a string, array, list, or set of stringssuffix
-- Returns:
- true if anything appended, false if not
-
indexOf
Find the index of the given object in the array.
This method returns
-1
ifnull
array input.- Parameters:
array
- the array to search through for the object, may benull
objectToFind
- the object to find, may benull
- Returns:
- the index of the object within the array,
-1
if not found ornull
array input
-
contains
Checks if the object is in the given array.
The method returns
false
if anull
array is passed in.- Parameters:
array
- the array to search throughobjectToFind
- the object to find- Returns:
true
if the array contains the object
-
indexOf
Find the index of the given object in the array starting at the given index.
This method returns
-1
ifnull
array input.A negative startIndex is treated as zero. A startIndex larger than the array length will return
-1
.- Parameters:
array
- the array to search through for the object, may benull
objectToFind
- the object to find, may benull
startIndex
- the index to start searching at- Returns:
- the index of the object within the array starting at the index,
-1
if not found ornull
array input
-
arrayPopOne
public static <T> T arrayPopOne(T[] array) Return the zero element of the array, if it exists, null if the array is empty. If there is more than one element in the list, an exception is thrown.- Type Parameters:
T
-- Parameters:
array
- is the container of objects to get the first of.- Returns:
- the first object, null, or exception.
-
dateToString
convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23- Parameters:
date
-- Returns:
- the string, or null if the date is null
-
stringToDate
convert a string to a date using the standard web service pattern Note that HH is 0-23- Parameters:
dateString
-- Returns:
- the string, or null if the date was null
-
getMaxLongValue
- Parameters:
values
-- Returns:
- the max long in the list of args
-
getMinLongValue
- Parameters:
values
-- Returns:
- the min long in the list of args
-
ipOnNetwork
see if an ip address is on a network- Parameters:
ipString
- is the ip address to checknetworkIpString
- is the ip address of the networkmask
- is the length of the mask (0-32)- Returns:
- boolean
-
ipOnNetworks
see if an ip address is on a network- Parameters:
ipString
- is the ip address to checknetworkIpStrings
- are the ip addresses of the networks, e.g. 1.2.3.4/12, 2.3.4.5/24- Returns:
- boolean
-
ipReadyForAnd
public static int ipReadyForAnd(int ip, int maskLength) get the ip address after putting 1's where the subnet mask is not- Parameters:
ip
- intmaskLength
- int- Returns:
- int
-
ipInt
get the ip addres integer from a string ip address- Parameters:
ip
- String- Returns:
- int
-
getFullStackTrace
A way to get the entire nested stack-trace of an throwable.
- Parameters:
throwable
- theThrowable
to be examined- Returns:
- the nested stack trace, with the root cause first
- Since:
- 2.0
-
get
Get a specific index of an array or collection (note for collections and iterating, it is more efficient to get an iterator and iterate- Parameters:
arrayOrCollection
-index
-- Returns:
- the object at that index
-
unenhanceClass
if a class is enhanced, get the unenhanced version- Parameters:
theClass
-- Returns:
- the unenhanced version
-
getThrowables
Returns the list of
Throwable
objects in the exception chain.A throwable without cause will return an array containing one element - the input throwable. A throwable with one cause will return an array containing two elements. - the input throwable and the cause throwable. A
null
throwable will return an array size zero.- Parameters:
throwable
- the throwable to inspect, may be null- Returns:
- the array of throwables, never null
-
isThrowableNested
public static boolean isThrowableNested()Checks if the Throwable class has a
getCause
method.This is true for JDK 1.4 and above.
- Returns:
- true if Throwable is nestable
- Since:
- 2.0
-
isNestedThrowable
Checks whether this
Throwable
class can store a cause.This method does not check whether it actually does store a cause.
- Parameters:
throwable
- theThrowable
to examine, may be null- Returns:
- boolean
true
if nested otherwisefalse
- Since:
- 2.0
-
getCause
Introspects the
Throwable
to obtain the cause.The method searches for methods with specific names that return a
Throwable
object. This will pick up most wrapping exceptions, including those from JDK 1.4, andNestableException
.The default list searched for are:
getCause()
getNextException()
getTargetException()
getException()
getSourceException()
getRootCause()
getCausedByException()
getNested()
In the absence of any such method, the object is inspected for a
detail
field assignable to aThrowable
.If none of the above is found, returns
null
.- Parameters:
throwable
- the throwable to introspect for a cause, may be null- Returns:
- the cause of the
Throwable
,null
if none found or null throwable input - Since:
- 1.0
-
getCause
Introspects the
Throwable
to obtain the cause.- Try known exception types.
- Try the supplied array of method names.
- Try the field 'detail'.
A
null
set of method names means use the default set. Anull
in the set of method names will be ignored.- Parameters:
throwable
- the throwable to introspect for a cause, may be nullmethodNames
- the method names, null treated as default set- Returns:
- the cause of the
Throwable
,null
if none found or null throwable input - Since:
- 1.0
-
concat
concat two strings- Parameters:
a
-b
-- Returns:
- the concatted string
-
concat
concat strings- Parameters:
a
-b
-c
-- Returns:
- the concatted string
-
concat
concat strings- Parameters:
a
-b
-c
-d
-- Returns:
- the concatted string
-
concat
concat strings- Parameters:
a
-b
-c
-d
-- Returns:
- the concatted string
-
hostname
Hostname of server- Returns:
- hostname of server
-
characterMatchesRegex
- Parameters:
character
-regex
-- Returns:
- if regex
-
splitTrimCurlyColons
public static List<String> splitTrimCurlyColons(String input, String commaSeparatedAttributes, String regexAllowedChars, String replaceChar) split by curly colons. only keep specific attribute values. if a regexAllowedChars is specified, then whitelist chars by regex. character to replace (e.g. underscore), default is underscore. if there isnt a value, dont put it in the list- Parameters:
input
-commaSeparatedAttributes
-regexAllowedChars
-replaceChar
-- Returns:
- the list of attributes
-
splitTrimCommas
public static List<String> splitTrimCommas(String input, String commaSeparatedAttributes, String regexAllowedChars, String replaceChar) split by commas. only keep specific attribute values. if a regexAllowedChars is specified, then whitelist chars by regex. character to replace (e.g. underscore), default is underscore. if there isnt a value, dont put it in the list- Parameters:
input
-commaSeparatedAttributes
-regexAllowedChars
-replaceChar
-- Returns:
- the list of attributes
-
getFriendlyTimezoneStringForInputDescription
Return a string that combines the standard and daylight timezones of the server into one string separated by a slash that can be used in an input description to inform the user of the server timezone. For the main US timezones, the following is returned instead: ET, CT, MT, PT.- Returns:
- string
-