Class StringUtils
java.lang.Object
org.deltava.util.StringUtils
A String utility class.
- Since:
- 1.0
- Version:
- 10.3
- Author:
- Luke
-
Method Summary
Modifier and TypeMethodDescriptionstatic intarrayIndexOf(String[] values, String value) Returns the index of a value within an array of Strings.static intarrayIndexOf(String[] values, String value, int defaultValue) Returns the index of a value within an array of Strings.static StringEscapes single and double quotes in a string with a leading backslash.static StringFilters a string by passing in a character filtering Predicate.static StringFormats a floating-point number into a string using a particular pattern.static StringFormats an integer into a string using a particular pattern.static StringFormats a date/time into a string using a particular pattern.static StringFormats a date into a string using a particular pattern.static Stringformat(ZonedDateTime dt, String fmtPattern) Formats a date/time into a string using a particular pattern.static Stringformat(GeoLocation loc, boolean asHTML, int formatMask) Formats a Latitude/Longitude pair.static StringformatHex(long value) Converts a number to a hexadecimal value by prepending "0x" and converting to hexadecimal.static StringgetPropertyMethod(String pName) Returns the method name used to retrieve a particular property value.getURLParameters(String url) Returns the query parameters on a URL.static booleanA null-safe mechanism to check if a String is null or empty.static StringlistConcat(Collection<?> values, String delim) Concatenates a collection of Strings into a single delimited String.nullTrim(Collection<String> s) Trims a Collection of Strings, removing elements if the string is empty.static doubleParses a string and converts into a floating-point number.static intParses a string and converts into a 32-bit integer.static longParses a string and converts into a 64-bit integer.static CSVTokensParses a line of CSV-fomratted text.static InstantparseEpoch(String dt) Parses an epoch Date.static intParses a string that may be in hexadecimal.static InstantparseInstant(String dt, String fmt) Parses a date using a given format pattern.static ZonedDateTimeparseLocal(String dt, String fmt, ZoneId tz) Parses a date using a given format pattern.static InstantHelper method to parse RFC3339 date strings.static StringproperCase(String s) Converts a string to "proper case".static StringRemoves leading and trailing double-quotes from a CSV string etntity.Splits a delimited String into a List of elements.static Stringstrip(CharSequence s, String chars) Strips out specific charaters from a string.static StringStrips out inline HTML in a string by replacing < and > with<and>.
-
Method Details
-
isEmpty
A null-safe mechanism to check if a String is null or empty.- Parameters:
s- the String to check- Returns:
- TRUE if s is null or empty, otherwise FALSE
-
removeCSVQuotes
-
escapeQuotes
Escapes single and double quotes in a string with a leading backslash.- Parameters:
s- the string- Returns:
- the escaped string
- Throws:
NullPointerException- if s is null
-
properCase
Converts a string to "proper case".- Parameters:
s- the string to convert- Returns:
- the converted string
- Throws:
NullPointerException- if the string is null
-
filter
-
stripInlineHTML
-
listConcat
Concatenates a collection of Strings into a single delimited String.- Parameters:
values- the List of valuesdelim- the value delimiter- Returns:
- the delimited value stirng
-
getPropertyMethod
Returns the method name used to retrieve a particular property value. This conforms to the Java Bean specification by prepending the string "get" to the property name, and converting the first character of the property name to uppercase.- Parameters:
pName- the property name- Returns:
- the name of the get method for this property
-
parseHex
Parses a string that may be in hexadecimal. If the string starts with "0x", it is treated as a hex string, otherwise it is parsed as a regular number.- Parameters:
hexValue- the number to parse- Returns:
- the value
- Throws:
NumberFormatException- if hexValue cannot be converted to a number
-
parse
Parses a string and converts into a 32-bit integer.- Parameters:
value- the value to convertdefaultValue- the default value- Returns:
- the value parsed into a number, or the default value if conversion fails
-
parse
Parses a string and converts into a 64-bit integer.- Parameters:
value- the value to convertdefaultValue- the default valueisUnsigned- TRUE to treat as an unsigned integer, otherwise FALSE- Returns:
- the value parsed into a number, or the default value if conversion fails
-
parse
Parses a string and converts into a floating-point number.- Parameters:
value- the value to convertdefaultValue- the default value- Returns:
- the value parsed into a number, or the default value if conversion fails
-
parseInstant
-
parseLocal
Parses a date using a given format pattern.- Parameters:
dt- the date to parsefmt- the format patterntz- the ZoneId- Returns:
- the parsed Date
- See Also:
-
parseEpoch
-
parseRFC3339Date
Helper method to parse RFC3339 date strings.- Parameters:
dt- the date/time string- Returns:
- a Date
- Throws:
IllegalArgumentException- if the date/time is not in RFC3339 format
-
formatHex
Converts a number to a hexadecimal value by prepending "0x" and converting to hexadecimal.- Parameters:
value- the number to convert- Returns:
- the hexadecimal value
- See Also:
-
arrayIndexOf
-
arrayIndexOf
Returns the index of a value within an array of Strings.- Parameters:
values- the array of Stringsvalue- the String to search fordefaultValue- the default value to return if not found- Returns:
- the offset of the value in the array, or defaultValue if not found
-
split
-
format
Formats a Latitude/Longitude pair.- Parameters:
loc- the locationasHTML- TRUE if HTML formatting to be used, otherwise FALSEformatMask- bitmask specifying the portion to format- Returns:
- a formatted latitude/longitude
- See Also:
-
format
-
format
-
format
-
format
-
format
Formats a date/time into a string using a particular pattern.- Parameters:
dt- the date/timefmtPattern- the formatter pattern- Returns:
- the formatted date/time
-
strip
Strips out specific charaters from a string.- Parameters:
s- the input stringchars- the characters to remove- Returns:
- the string with no characters specified in chars
-
nullTrim
Trims a Collection of Strings, removing elements if the string is empty.- Parameters:
s- the Collection of Strings to trim- Returns:
- a List of Strings
-
getURLParameters
-
parseCSV
-