|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sibvisions.util.type.StringUtil
public final class StringUtil
The StringUtil contains String dependent utility methods.
| Nested Class Summary | |
|---|---|
static class |
StringUtil.CaseSensitiveType
case senstive types. |
static class |
StringUtil.CharacterType
the character types. |
static class |
StringUtil.TextType
the text types. |
| Method Summary | |
|---|---|
static String |
concat(String pDelimiter,
List<? extends Object> pObjects)
Concatenates the given List of Objects with the given
delimiter. |
static String |
concat(String pDelimiter,
Object... pObjects)
Concatenates the Objects with the given delimiter. |
static String |
concat(String pDelimiter,
String... pElements)
Concatenates the elements with pDelimiter as separator. |
static boolean |
containsWhitespace(String pText)
Gets whether a text contains at least one whitespace character. |
static String |
convertMemberNameToText(String pMemberName)
Converts a member name in a human readable format e.g. |
static String |
convertMemberNameToText(String pMemberName,
boolean pReplaceSpecialCharacterSequences)
Converts a member name in a human readable format e.g. |
static String |
convertMethodNameToFieldName(String pMethodName)
Converts a method name to a name, without prefix and first character lowercase. |
static String |
convertMethodNameToText(String pMethodName)
Converts a method name in a human readable format. |
static String |
convertMethodNameToText(String pMethodName,
boolean pReplaceSpecialCharacterSequences)
Converts a method name in a human readable format. |
static String |
convertToMemberName(String pName)
Converts any text to a member name. |
static String |
convertToMethodName(String pPrefix,
String pName)
Converts any text to a method name. |
static String |
convertToName(String pText)
Converts text to a valid name. |
static int |
countCharacter(String pText,
char pCharToCount)
Counts the number of times the given character appears in the given text. |
static String |
firstCharLower(String pText)
Converts the first char to lowercase. |
static String |
firstCharUpper(String pText)
Converts the first char to uppercase. |
static String |
formatInitCap(String pName)
Sets the first character in each word to uppercase and the rest to lowercase. |
static String |
formatInitCap(String pName,
boolean pRemoveSpaces)
Sets the first character in each word to uppercase and the rest to lowercase. |
static String |
formatMemberName(String pName)
Formats a member name. |
static String |
formatMethodName(String pPrefix,
String pName)
Formats a method name with a given property name and the method prefix. |
static StringUtil.CaseSensitiveType |
getCaseSensitiveType(String pText)
Gets the case sensitive type of a text. |
static StringUtil.CharacterType |
getCharacterType(String pText)
Gets the character type of a text. |
static String |
getFirstWord(String pText)
Gets the first word of a text. |
static int[] |
getQuotedBoundaries(String pText)
Returns the boundaries of quoted strings. |
static String |
getShortenedWords(String pText,
int pMaxWordLength)
Gets all words from the given text with the given maximum length. |
static String |
getText(String pText,
char... pAllowed)
Gets only specific characters from a string. |
static String |
getText(String pText,
StringUtil.TextType pType)
Gets only specific characters from a string. |
static boolean |
isEmpty(String pString)
Gets whether the given text contains no characters or consists only of whitespace. |
static int |
levenshteinDistance(String pStringA,
String pStringB)
Calculates the Damerau-Levenshtein distance between two strings. |
static boolean |
like(String pSource,
String pSearch)
Fast like search in Strings with wildcard (* and ?) |
static String |
lpad(String pText,
int pLength)
Pads the given string on the left side with spaces until it has the specified length. |
static String |
ltrim(String pText)
Removes all whitespaces before the first non whitespace character. |
static String |
padLeft(Object pText,
int pLength)
Deprecated. since 2.5, use lpad(String, int) instead. |
static String |
padRight(Object pText,
int pLength)
Deprecated. since 2.5, use rpad(String, int) instead. |
static int[] |
parseColor(String pValue)
Parses color codes from given string. |
static int[] |
parseInteger(String pValues,
String pDelimiter)
Gets the int values from a string with delimiters. |
static String |
quote(String pText,
char pQuoteChar)
Adds a quote character to the begin and end of text. |
static String |
removeCharacters(String pText,
char... pCharsToRemove)
Removes specific characters from the given string. |
static String |
removeQuotes(String pText,
String pQuote)
Removes the begin and end quote of strings, e.g. |
static String |
removeQuotes(String pText,
String pStartQuote,
String pEndQuote)
Removes the begin and end quote of strings, e.g. |
static String |
removeWhitespaces(String pString)
Removes all the whitespace
characters from the given string. |
static String |
removeWhiteSpaces(String pText)
Deprecated. since 2.5, use removeWhitespaces(String)
instead. |
static String |
replace(String pText,
String pOld,
String pNew)
Returns a new string resulting from replacing all occurrences of pOld in this string with pNew. |
static String |
replacePlaceholder(String pValue)
Replaces all placeholders with the values from the defined property. |
static String |
rpad(String pText,
int pLength)
It formats a string with right Padding over pWidth characters. |
static String |
rtrim(String pText)
Removes all whitespaces after the last non whitespace character. |
static String |
sanitizeId(String pId)
Sanitizes the given input so that it can be used as ID (for example in a HTML document). |
static ArrayUtil<String> |
separate(String pText,
String pStartDelimiter,
String pEndDelimiter,
boolean pIncludeDelimiter)
Separates the given text in parts. |
static ArrayUtil<String> |
separateList(String pList,
String pDelimiter,
boolean pTrim)
Separates a string of values with a configurable delimiter. |
static String |
stripTags(String pText)
Strips any tags from the given text. |
static String |
toString(Object pObject)
Returns a string representation of the "deep contents" of the specified object. |
static String |
toString(Object pObject,
int pMaxArrayLength)
Returns a string representation of the "deep contents" of the specified object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static String concat(String pDelimiter,
List<? extends Object> pObjects)
List of Objects with the given
delimiter. Object.toString() is used to convert
the Object to a String, if the Object is
null, the String "null" will be appended.
pDelimiter - the delimiter to use.pObjects - the Objects to concatenate.
String. An empty String if the
List is either null or empty.concat(String, Object...),
concat(String, String...),
Object.toString()
public static String concat(String pDelimiter,
Object... pObjects)
Objects with the given delimiter.
Object.toString() is used to convert the the Object to a
String, if the Object is null, the String
"null" will be appended.
pDelimiter - the delimiter to use.pObjects - the Objects to concatenate.
String. An empty String if the
List is either null or empty.concat(String, List),
concat(String, String...),
Object.toString()
public static String concat(String pDelimiter,
String... pElements)
pDelimiter - the delimiter.pElements - the elements to concatenate.
concat(String, List),
concat(String, Object...)public static boolean containsWhitespace(String pText)
whitespace character.
pText - the text to check.
true if at least one whitespace character was found,
false otherwise.Character.isWhitespace(char)public static String convertMemberNameToText(String pMemberName)
myMethodName is converted to My Method Name. No special
character sequences are replaced e.g. ue is not replaced with
ü (german umlaut).
pMemberName - the member name.
convertMethodNameToText(String, boolean)
public static String convertMemberNameToText(String pMemberName,
boolean pReplaceSpecialCharacterSequences)
myMethodName is converted to My Method Name.
pMemberName - the member name.pReplaceSpecialCharacterSequences - true to replace e.g.
ue to ü (german umlaut).
public static String convertMethodNameToText(String pMethodName)
getMyMethodName is converted to My Method Name. No
special character sequences are replaced e.g. ue is not replaced
with ü (german umlaut).
pMethodName - the method name.
convertMethodNameToText(String, boolean)
public static String convertMethodNameToText(String pMethodName,
boolean pReplaceSpecialCharacterSequences)
getMyMethodName is converted to My Method Name.
pMethodName - the method name.pReplaceSpecialCharacterSequences - true to replace e.g.
{code ue} to ü (german umlaut).
public static String convertMethodNameToFieldName(String pMethodName)
pMethodName - the method name
public static String convertToMemberName(String pName)
_ they will be removed. If the text contains special characters
like German umlauts, the characters will be replaced by appropriate ASCII
characters.
pName - the text.
public static String convertToMethodName(String pPrefix,
String pName)
_ they will be removed. If the text contains special characters
like German umlauts, the characters will be replaced by appropriate ASCII
characters. If the name contains no text, null will be returned.
pPrefix - the method prefix e.g. get, set, is, has, ...pName - the text.
public static String convertToName(String pText)
pText - any text.
public static int countCharacter(String pText,
char pCharToCount)
pText - the text.pCharToCount - the character to search.
pChar in pText.public static String firstCharLower(String pText)
pText - the text.
public static String firstCharUpper(String pText)
pText - the text.
public static String formatInitCap(String pName)
pName - the unformatted text.
public static String formatInitCap(String pName,
boolean pRemoveSpaces)
pName - the unformatted or formatted text.pRemoveSpaces - true to remove whitespace characters from
the result.
public static String formatMemberName(String pName)
pName - the member name.
public static String formatMethodName(String pPrefix,
String pName)
pPrefix - the method prefix, an empty string or null if the
method name has no prefix.pName - the unformatted method name.
public static StringUtil.CaseSensitiveType getCaseSensitiveType(String pText)
pText - any text or null.
StringUtil.CaseSensitiveType.NoLetter if the text contains no letter
or the text is null. StringUtil.CaseSensitiveType.LowerCase
if the text contains at least one letter and all available
letters are lower case. StringUtil.CaseSensitiveType.UpperCase if
the text contains at least one letter and all available letters
are upper case. StringUtil.CaseSensitiveType.MixedCase if the text
contains at least two letters and the text contains lower and
upper case letters.public static StringUtil.CharacterType getCharacterType(String pText)
pText - any text or null.
StringUtil.CharacterType.None if the text is empty or null.
StringUtil.CharacterType.Letters if the text only contains letters.
StringUtil.CharacterType.Digits if the text only contains digits.
StringUtil.CharacterType.LettersDigits if the text only contains
letters and digits. StringUtil.CharacterType.LettersSpecial if the
text contains letters and other characters but no digits.
StringUtil.CharacterType.DigitsSpecial if the text contains digits
and other characters but no letters.
StringUtil.CharacterType.LettersDigitsWhitespace if the text only
contains letters, digits and whitespaces.
StringUtil.CharacterType.LettersDigitsSpace if the text only
contains letters, digits and spaces.
StringUtil.CharacterType.OnlyWhitespace if the text only contains
whitespaces. StringUtil.CharacterType.OnlySpecial if the text
contains no letters and no digits. StringUtil.CharacterType.All if
the text contains letters, digits and other characters.public static String getFirstWord(String pText)
pText - the text.
public static int[] getQuotedBoundaries(String pText)
unitTest("Test", Application.class, " Application.class");
unitTest("Test\", Application.class", Application.class");
unitTest("Test", Application.class", Application.class);
pText - the text with our without quotes.
public static String getShortenedWords(String pText,
int pMaxWordLength)
null or empty the given text is returned. If the
given text does not contain any upper case characters, an empty string is
returned.
Anything that is not a letter is returned verbatim and assumed to be a
word separator.
Examples:
SomeDataWorkScreen, 3 -> SomDatWorScr ContractsEducation, 3 -> ConEdu ContractsEducation, 5 -> ContrEduca com.sibvisions.test.ClassName, 3 -> com.sib.tes.ClaNam
pText - the text to process.pMaxWordLength - the maximum length of the words.
null if the given text was null, an empty string if the
given text was empty or the maximum word length was equal or less
than zero.
public static String getText(String pText,
char... pAllowed)
pText - any text.pAllowed - the allowed characters.
public static String getText(String pText,
StringUtil.TextType pType)
pText - any text.pType - the character return type.
public static boolean isEmpty(String pString)
pString - the string to test.
true if pText is null or has 0 characters
(whitespaces will be ignored).String.trim()
public static int levenshteinDistance(String pStringA,
String pStringB)
pStringA - the first string. Needs to be not null.pStringB - the second string. Needs to be not null.
IllegalArgumentException - if any of the parameters is null
.
public static boolean like(String pSource,
String pSearch)
pSource - any string.pSearch - search pattern with or without wildcards.
true if, and only if, the string matches the pattern.
public static String lpad(String pText,
int pLength)
pText - the text to format.pLength - the length in characters to pad left.
public static String ltrim(String pText)
pText - the text.
@Deprecated
public static String padLeft(Object pText,
int pLength)
lpad(String, int) instead.
pText - the text to format.pLength - the length in characters to pad left.
@Deprecated
public static String padRight(Object pText,
int pLength)
rpad(String, int) instead.
pText - the text to format.pLength - the length in characters to pad right.
public static int[] parseColor(String pValue)
#9988AA (web style) #98A (web style) 0x9988AA 127, 127, 127 (without alpha value) 127, 127, 127, 0 (with alpha value)
pValue - the color definition.
null if format isn't
supported.
public static int[] parseInteger(String pValues,
String pDelimiter)
pValues - the string with numbers and delimiters.pDelimiter - the delimiter.
null if the values are null or
empty.
public static String quote(String pText,
char pQuoteChar)
pText - the text to protect.pQuoteChar - the quote character.
public static String removeCharacters(String pText,
char... pCharsToRemove)
pText - a string.pCharsToRemove - the characters which should be removed.
public static String removeQuotes(String pText,
String pQuote)
'text' will be
translated to text
pText - the quoted text.pQuote - the quote character e.g. ' or ".
pText without begin and end quote.
public static String removeQuotes(String pText,
String pStartQuote,
String pEndQuote)
'text' will be
translated to text
pText - the quoted text.pStartQuote - the start quote character e.g. ' or "
or (.pEndQuote - the end quote character e.g. ' or " or
).
pText without begin and end quote.public static String removeWhitespaces(String pString)
whitespace
characters from the given string.
pString - the string to clean.
Character.isWhitespace(char)@Deprecated public static String removeWhiteSpaces(String pText)
removeWhitespaces(String)
instead.
pText - the text.
public static String replace(String pText,
String pOld,
String pNew)
pOld in this string with pNew.
pText - the original text.pOld - the text to replace.pNew - the replacement.
public static String replacePlaceholder(String pValue)
pValue - the value with or without placeholders
public static String rpad(String pText,
int pLength)
pText - the text to format.pLength - the length in characters to pad right.
public static String rtrim(String pText)
pText - the text.
public static String sanitizeId(String pId)
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
pId - the id to sanitize.
null if the given id was null.
public static ArrayUtil<String> separate(String pText,
String pStartDelimiter,
String pEndDelimiter,
boolean pIncludeDelimiter)
pText - the text.pStartDelimiter - the start delimiter.pEndDelimiter - the end delimiter.pIncludeDelimiter - true to include the delimiters in the
result for every found part.
public static ArrayUtil<String> separateList(String pList,
String pDelimiter,
boolean pTrim)
pList - string with values.pDelimiter - delimiter to separate.pTrim - true to trim the separated values.
public static String stripTags(String pText)
<html>Something</html> Something <b>Some</b>thing</b> Something <html>This is<br>a<br><br>new line test.</html> This isanew line test.
pText - the test from which to strip all HTML tags.
public static String toString(Object pObject)
The string representation consists of a list of the object's elements, enclosed in brackets ("[]" or "{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space).
To avoid infinite recursion, if the specified object contains itself as an element, or contains an indirect reference to itself through one or more levels of arrays, the self-reference is converted to the string "#REF#". For example, an array containing only a reference to itself would be rendered as "[#REF#]".
This method returns "null" if the specified object is null.
pObject - the object whose string representation to return
public static String toString(Object pObject,
int pMaxArrayLength)
The string representation consists of a list of the object's elements, enclosed in brackets ("[]" or "{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space).
To avoid infinite recursion, if the specified object contains itself as an element, or contains an indirect reference to itself through one or more levels of arrays, the self-reference is converted to the string "#REF#". For example, an array containing only a reference to itself would be rendered as "[#REF#]".
This method returns "null" if the specified object is null.
pObject - the object whose string representation to returnpMaxArrayLength - the maximum length of arrays. If the length of an
array is exceeded, the elements won't be printed. Instead a
placeholder like byte[n] will be printed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||