public class StringToolkit
extends java.lang.Object
StringToolkit provides a set of convenience methods and utilities for using and modifying
Strings.| Constructor and Description |
|---|
StringToolkit() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsOnlyWhitespaces(char[] chars,
int start,
int length)
Tests if the given char array contains only whitespaces
|
static boolean |
containsOnlyWhitespaces(java.lang.String string,
int start,
int length)
Tests if the given
String contains only whitespaces. |
static java.lang.String |
createValidIdentifier(java.lang.String string)
Creates a valid identifier string from the given
String. |
static java.lang.String |
createValidIdentifier(java.lang.String string,
char replaceChar)
Creates a valid identifier string from the given
String where white spaces and
other invalid identifier characters are replaced with the given replacement character. |
static java.lang.String |
encode(java.lang.String string)
Encodes the given
String using the default encoding. |
static java.lang.String |
encode(java.lang.String string,
java.nio.charset.Charset encoding)
Encodes the given
String using the specified encoding. |
static java.lang.String |
encodeFileName(java.lang.String fileName) |
static boolean |
equals(char[] chars,
int offset,
int length,
java.lang.String string)
Tests if the given
char array equals with the given String. |
static boolean |
equals(char[] chars,
int length,
java.lang.String string)
Tests if the given
char array equals with the given String. |
static java.lang.String |
formatString(android.content.res.Resources resources,
int stringResId,
int... formatArgResIds) |
static java.lang.String |
formatString(java.lang.String string,
java.util.List<?> args)
Formats the given
String with given arguments. |
static java.lang.String |
formatString(java.lang.String string,
java.lang.Object... args)
Formats the given
String with given arguments and by using the
String.format(java.lang.String, java.lang.Object...) method. |
static boolean |
isBlank(java.lang.CharSequence string)
Test if the given
CharSequence is not null, but empty, or contains just
white space. |
static boolean |
isEmpty(java.lang.String string)
Test if the given
String is either null, empty, or contains just white space |
static boolean |
isNotEmpty(java.lang.String string)
Test if the given
String is not null, empty, nor contains just white space |
static boolean |
isValidFileName(java.lang.String fileName)
Tests whether the given
String represents a valid file name. |
static boolean |
isValidIdentifier(java.lang.String identifier)
Tests whether the given
String represents a syntactically valid Java identifier. |
static boolean |
isValidNamespace(java.lang.String string)
Tests whether the given
String represents a syntactically valid namespace name. |
static java.lang.String |
lowerCaseFirstCharacter(java.lang.String string)
Changes the first character of the given
String to be a lowercase character. |
static java.lang.String |
normalize(java.lang.String string) |
static java.lang.String |
normalize(java.lang.String string,
java.text.Normalizer.Form form) |
static java.lang.String[] |
parseKeyTokens(java.lang.String propertyKey)
Parses the property key to create an array of
Strings containing individual
tokens of the key. |
static void |
parseKeyTokens(java.lang.String tokensString,
java.lang.String separator,
java.util.List<java.lang.String> tokens)
Parses the tokens separated by the specified separator from the given
String. |
static java.lang.String |
reverse(java.lang.String string)
Reverses the given
String. |
static java.lang.String |
stripWhiteSpaces(java.lang.String string)
Strips all the white spaces from the given
String. |
static java.lang.String |
truncateAt(java.lang.String string,
int length)
Truncates the given
String to specified length. |
static java.lang.String |
upperCaseFirstCharacter(java.lang.String string)
Changes the first character of the given
String to be a uppercase character. |
static java.lang.String |
valueOrDefault(java.lang.String string,
java.lang.String alternativeString)
Return the given
String as value if it is not empty as tested by
isNotEmpty(String) or the given default value. |
public static java.lang.String createValidIdentifier(java.lang.String string)
String.string - The object name as a String.String.java.lang.IllegalArgumentException - If the given string is null.public static java.lang.String createValidIdentifier(java.lang.String string,
char replaceChar)
String where white spaces and
other invalid identifier characters are replaced with the given replacement character.string - The object name as a String.replaceChar - A replace char.String.java.lang.IllegalArgumentException - If the given string is null.public static boolean containsOnlyWhitespaces(java.lang.String string,
int start,
int length)
String contains only whitespaces. If the String is
null, boolean value true is returned.string - The String to be tested.start - The start offset.length - The length of data.boolean value.public static boolean containsOnlyWhitespaces(char[] chars,
int start,
int length)
chars - The array of chars.start - The start offset.length - The length of data.boolean value.public static boolean equals(char[] chars,
int length,
java.lang.String string)
char array equals with the given String.chars - The given char array.length - The number of characters to be compared. Should not exceed the length of the
char array.string - The given String. Cannot be null.true if the char array and the String contain
the same characters.public static boolean equals(char[] chars,
int offset,
int length,
java.lang.String string)
char array equals with the given String.chars - The given char array.offset - The offset for the char array.length - The number of characters to be compared. Should not exceed the length of the
char array.string - The given String. Cannot be null.char array and the String contain the same characters.public static boolean isValidIdentifier(java.lang.String identifier)
String represents a syntactically valid Java identifier.identifier - The given String to be tested.boolean.public static boolean isValidFileName(java.lang.String fileName)
String represents a valid file name.fileName - The given String to be tested.boolean.public static boolean isValidNamespace(java.lang.String string)
String represents a syntactically valid namespace name.string - The given String to be tested.boolean.public static java.lang.String normalize(java.lang.String string)
public static java.lang.String normalize(java.lang.String string,
java.text.Normalizer.Form form)
public static java.lang.String encodeFileName(java.lang.String fileName)
public static java.lang.String formatString(java.lang.String string,
java.util.List<?> args)
String with given arguments.string - The string String.args - A List containing the arguments for String.format(java.lang.String, java.lang.Object...) method.String.public static java.lang.String formatString(java.lang.String string,
java.lang.Object... args)
String with given arguments and by using the
String.format(java.lang.String, java.lang.Object...) method.string - The string String.args - The arguments for String.format(java.lang.String, java.lang.Object...) method.String.public static java.lang.String formatString(android.content.res.Resources resources,
int stringResId,
int... formatArgResIds)
public static java.lang.String lowerCaseFirstCharacter(java.lang.String string)
String to be a lowercase character.string - The given String. It must contain at least one character.String.public static java.lang.String[] parseKeyTokens(java.lang.String propertyKey)
Strings containing individual
tokens of the key.propertyKey - The specified property key String.Strings containing the key tokens.public static void parseKeyTokens(java.lang.String tokensString,
java.lang.String separator,
java.util.List<java.lang.String> tokens)
String. Parsed
tokens are stored into the given Vector.tokensString - The given tokens String.separator - The specified separator String.tokens - A List used for storing the parsed tokens.public static java.lang.String stripWhiteSpaces(java.lang.String string)
String.string - The given String.String.public static java.lang.String upperCaseFirstCharacter(java.lang.String string)
String to be a uppercase character.string - The given String. It must contain at least one character.String.public static boolean isBlank(java.lang.CharSequence string)
CharSequence is not null, but empty, or contains just
white space.string - A CharSequence to be tested.boolean.public static java.lang.String valueOrDefault(java.lang.String string,
java.lang.String alternativeString)
String as value if it is not empty as tested by
isNotEmpty(String) or the given default value.string - A StringalternativeString - A alternative value as a String.String value.public static java.lang.String truncateAt(java.lang.String string,
int length)
String to specified length.string - A String to be truncated.length - The length of truncated String.String.public static java.lang.String reverse(java.lang.String string)
String.string - A String to be reversed.String.public static java.lang.String encode(java.lang.String string)
String using the default encoding.string - A String to be encoded.String.public static java.lang.String encode(java.lang.String string,
java.nio.charset.Charset encoding)
String using the specified encoding.string - A String to be encoded.encoding - A Charset specifying the encoding.String.public static boolean isEmpty(java.lang.String string)
String is either null, empty, or contains just white spacestring - A String to be tested.boolean.public static boolean isNotEmpty(java.lang.String string)
String is not null, empty, nor contains just white spacestring - A String to be tested.boolean.