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 int
arrayIndexOf
(String[] values, String value) Returns the index of a value within an array of Strings.static int
arrayIndexOf
(String[] values, String value, int defaultValue) Returns the index of a value within an array of Strings.static String
Escapes single and double quotes in a string with a leading backslash.static String
Filters a string by passing in a character filtering Predicate.static String
Formats a floating-point number into a string using a particular pattern.static String
Formats an integer into a string using a particular pattern.static String
Formats a date/time into a string using a particular pattern.static String
Formats a date into a string using a particular pattern.static String
format
(ZonedDateTime dt, String fmtPattern) Formats a date/time into a string using a particular pattern.static String
format
(GeoLocation loc, boolean asHTML, int formatMask) Formats a Latitude/Longitude pair.static String
formatHex
(long value) Converts a number to a hexadecimal value by prepending "0x" and converting to hexadecimal.static String
getPropertyMethod
(String pName) Returns the method name used to retrieve a particular property value.getURLParameters
(String url) Returns the query parameters on a URL.static boolean
A null-safe mechanism to check if a String is null or empty.static String
listConcat
(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 double
Parses a string and converts into a floating-point number.static int
Parses a string and converts into a 32-bit integer.static long
Parses a string and converts into a 64-bit integer.static CSVTokens
Parses a line of CSV-fomratted text.static Instant
parseEpoch
(String dt) Parses an epoch Date.static int
Parses a string that may be in hexadecimal.static Instant
parseInstant
(String dt, String fmt) Parses a date using a given format pattern.static ZonedDateTime
parseLocal
(String dt, String fmt, ZoneId tz) Parses a date using a given format pattern.static Instant
Helper method to parse RFC3339 date strings.static String
properCase
(String s) Converts a string to "proper case".static String
Removes leading and trailing double-quotes from a CSV string etntity.Splits a delimited String into a List of elements.static String
strip
(CharSequence s, String chars) Strips out specific charaters from a string.static String
Strips 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
-