@ThreadSafe public final class Strings extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Strings.CharacterPredicate
Represents a predicate (boolean-valued function) of one character argument.
|
static class |
Strings.Justify |
| Modifier | Constructor and Description |
|---|---|
private |
Strings() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
asBoolean(String value,
boolean defaultValue)
Parse the supplied string as a boolean value.
|
static double |
asDouble(String value,
double defaultValue)
Parse the supplied string as a double value.
|
static int |
asInt(String value,
int defaultValue)
Parse the supplied string as a integer value.
|
static long |
asLong(String value,
long defaultValue)
Parse the supplied string as a long value.
|
static int |
compareTo(CharSequence str1,
CharSequence str2)
Compare two
CharSequence instances. |
static String |
createString(char charToRepeat,
int numberOfRepeats)
Create a new string containing the specified character repeated a specific number of times.
|
static String |
duration(long durationInMillis)
For the given duration in milliseconds, obtain a readable representation of the form
HHH:MM:SS.mmm, where
HHH
is the number of hours written in at least 2 digits (e.g., "03")
MM
is the number of hours written in at least 2 digits (e.g., "05")
SS
is the number of hours written in at least 2 digits (e.g., "09")
mmm
is the fractional part of seconds, written with 1-3 digits (any trailing zeros are dropped)
|
static String |
getStackTrace(Throwable throwable)
Get the stack trace of the supplied exception.
|
static String |
join(CharSequence delimiter,
int[] values)
Returns a new String composed of the supplied integer values joined together
with a copy of the specified
delimiter. |
static String |
justify(Strings.Justify justify,
String str,
int width,
char padWithChar)
Justify the contents of the string.
|
static String |
justifyCenter(String str,
int width,
char padWithChar)
Center the contents of the string.
|
static String |
justifyLeft(String str,
int width,
char padWithChar)
Left justify the contents of the string, ensuring that the supplied string begins at the first character and that the
resulting string is of the desired length.
|
protected static String |
justifyLeft(String str,
int width,
char padWithChar,
boolean trimWhitespace) |
static String |
justifyRight(String str,
int width,
char padWithChar)
Right justify the contents of the string, ensuring that the string ends at the last character.
|
static <T> Set<T> |
listOf(String input,
char delimiter,
Function<String,T> factory)
Generate the set of values that are included in the list delimited by the given delimiter.
|
static <T> Set<T> |
listOf(String input,
Function<String,String[]> splitter,
Function<String,T> factory)
Generate the set of values that are included in the list.
|
static <T> Set<T> |
listOf(String input,
Function<String,T> factory)
Generate the set of values that are included in the list separated by commas.
|
static Set<Pattern> |
listOfRegex(String input)
Generate the set of regular expression
Patterns that are specified in the string containing comma-separated
regular expressions. |
static Set<Pattern> |
listOfRegex(String input,
int regexFlags)
Generate the set of regular expression
Patterns that are specified in the string containing comma-separated
regular expressions. |
static String |
setLength(String original,
int length,
char padChar)
Set the length of the string, padding with the supplied character if the supplied string is shorter than desired, or
truncating the string if it is longer than desired.
|
static List<String> |
splitLines(String content)
Split the supplied content into lines, returning each line as an element in the returned list.
|
static String |
trim(String str)
Trim away any leading or trailing whitespace characters.
|
static String |
trim(String str,
Strings.CharacterPredicate predicate)
Trim away any leading or trailing characters that satisfy the supplied predicate
|
public static <T> Set<T> listOf(String input, Function<String,String[]> splitter, Function<String,T> factory)
input - the input stringsplitter - the function that splits the input into multiple items; may not be nullfactory - the factory for creating string items into filter matches; may not be nullpublic static <T> Set<T> listOf(String input, char delimiter, Function<String,T> factory)
input - the input stringdelimiter - the character used to delimit the items in the inputfactory - the factory for creating string items into filter matches; may not be nullpublic static <T> Set<T> listOf(String input, Function<String,T> factory)
input - the input stringfactory - the factory for creating string items into filter matches; may not be nullpublic static Set<Pattern> listOfRegex(String input)
Patterns that are specified in the string containing comma-separated
regular expressions.input - the input string with comma-separated regular expressionsPatterns included in the list; never nullpublic static Set<Pattern> listOfRegex(String input, int regexFlags)
Patterns that are specified in the string containing comma-separated
regular expressions.input - the input string with comma-separated regular expressionsregexFlags - the flags for compiling regular expressionsPatterns included in the list; never nullpublic static List<String> splitLines(String content)
content - the string content that is to be splitpublic static int compareTo(CharSequence str1, CharSequence str2)
CharSequence instances.str1 - the first character sequence; may be nullstr2 - the second character sequence; may be nullpublic static String join(CharSequence delimiter, int[] values)
delimiter.delimiter - the delimiter that separates each elementvalues - the values to join together.String that is composed of the elements separated by the delimiterNullPointerException - If delimiter or elements is nullString.join(java.lang.CharSequence, java.lang.CharSequence...)public static String trim(String str)
This is semantically equivalent to String.trim() but instead uses trim(String, CharacterPredicate).
str - the string to be trimmed; may not be nulltrim(String,CharacterPredicate)public static String trim(String str, Strings.CharacterPredicate predicate)
str - the string to be trimmed; may not be nullpredicate - the predicate function; may not be nulltrim(String)public static String createString(char charToRepeat, int numberOfRepeats)
charToRepeat - the character to repeatnumberOfRepeats - the number of times the character is to repeat in the result; must be greater than 0public static String setLength(String original, int length, char padChar)
justifyLeft(String, int, char), this method does not
remove leading and trailing whitespace.original - the string for which the length is to be set; may not be nulllength - the desired length; must be positivepadChar - the character to use for padding, if the supplied string is not long enoughjustifyLeft(String, int, char)public static String justify(Strings.Justify justify, String str, int width, char padWithChar)
justify - the way in which the string is to be justifiedstr - the string to be right justified; if null, an empty string is usedwidth - the desired width of the string; must be positivepadWithChar - the character to use for padding, if neededpublic static String justifyRight(String str, int width, char padWithChar)
str - the string to be right justified; if null, an empty string is usedwidth - the desired width of the string; must be positivepadWithChar - the character to use for padding, if neededpublic static String justifyLeft(String str, int width, char padWithChar)
str - the string to be left justified; if null, an empty string is usedwidth - the desired width of the string; must be positivepadWithChar - the character to use for padding, if neededsetLength(String, int, char)protected static String justifyLeft(String str, int width, char padWithChar, boolean trimWhitespace)
public static String justifyCenter(String str, int width, char padWithChar)
str - the string to be left justified; if null, an empty string is usedwidth - the desired width of the string; must be positivepadWithChar - the character to use for padding, if neededsetLength(String, int, char)public static String getStackTrace(Throwable throwable)
throwable - the exception for which the stack trace is to be returnedpublic static int asInt(String value, int defaultValue)
value - the string representation of a integer valuedefaultValue - the value to return if the string value is null or cannot be parsed as an intpublic static long asLong(String value, long defaultValue)
value - the string representation of a long valuedefaultValue - the value to return if the string value is null or cannot be parsed as a longpublic static double asDouble(String value, double defaultValue)
value - the string representation of a double valuedefaultValue - the value to return if the string value is null or cannot be parsed as a doublepublic static boolean asBoolean(String value, boolean defaultValue)
value - the string representation of a boolean valuedefaultValue - the value to return if the string value is null or cannot be parsed as a booleanpublic static String duration(long durationInMillis)
HHH:MM:SS.mmm, where
durationInMillis - the duration in millisecondsCopyright © 2016 JBoss by Red Hat. All rights reserved.