Class SubjectUtils
-
Field Summary
Modifier and TypeFieldDescriptionstatic 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[]
An empty immutableString
array.static final int
special number when a number is not foundstatic 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 void
If false, throw an assertException, and give a reasonstatic void
assignField
(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, boolean callOnSupers, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride) assign data to a fieldstatic void
assignField
(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, Class<? extends Annotation> annotationWithValueOverride) assign data to a field.static void
assignField
(Object invokeOn, String fieldName, Object dataToAssign) assign data to a field.static void
assignField
(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast) assign data to a fieldstatic void
assignField
(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride) assign data to a fieldstatic <T> List<T>
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 Byte
byteObjectValue
(Object input) Convert an object to a byte, allow nullsstatic byte
convert an object to a bytestatic Character
charObjectValue
(Object input) get the Character wrapper value for the inputstatic char
convert an object to a charstatic ClassLoader
fast class loaderstatic String
null safe classname method, gets the unenhanced namestatic String
classNameCollection
(Object object) null safe classname method, max out at 20static void
closeQuietly
(InputStream input) Unconditionally close anInputStream
.static void
closeQuietly
(OutputStream output) Unconditionally close anOutputStream
.static void
closeQuietly
(Reader input) Unconditionally close anReader
.static void
closeQuietly
(Writer writer) close a writer quietlystatic void
closeQuietly
(Connection connection) close a connection null safe and dont throw exceptionstatic void
closeQuietly
(ResultSet resultSet) close a resultSet null safe and dont throw exceptionstatic void
closeQuietly
(Statement statement) close a statement null safe and dont throw exceptionstatic int
compare
(Comparable first, Comparable second) compare null safestatic URL
computeUrl
(String resourceName, boolean canBeNull) compute a url of a resourcestatic void
copy
(InputStream input, Writer output, String encoding) Copy and convert bytes from anInputStream
to chars on aWriter
, using the specified encoding.static int
Copy chars from aReader
to aWriter
.static 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 <T> T
defaultIfNull
(T theValue, T defaultIfTheValueIsNull) genericized method to see if first is null, if so then return second, else first.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 <E extends Enum<?>>
EenumValueOfIgnoreCase
(Class<E> theEnumClass, String string, boolean exceptionOnNotFound) do a case-insensitive matchingstatic <E extends Enum<?>>
EenumValueOfIgnoreCase
(Class<E> theEnumClass, String string, boolean exceptionOnNotFound, boolean exceptionIfInvalid) do a case-insensitive matchingstatic boolean
equalsIgnoreCase
(String str1, String str2) equalsignorecasestatic Field
get a field object for a class, potentially in superclassesstatic String
fileCanonicalPath
(File file) get canonical path of filestatic File
fileFromResourceName
(String resourceName) Deprecated.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 Class
Returns the class object.static String
getLocationFromResourceName
(String resourceName) get a file name from a resource namestatic boolean
injectInException
(Throwable t, String message) If we can, inject this into the exception, else return falsestatic 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 boolean
See if the input is null or if string, if it is empty or blank (whitespace)static Iterator
null safe iterator getter if the type if collectionstatic int
Null safe array length or mapstatic <T> List<T>
listFromCollection
(Collection<T> collection) null safe convert collection to liststatic 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 <T> T
newInstance
(Class<T> theClass) Construct a classstatic 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 boolean
nullOrBlank
(Object object) is an object null or blankstatic Properties
propertiesFromResourceName
(String resourceName) read properties from a resource, dont modify the properties returned since they are cachedstatic String
propertiesToString
(Properties properties) convert properties 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 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[]
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)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 Timestamp
stringToTimestamp
(String input) convert a string to timestamp based on the following formats: yyyyMMdd 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
subjectToString
(Subject subject) convert a subject to string safelystatic String
substituteExpressionLanguage
(String stringToParse, Map<String, Object> variableMap) substitute an EL for objectsstatic String
substituteExpressionLanguage
(String stringToParse, Map<String, Object> variableMap, boolean lenient) substitute an EL for objectsstatic String
timestampToString
(Date timestamp) Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSSstatic <T> List<T>
toList
(T... objects) return a list of objects from varargs.static <M> Set<M>
toSet
(M... inputs) convert an element to a setstatic String
toString
(InputStream input, String encoding) Get the contents of anInputStream
as a String.static String
toStringForLog
(Object object) print out various types of objectsstatic String
toStringForLog
(Object object, int maxChars) print out various types of objectsstatic Timestamp
toTimestamp
(Object input) Convert a string or object to a timestamp (could be string, date, timestamp, etc) yyyymmdd or yyyy/MM/dd HH:mm:ss or yyyy/MM/dd HH:mm:ss.SSS or yyyy/MM/dd HH:mm:ss.SSSSSSstatic String
trim whitespace from stringstatic <T> T
If necessary, convert an object to another type.static <T> T
typeCast
(Object value, Class<T> theClass, boolean convertNullToDefaultPrimitive, boolean useNewInstanceHooks) If necessary, convert an object to another type.
-
Field Details
-
DATE_FORMAT
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.
-
-
Constructor Details
-
SubjectUtils
public SubjectUtils()
-
-
Method Details
-
enumValueOfIgnoreCase
public static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound) throws RuntimeException do a case-insensitive matching- Type Parameters:
E
- generic type- Parameters:
theEnumClass
- class of the enumstring
-exceptionOnNotFound
- true if exception should be thrown on not found- Returns:
- the enum or null or exception if not found
- Throws:
RuntimeException
- if there is a problem
-
equalsIgnoreCase
equalsignorecase- Parameters:
str1
-str2
-- Returns:
- true if the strings are equal ignore case
-
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
-
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
-
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
-
enumValueOfIgnoreCase
public static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound, boolean exceptionIfInvalid) throws RuntimeException do a case-insensitive matching- Type Parameters:
E
- generic type- Parameters:
theEnumClass
- class of the enumstring
-exceptionOnNotFound
- true if exception should be thrown on not foundexceptionIfInvalid
- if there is a string, but it is invalid, if should throw exception- Returns:
- the enum or null or exception if not found
- Throws:
RuntimeException
- if there is a problem
-
injectInException
If we can, inject this into the exception, else return false- Parameters:
t
-message
-- Returns:
- true if success, false if not
-
assignField
public static void assignField(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, boolean callOnSupers, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride) assign data to a field- Parameters:
theClass
- the class which has the methodinvokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- datacallOnSupers
- if static and method not exists, try on supersoverrideSecurity
- true to call on protected or private etc methodstypeCast
- true if we should typecastannotationWithValueOverride
- annotation with value of override
-
assignField
public static void assignField(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, Class<? extends Annotation> annotationWithValueOverride) assign data to a field. Will find the field in superclasses, will typecast, and will override security (private, protected, etc)- Parameters:
theClass
- the class which has the methodinvokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- dataannotationWithValueOverride
- annotation with value of override
-
assignField
public static void assignField(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast) assign data to a field- Parameters:
field
- is the field to assign toinvokeOn
- to call on or null for staticdataToAssign
- dataoverrideSecurity
- true to call on protected or private etc methodstypeCast
- true if we should typecast
-
assignField
public static void assignField(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride) assign data to a field- Parameters:
field
- is the field to assign toinvokeOn
- to call on or null for staticdataToAssign
- dataoverrideSecurity
- true to call on protected or private etc methodstypeCast
- true if we should typecastannotationWithValueOverride
- annotation with value of override, or null if none
-
assignField
assign data to a field. Will find the field in superclasses, will typecast, and will override security (private, protected, etc)- Parameters:
invokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- data
-
field
public static Field field(Class theClass, String fieldName, boolean callOnSupers, boolean throwExceptionIfNotFound) get a field object for a class, potentially in superclasses- Parameters:
theClass
-fieldName
-callOnSupers
- true if superclasses should be looked in for the fieldthrowExceptionIfNotFound
- will throw runtime exception if not found- Returns:
- the field object or null if not found (or exception if param is set)
-
typeCast
If necessary, convert an object to another type. if type is Object.class, just return the input. Do not convert null to an empty primitive- Type Parameters:
T
- is template type- Parameters:
value
-theClass
-- Returns:
- the object of that instance converted into something else
-
typeCast
public static <T> T typeCast(Object value, Class<T> theClass, boolean convertNullToDefaultPrimitive, boolean useNewInstanceHooks) If necessary, convert an object to another type. if type is Object.class, just return the input- Type Parameters:
T
- is the type to return- Parameters:
value
-theClass
-convertNullToDefaultPrimitive
- if the value is null, and theClass is primitive, should we convert the null to a primitive default valueuseNewInstanceHooks
- if theClass is not recognized, then honor the string "null", "newInstance", or get a constructor with one param, and call it- Returns:
- the object of that instance converted into something else
-
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
-
isBlank
See if the input is null or if string, if it is empty or blank (whitespace)- Parameters:
input
-- Returns:
- true if blank
-
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
-
stringValue
convert a date to the standard string yyyymmdd- Parameters:
date
-- Returns:
- the string value
-
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
-
toString
Get the contents of anInputStream
as a String.- Parameters:
input
- theInputStream
to read fromencoding
- The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.- Returns:
- the requested
String
- Throws:
IOException
- In case of an I/O problem
-
toTimestamp
Convert a string or object to a timestamp (could be string, date, timestamp, etc) yyyymmdd 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
-
className
null safe classname method, gets the unenhanced name- Parameters:
object
-- Returns:
- the classname
-
classNameCollection
null safe classname method, max out at 20- Parameters:
object
-- Returns:
- the classname
-
bigDecimalObjectValue
Convert an object to a byte, allow nulls- Parameters:
input
-- Returns:
- the boolean object value
-
booleanObjectValue
get the Boolean value for an object- Parameters:
object
-- Returns:
- the Boolean or null if null or empty
-
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
-
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
-
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
-
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
-
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
-
forName
Returns the class object.
- Parameters:
origClassName
- is fully qualified- Returns:
- the class
-
newInstance
Construct a class- Type Parameters:
T
- template type- Parameters:
theClass
-- Returns:
- the instance
-
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
-
copy
Copy chars from aReader
to aWriter
.- Parameters:
input
- theReader
to read fromoutput
- theWriter
to write to- Returns:
- the number of characters copied
- Throws:
IOException
- In case of an I/O problem
-
copy
Copy and convert bytes from anInputStream
to chars on aWriter
, using the specified encoding.- Parameters:
input
- theInputStream
to read fromoutput
- theWriter
to write toencoding
- The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.- Throws:
IOException
- In case of an I/O problem
-
stringToTimestamp
convert a string to timestamp based on the following formats: yyyyMMdd 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
-
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
-
nullOrBlank
is an object null or blank- Parameters:
object
-- Returns:
- true if null or blank
-
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
-
defaultIfBlank
return the string or the other if the first is blank- Parameters:
string
-defaultStringIfBlank
-- Returns:
- the string or the default one
-
propertiesFromResourceName
read properties from a resource, dont modify the properties returned since they are cached- Parameters:
resourceName
-- Returns:
- the properties
-
computeUrl
compute a url of a resource- Parameters:
resourceName
-canBeNull
- if cant be null, throw runtime- Returns:
- the URL
-
classLoader
fast class loader- Returns:
- the class loader
-
closeQuietly
close a connection null safe and dont throw exception- Parameters:
connection
-
-
closeQuietly
Unconditionally close anInputStream
. Equivalent toInputStream.close()
, except any exceptions will be ignored.- Parameters:
input
- A (possibly null) InputStream
-
closeQuietly
Unconditionally close anOutputStream
. Equivalent toOutputStream.close()
, except any exceptions will be ignored.- Parameters:
output
- A (possibly null) OutputStream
-
closeQuietly
Unconditionally close anReader
. Equivalent toReader.close()
, except any exceptions will be ignored.- Parameters:
input
- A (possibly null) Reader
-
closeQuietly
close a resultSet null safe and dont throw exception- Parameters:
resultSet
-
-
closeQuietly
close a statement null safe and dont throw exception- Parameters:
statement
-
-
closeQuietly
close a writer quietly- Parameters:
writer
-
-
fileFromResourceName
Deprecated.get a file name from a resource name- Parameters:
resourceName
- is the classpath location- Returns:
- the file path on the system
-
getLocationFromResourceName
get a file name from a resource name- Parameters:
resourceName
- is the classpath location- Returns:
- Full path to the resource. For files, the file path on the system; otherwise, the resource URL
-
fileCanonicalPath
get canonical path of file- Parameters:
file
-- Returns:
- the path
-
substituteExpressionLanguage
public static String substituteExpressionLanguage(String stringToParse, Map<String, Object> variableMap) substitute an EL for objects- Parameters:
stringToParse
-variableMap
-- Returns:
- the string
-
substituteExpressionLanguage
public static String substituteExpressionLanguage(String stringToParse, Map<String, Object> variableMap, boolean lenient) substitute an EL for objects- Parameters:
stringToParse
-variableMap
-lenient
-- Returns:
- the string
-
assertion
If false, throw an assertException, and give a reason- Parameters:
isTrue
-reason
-
-
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
-
trim
trim whitespace from string- Parameters:
str
-- Returns:
- trimmed string
-
toSet
convert an element to a set- Type Parameters:
M
-- Parameters:
m
-- Returns:
-
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
-
mapToString
convert a set to a string (comma separate)- Parameters:
map
-- Returns:
- the String
-
propertiesToString
convert properties to a string (comma separate)- Parameters:
properties
-- Returns:
- the String
-
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
-
subjectToString
convert a subject to string safely- Parameters:
subject
-- Returns:
- the string value of subject (might be null)
-
listFromCollection
null safe convert collection to list- Type Parameters:
T
-- Parameters:
collection
-- Returns:
- the list
-
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 list- Type Parameters:
T
-- Parameters:
list
-- Returns:
- the list or empty list 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
-
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 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
-
compare
compare null safe- Parameters:
first
-second
-- Returns:
- 0 for equal, 1 for greater, -1 for less
-