public class SubjectUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DATE_FORMAT
string format of dates
|
static String |
DATE_MINUTES_SECONDS_FORMAT
format including minutes and seconds: yyyy/MM/dd HH:mm:ss
|
static String |
DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
format including minutes and seconds: yyyyMMdd HH:mm:ss
|
static int |
DEFAULT_BUFFER_SIZE
The name says it all.
|
static String[] |
EMPTY_STRING_ARRAY
An empty immutable
String array. |
static int |
NOT_FOUND
special number when a number is not found
|
static String |
TIMESTAMP_FORMAT
format on screen of config for milestone: yyyy/MM/dd HH:mm:ss.SSS
|
static String |
TIMESTAMP_NO_SLASH_FORMAT
format on screen of config for milestone: yyyyMMdd HH:mm:ss.SSS
|
Constructor and Description |
---|
SubjectUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
assertion(boolean isTrue,
String reason)
If false, throw an assertException, and give a reason
|
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
|
static void |
assignField(Class theClass,
Object invokeOn,
String fieldName,
Object dataToAssign,
Class<? extends Annotation> annotationWithValueOverride)
assign data to a field.
|
static void |
assignField(Field field,
Object invokeOn,
Object dataToAssign,
boolean overrideSecurity,
boolean typeCast)
assign data to a field
|
static void |
assignField(Field field,
Object invokeOn,
Object dataToAssign,
boolean overrideSecurity,
boolean typeCast,
Class<? extends Annotation> annotationWithValueOverride)
assign data to a field
|
static void |
assignField(Object invokeOn,
String fieldName,
Object dataToAssign)
assign data to a field.
|
static <T> List<T> |
batchList(List<T> collection,
int batchSize,
int batchIndex)
retrieve a batch by 0 index.
|
static int |
batchNumberOfBatches(Collection<?> collection,
int batchSize)
If batching this is the number of batches
|
static int |
batchNumberOfBatches(int count,
int batchSize)
If batching this is the number of batches
|
static BigDecimal |
bigDecimalObjectValue(Object input)
Convert an object to a byte, allow nulls
|
static Boolean |
booleanObjectValue(Object object)
get the Boolean value for an object
|
static boolean |
booleanValue(Object object)
get the boolean value for an object, cant be null or blank
|
static boolean |
booleanValue(Object object,
boolean defaultBoolean)
get the boolean value for an object
|
static Byte |
byteObjectValue(Object input)
Convert an object to a byte, allow nulls
|
static byte |
byteValue(Object input)
convert an object to a byte
|
static Character |
charObjectValue(Object input)
get the Character wrapper value for the input
|
static char |
charValue(Object input)
convert an object to a char
|
static ClassLoader |
classLoader()
fast class loader
|
static String |
className(Object object)
null safe classname method, gets the unenhanced name
|
static String |
classNameCollection(Object object)
null safe classname method, max out at 20
|
static void |
closeQuietly(Connection connection)
close a connection null safe and dont throw exception
|
static void |
closeQuietly(InputStream input)
Unconditionally close an
InputStream . |
static void |
closeQuietly(OutputStream output)
Unconditionally close an
OutputStream . |
static void |
closeQuietly(Reader input)
Unconditionally close an
Reader . |
static void |
closeQuietly(ResultSet resultSet)
close a resultSet null safe and dont throw exception
|
static void |
closeQuietly(Statement statement)
close a statement null safe and dont throw exception
|
static void |
closeQuietly(Writer writer)
close a writer quietly
|
static int |
compare(Comparable first,
Comparable second)
compare null safe
|
static URL |
computeUrl(String resourceName,
boolean canBeNull)
compute a url of a resource
|
static void |
copy(InputStream input,
Writer output,
String encoding)
Copy and convert bytes from an
InputStream to chars on a
Writer , using the specified encoding. |
static int |
copy(Reader input,
Writer output)
Copy chars from a
Reader to a Writer . |
static Date |
dateValue(Object inputObject)
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 blank
|
static <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 object
|
static double |
doubleValue(Object input)
get the double value of an object
|
static double |
doubleValueNoError(Object input)
get the double value of an object, do not throw an
exception if there is an
error
|
static <E extends Enum<?>> |
enumValueOfIgnoreCase(Class<E> theEnumClass,
String string,
boolean exceptionOnNotFound)
do a case-insensitive matching
|
static <E extends Enum<?>> |
enumValueOfIgnoreCase(Class<E> theEnumClass,
String string,
boolean exceptionOnNotFound,
boolean exceptionIfInvalid)
do a case-insensitive matching
|
static boolean |
equalsIgnoreCase(String str1,
String str2)
equalsignorecase
|
static Field |
field(Class theClass,
String fieldName,
boolean callOnSupers,
boolean throwExceptionIfNotFound)
get a field object for a class, potentially in superclasses
|
static String |
fileCanonicalPath(File file)
get canonical path of file
|
static File |
fileFromResourceName(String resourceName)
get a file name from a resource name
|
static Float |
floatObjectValue(Object input,
boolean allowNullBlank)
get the Float value of an object
|
static float |
floatValue(Object input)
get the float value of an object
|
static float |
floatValueNoError(Object input)
get the float value of an object, do not throw an exception if there is an
error
|
static Class |
forName(String origClassName)
Returns the class object.
|
static boolean |
injectInException(Throwable t,
String message)
If we can, inject this into the exception, else return false
|
static Integer |
intObjectValue(Object input,
boolean allowNullBlank)
get the Integer value of an object
|
static int |
intValue(Object input)
convert an object to a int
|
static int |
intValue(Object input,
int valueIfNull)
convert an object to a int
|
static int |
intValueNoError(Object input)
get the int value of an object, do not throw an exception if there is an
error
|
static boolean |
isBlank(Object input)
See if the input is null or if string, if it is empty or blank (whitespace)
|
static Iterator |
iterator(Object collection)
null safe iterator getter if the type if collection
|
static int |
length(Object arrayOrCollection)
Null safe array length or map
|
static <T> List<T> |
listFromCollection(Collection<T> collection)
null safe convert collection to list
|
static Long |
longObjectValue(Object input,
boolean allowNullBlank)
get the Long value of an object
|
static long |
longValue(Object input)
convert an object to a long
|
static long |
longValue(Object input,
long valueIfNull)
convert an object to a long
|
static long |
longValueNoError(Object input)
get the long value of an object, do not throw an exception if there is an
error
|
static String |
mapToString(Map map)
convert a set to a string (comma separate)
|
static <T> T |
newInstance(Class<T> theClass)
Construct a class
|
static Object |
next(Object arrayOrCollection,
Iterator iterator,
int index)
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> |
nonNull(List<T> list)
make sure a list is non null.
|
static <K,V> Map<K,V> |
nonNull(Map<K,V> map)
make sure it is non null, if null, then give new map
|
static <T> Set<T> |
nonNull(Set<T> set)
make sure a list is non null.
|
static <T> T[] |
nonNull(T[] array,
Class<?> theClass)
make sure a array is non null.
|
static boolean |
nullOrBlank(Object object)
is an object null or blank
|
static Properties |
propertiesFromResourceName(String resourceName)
read properties from a resource, dont modify the properties returned since they are cached
|
static 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 short
|
static String[] |
split(String str)
Splits the provided text into an array, using whitespace as the
separator.
|
static String[] |
split(String str,
char separatorChar)
Splits the provided text into an array, separator specified.
|
static String[] |
split(String str,
String separatorChars)
Splits the provided text into an array, separators specified.
|
static String[] |
split(String str,
String separatorChars,
int max)
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[] |
splitTrim(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 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)
|
static Set<String> |
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.SSSSSS
|
static String |
stringValue(Date date)
convert a date to the standard string yyyymmdd
|
static String |
stringValue(Object input)
convert an object to a string
|
static String |
subjectToString(Subject subject)
convert a subject to string safely
|
static String |
substituteExpressionLanguage(String stringToParse,
Map<String,Object> variableMap)
substitute an EL for objects
|
static String |
substituteExpressionLanguage(String stringToParse,
Map<String,Object> variableMap,
boolean lenient)
substitute an EL for objects
|
static String |
timestampToString(Date timestamp)
Convert a timestamp into a string: yyyy/MM/dd HH:mm:ss.SSS
|
static <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 set
|
static String |
toString(InputStream input,
String encoding)
Get the contents of an
InputStream as a String. |
static String |
toStringForLog(Object object)
print out various types of objects
|
static String |
toStringForLog(Object object,
int maxChars)
print out various types of objects
|
static 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.SSSSSS
|
static String |
trim(String str)
trim whitespace from string
|
static <T> T |
typeCast(Object value,
Class<T> theClass)
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.
|
public static final String DATE_FORMAT
public static final String DATE_MINUTES_SECONDS_FORMAT
public static final String DATE_MINUTES_SECONDS_NO_SLASH_FORMAT
public static final String TIMESTAMP_FORMAT
public static final String TIMESTAMP_NO_SLASH_FORMAT
public static final int NOT_FOUND
public static final int DEFAULT_BUFFER_SIZE
public static final String[] EMPTY_STRING_ARRAY
String
array.public static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound) throws RuntimeException
E
- generic typetheEnumClass
- class of the enumstring
- exceptionOnNotFound
- true if exception should be thrown on not foundRuntimeException
- if there is a problempublic static boolean equalsIgnoreCase(String str1, String str2)
str1
- str2
- public static String[] splitTrim(String input, String separator)
input
- is the delimited input to split and trimseparator
- is what to split onpublic static Set<String> splitTrimToSet(String input, String separator)
input
- is the delimited input to split and trimseparator
- is what to split onpublic static String[] splitTrim(String input, String separator, boolean treatAdjacentSeparatorsAsOne)
input
- is the delimited input to split and trimseparator
- is what to split ontreatAdjacentSeparatorsAsOne
- public static String[] splitByWholeSeparator(String str, String separator)
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 returns null
.
A null
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"]
str
- the String to parse, may be nullseparator
- String containing the String to be used as a delimiter,
null
splits on whitespacenull
if null String was inputpublic static String[] splitByWholeSeparator(String str, String separator, int max)
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 returns null
.
A null
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"]
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.null
if null String was inputpublic static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound, boolean exceptionIfInvalid) throws RuntimeException
E
- generic typetheEnumClass
- 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 exceptionRuntimeException
- if there is a problempublic static boolean injectInException(Throwable t, String message)
t
- message
- public static void assignField(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, boolean callOnSupers, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride)
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 overridepublic static void assignField(Class theClass, Object invokeOn, String fieldName, Object dataToAssign, Class<? extends Annotation> annotationWithValueOverride)
theClass
- the class which has the methodinvokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- dataannotationWithValueOverride
- annotation with value of overridepublic static void assignField(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast)
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 typecastpublic static void assignField(Field field, Object invokeOn, Object dataToAssign, boolean overrideSecurity, boolean typeCast, Class<? extends Annotation> annotationWithValueOverride)
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 nonepublic static void assignField(Object invokeOn, String fieldName, Object dataToAssign)
invokeOn
- to call on or null for staticfieldName
- method name to calldataToAssign
- datapublic static Field field(Class theClass, String fieldName, boolean callOnSupers, boolean throwExceptionIfNotFound)
theClass
- fieldName
- callOnSupers
- true if superclasses should be looked in for the fieldthrowExceptionIfNotFound
- will throw runtime exception if not foundpublic static <T> T typeCast(Object value, Class<T> theClass)
T
- is template typevalue
- theClass
- public static <T> T typeCast(Object value, Class<T> theClass, boolean convertNullToDefaultPrimitive, boolean useNewInstanceHooks)
T
- is the type to returnvalue
- 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 itpublic static Date dateValue(Object inputObject)
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
inputObject
- is the String or Date to convertpublic static boolean isBlank(Object input)
input
- public static Integer intObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- true if convert null or blank to nullpublic static int intValue(Object input)
input
- public static int intValue(Object input, int valueIfNull)
input
- valueIfNull
- is if the input is null or empty, return this valuepublic static int intValueNoError(Object input)
input
- is a number or Stringpublic static String stringValue(Date date)
date
- public static String stringValue(Object input)
input
- is the object to convertpublic static String timestampToString(Date timestamp)
timestamp
- public static String toString(InputStream input, String encoding) throws IOException
InputStream
as a String.input
- the InputStream
to read fromencoding
- The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.String
IOException
- In case of an I/O problempublic static 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.SSSSSS
input
- RuntimeException
- if invalid formatpublic static String className(Object object)
object
- public static String classNameCollection(Object object)
object
- public static BigDecimal bigDecimalObjectValue(Object input)
input
- public static Boolean booleanObjectValue(Object object)
object
- public static boolean booleanValue(Object object)
object
- public static boolean booleanValue(Object object, boolean defaultBoolean)
object
- defaultBoolean
- if object is null or emptypublic static Byte byteObjectValue(Object input)
input
- public static byte byteValue(Object input)
input
- public static Character charObjectValue(Object input)
input
- allow null, return nullpublic static char charValue(Object input)
input
- public static Double doubleObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- used to default to false, if true, return null if nul inputtedpublic static double doubleValue(Object input)
input
- is a number or Stringpublic static double doubleValueNoError(Object input)
input
- is a number or Stringpublic static Float floatObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- true if allow null or blankpublic static float floatValue(Object input)
input
- is a number or Stringpublic static float floatValueNoError(Object input)
input
- is a number or Stringpublic static Long longObjectValue(Object input, boolean allowNullBlank)
input
- is a number or StringallowNullBlank
- true if null or blank converts to nullpublic static long longValue(Object input)
input
- public static long longValue(Object input, long valueIfNull)
input
- valueIfNull
- is if the input is null or empty, return this valuepublic static long longValueNoError(Object input)
input
- is a number or Stringpublic static Short shortObjectValue(Object input)
input
- is a number or Stringpublic static short shortValue(Object input)
input
- public static Class forName(String origClassName)
Returns the class object.
origClassName
- is fully qualifiedpublic static <T> T newInstance(Class<T> theClass)
T
- template typetheClass
- public static String toStringForLog(Object object)
object
- public static String toStringForLog(Object object, int maxChars)
object
- maxChars
- is the max chars that should be returned (abbreviate if longer), or -1 for any amountpublic static int copy(Reader input, Writer output) throws IOException
Reader
to a Writer
.input
- the Reader
to read fromoutput
- the Writer
to write toIOException
- In case of an I/O problempublic static void copy(InputStream input, Writer output, String encoding) throws IOException
InputStream
to chars on a
Writer
, using the specified encoding.input
- the InputStream
to read fromoutput
- the Writer
to write toencoding
- The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.IOException
- In case of an I/O problempublic 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.SSSSSS
input
- public static Iterator iterator(Object collection)
collection
- public static int length(Object arrayOrCollection)
arrayOrCollection
- public static Object next(Object arrayOrCollection, Iterator iterator, int index)
arrayOrCollection
- iterator
- index
- public static boolean nullOrBlank(Object object)
object
- public static <T> T defaultIfNull(T theValue, T defaultIfTheValueIsNull)
T
- theValue
- first inputdefaultIfTheValueIsNull
- second inputpublic static String defaultIfBlank(String string, String defaultStringIfBlank)
string
- defaultStringIfBlank
- public static Properties propertiesFromResourceName(String resourceName)
resourceName
- public static URL computeUrl(String resourceName, boolean canBeNull)
resourceName
- canBeNull
- if cant be null, throw runtimepublic static ClassLoader classLoader()
public static void closeQuietly(Connection connection)
connection
- public static void closeQuietly(InputStream input)
InputStream
.
Equivalent to InputStream.close()
, except any exceptions will be ignored.input
- A (possibly null) InputStreampublic static void closeQuietly(OutputStream output)
OutputStream
.
Equivalent to OutputStream.close()
, except any exceptions will be ignored.output
- A (possibly null) OutputStreampublic static void closeQuietly(Reader input)
Reader
.
Equivalent to Reader.close()
, except any exceptions will be ignored.input
- A (possibly null) Readerpublic static void closeQuietly(ResultSet resultSet)
resultSet
- public static void closeQuietly(Statement statement)
statement
- public static void closeQuietly(Writer writer)
writer
- public static File fileFromResourceName(String resourceName)
resourceName
- is the classpath locationpublic static String fileCanonicalPath(File file)
file
- public static String substituteExpressionLanguage(String stringToParse, Map<String,Object> variableMap)
stringToParse
- variableMap
- public static String substituteExpressionLanguage(String stringToParse, Map<String,Object> variableMap, boolean lenient)
stringToParse
- variableMap
- lenient
- public static void assertion(boolean isTrue, String reason)
isTrue
- reason
- public static String[] split(String str)
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 returns null
.
StringUtils.split(null) = null StringUtils.split("") = [] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split(" abc ") = ["abc"]
str
- the String to parse, may be nullnull
if null String inputpublic static String[] split(String str, char separatorChar)
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 returns null
.
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"]
str
- the String to parse, may be nullseparatorChar
- the character used as the delimiter,
null
splits on whitespacenull
if null String inputpublic static String[] split(String str, String separatorChars)
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 returns null
.
A null
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"]
str
- the String to parse, may be nullseparatorChars
- the characters used as the delimiters,
null
splits on whitespacenull
if null String inputpublic static String[] split(String str, String separatorChars, int max)
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 returns null
.
A null
separatorChars splits on whitespace.
If more than max
delimited substrings are found, the last
returned string includes all characters after the first max - 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"]
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 limitnull
if null String inputpublic static String trim(String str)
str
- public static <M> Set<M> toSet(M... inputs)
M
- m
- public static int batchNumberOfBatches(Collection<?> collection, int batchSize)
collection
- batchSize
- public static int batchNumberOfBatches(int count, int batchSize)
count
- is size of setbatchSize
- public static <T> List<T> batchList(List<T> collection, int batchSize, int batchIndex)
T
- template typecollection
- batchSize
- batchIndex
- public static String mapToString(Map map)
map
- public static String propertiesToString(Properties properties)
properties
- public static <T> List<T> toList(T... objects)
T
- template type of the objectsobjects
- public static String subjectToString(Subject subject)
subject
- public static <T> List<T> listFromCollection(Collection<T> collection)
T
- collection
- public static <T> Collection<T> nonNull(Collection<T> list)
T
- list
- public static <T> List<T> nonNull(List<T> list)
T
- list
- public static <K,V> Map<K,V> nonNull(Map<K,V> map)
K
- key of mapV
- value of mapmap
- is mappublic static <T> Set<T> nonNull(Set<T> set)
T
- set
- public static <T> T[] nonNull(T[] array, Class<?> theClass)
T
- array
- theClass
- to make array frompublic static int compare(Comparable first, Comparable second)
first
- second
- Copyright © 2016 Internet2. All rights reserved.