Class StringUtils
java.lang.Object
org.datanucleus.util.StringUtils
Utilities for String manipulation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareStringsEqual(String str1, String str2) Utility to tell if two strings are the same.static StringbooleanArrayToString(boolean[] ba) Utility to convert a boolean[] to a String.static StringcollectionToString(Collection coll) Converts the given collection of objects to string as a comma-separated list.Converts the input comma-separated string into a Set of the individual strings, with each string trimmed and converted to UPPERCASE.static StringFormats the given BigDecimal value into a floating-point literal (like we find in SQL).static StringgetDecodedStringFromURLString(String urlString) Convenience method to decode a URL string for use (so spaces are allowed)static StringgetEncodedURLStringFromString(String string) Convenience method to encode a URL string for use (so spaces are allowed)static FilegetFileForFilename(String filename) Convenience method to get a File for the specified filename.static JarFilegetJarFileForFilename(String filename) Convenience method to get a JarFile for the specified filename.static StringConvenience method to take a throwable and navigate up to the root cause and return the message of the root cause.static StringgetNameOfClass(Class cls) static StringgetStringFromException(Throwable exception) Gets a String message from an Exception.static StringConvert an exception to a String with full stack tracestatic StringintArrayToString(int[] ia) Utility to convert an int[] to a String.static booleancheck string is null or length is 0.static booleanisWhitespace(String str) Utility to check if a string is whitespace.static StringleftAlignedPaddedString(String input, int length) Utility to return a left-aligned version of a string padded to the number of characters specified.static StringmapToString(Map map) Converts the given map of objects to string as a comma-separated list.static booleancheck string is not null and length > 0.static StringobjectArrayToString(Object[] arr) Utility to convert an Object[] to a String.static StringMethod to return the input string with all special tags (end-of-line, tab, etc) replaced by spaces.static StringreplaceAll(String theString, String toReplace, String replacement) A more efficient version thanString.replace(CharSequence, CharSequence)which uses Regex for the implementation and requires compilation for every execution.static StringrightAlignedPaddedString(String input, int length) Utility to return a right-aligned version of a string padded to the number of characters specified.static String[]Splits a list of values separated by a tokenstatic StringtoJVMIDString(Object obj) Utility to convert an object to a JVM type string.
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
getMessageFromRootCauseOfThrowable
-
getStringFromStackTrace
-
getFileForFilename
-
getJarFileForFilename
Convenience method to get a JarFile for the specified filename. Caters for URL-encoded characters in the filename (treatment of spaces on Windows etc)- Parameters:
filename- Name of file- Returns:
- The JarFile
- Throws:
IOException- if there is a problem opening the JarFile
-
getDecodedStringFromURLString
-
getEncodedURLStringFromString
-
replaceAll
A more efficient version thanString.replace(CharSequence, CharSequence)which uses Regex for the implementation and requires compilation for every execution.- Parameters:
theString- The string to usetoReplace- The string to replace.replacement- The replacement string.- Returns:
- The updated string after replacing.
-
isWhitespace
Utility to check if a string is whitespace. If the string is null, returns true also.- Parameters:
str- The string to check- Returns:
- Whether the string is just whitespace
-
areStringsEqual
-
leftAlignedPaddedString
-
rightAlignedPaddedString
-
split
-
convertCommaSeparatedStringToSet
Converts the input comma-separated string into a Set of the individual strings, with each string trimmed and converted to UPPERCASE.- Parameters:
str- The input string- Returns:
- Set of the comma-separated strings that it is comprised of
-
toJVMIDString
-
booleanArrayToString
Utility to convert a boolean[] to a String.- Parameters:
ba- The boolean[]- Returns:
- String version
-
intArrayToString
Utility to convert an int[] to a String.- Parameters:
ia- The int[]- Returns:
- String version
-
objectArrayToString
-
collectionToString
Converts the given collection of objects to string as a comma-separated list. If the list is empty the string "<none>" is returned.- Parameters:
coll- collection of objects to be converted- Returns:
- A string containing each object in the given collection, converted toString() and separated by commas.
-
getNameOfClass
-
mapToString
Converts the given map of objects to string as a comma-separated list. If the map is empty the string "<none>" is returned.- Parameters:
map- Map to be converted- Returns:
- A string containing each object in the given map, converted toString() and separated by commas.
-
isEmpty
check string is null or length is 0.- Parameters:
s- check string- Returns:
- return true if string is null or length is 0. return false other case.
-
notEmpty
check string is not null and length > 0.- Parameters:
s- check string- Returns:
- return true if string isnot null and length greater than 0. return false other case.
-
exponentialFormatBigDecimal
Formats the given BigDecimal value into a floating-point literal (like we find in SQL). BigDecimal.toString() is not well suited to this purpose because it never uses E-notation, which causes some values with large exponents to be output as long strings with tons of zeroes in them.- Parameters:
bd- The number to format.- Returns:
- The formatted String.
-
removeSpecialTagsFromString
-
getStringFromException
-