public class StringUtils extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.text.NumberFormat |
DOUBLE_FORMAT |
static java.text.NumberFormat |
INTEGER_FORMAT |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.util.List<java.lang.String> |
charSequenceToStringList(java.lang.CharSequence sequence)
Converts the specified character sequence to a list strings, where each character of the sequence is
represented as a single string object.
|
static java.lang.String |
concatWithOperator(java.lang.String leftPart,
java.lang.String rightPart,
java.lang.String operator)
Concatenates two expressions with an operator if both are not empty.
|
static java.lang.String |
concatWithOperator(java.lang.String leftPart,
java.lang.String rightPart,
java.lang.String operator,
java.lang.String leftBracket,
java.lang.String rightBracket)
Concatenates two expressions with an operator if both are not empty.
|
static boolean |
containsWhitespace(java.lang.CharSequence sequence)
Tests if the specified character sequence does not contain any whitespace.
|
static java.lang.String |
convertCamelCase(java.lang.String text,
java.lang.String separator)
Converts a camel case keyword to a string with the specified separator where all characters are in lower case.
|
static java.lang.CharSequence |
cutEnd(java.lang.CharSequence sequence,
int length)
Cuts off the specified number of characters from the end of the specified character sequence.
|
static java.lang.String |
cutEnd(java.lang.String sequence,
int length)
Cuts off the specified number of characters from the end of the specified string.
|
static boolean |
endsWith(java.lang.CharSequence sequence,
char terminalSymbol)
Tests whether a character sequence ends with a specified character.
|
static java.lang.String |
firstCharToLowerCase(java.lang.String text) |
static java.lang.String |
firstCharToUpperCase(java.lang.String text) |
static int |
indexOfWhiteSpace(java.lang.CharSequence sequence)
Returns the first index of any whitespace character.
|
static int |
indexOfWhiteSpace(java.lang.CharSequence sequence,
int fromIndex)
Returns the first index of any whitespace character.
|
static java.lang.String |
invert(java.lang.CharSequence s) |
static boolean |
isNewLineChar(char c)
Checks if the specified character is a new line character
|
static char |
lastChar(java.lang.CharSequence sequence)
Returns the last character of the specified sequence.
|
static void |
renameRepeatedEntries(java.util.List<java.lang.String> list) |
static void |
renameRepeatedEntries(java.lang.String[] array) |
static java.lang.String |
repeat(java.lang.CharSequence element,
int count) |
public static final java.text.NumberFormat DOUBLE_FORMAT
public static final java.text.NumberFormat INTEGER_FORMAT
public StringUtils()
public static java.lang.String invert(java.lang.CharSequence s)
public static java.lang.String repeat(java.lang.CharSequence element, int count)
public static void renameRepeatedEntries(java.lang.String[] array)
public static void renameRepeatedEntries(java.util.List<java.lang.String> list)
public static java.lang.String concatWithOperator(java.lang.String leftPart, java.lang.String rightPart, java.lang.String operator, java.lang.String leftBracket, java.lang.String rightBracket)
Concatenates two expressions with an operator if both are not empty.
Example:
concatWithOperator("A", "B", " + ", "(", ")")
would return
"(A + B)".
concatWithOperator("A", "", " + ", "(", ")")
would return
"A".
leftPart
- the left expressionrightPart
- the right expressionoperator
- the operator (including white spaces if necessary)leftBracket
- the left bracket to be used (e.g. "{")rightBracket
- the right bracket to be used (e.g. "}")public static java.lang.String concatWithOperator(java.lang.String leftPart, java.lang.String rightPart, java.lang.String operator)
leftPart
- the left expressionrightPart
- the right expressionoperator
- the operator (including white spaces if necessary)concatWithOperator(String, String, String, String, String)
public static java.lang.String firstCharToLowerCase(java.lang.String text)
public static java.lang.String firstCharToUpperCase(java.lang.String text)
public static java.lang.String convertCamelCase(java.lang.String text, java.lang.String separator)
Example: anExampleKeyword
would be converted to an-example-keyword
and A
to a
.
text
- the string to be convertedseparator
- the separator to be insertedpublic static boolean isNewLineChar(char c)
c
- the character to be testedtrue
if c
is either '\n'
or '\r'
, false
otherwise.public static int indexOfWhiteSpace(java.lang.CharSequence sequence)
sequence
- the character sequence to be searchedCharacter.isWhitespace(char)
)
or -1 if the sequence does not contain any whitespacepublic static int indexOfWhiteSpace(java.lang.CharSequence sequence, int fromIndex)
sequence
- the character sequence to be searchedfromIndex
- the index to start the searchCharacter.isWhitespace(char)
)
at or after fromIndex
or -1 if the sequence does not contain any whitespace behind that
positionpublic static boolean containsWhitespace(java.lang.CharSequence sequence)
Note this method will return false
, if an empty sequence (""
) is specified.
sequence
- the character sequence to be testedtrue
if the sequence contains no whitespace or false
otherwisejava.lang.NullPointerException
- if sequence
is null
public static boolean endsWith(java.lang.CharSequence sequence, char terminalSymbol)
sequence
- the sequence to be testedterminalSymbol
- the expected last character of the sequencetrue
if the sequence is at least one character long and last character is equal to
terminalSymbol
, false
otherwise.public static java.lang.CharSequence cutEnd(java.lang.CharSequence sequence, int length)
If length
is higher than the length of sequence
an empty string is returned.
sequence
- the character sequence to be cutlength
- the number of characters to be removed from the endpublic static java.lang.String cutEnd(java.lang.String sequence, int length)
If length
is higher than the length of sequence
an empty string is returned.
sequence
- the string to be cutlength
- the number of characters to be removed from the endpublic static char lastChar(java.lang.CharSequence sequence)
sequence
- the character sequence to extract the last character fromjava.lang.IllegalArgumentException
- if sequence
is not at least one character longpublic static java.util.List<java.lang.String> charSequenceToStringList(java.lang.CharSequence sequence)
sequence
- the sequence to be converted