|
||||||||||
| 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,
String... pElements)
Concats the elements with pDelimiter as seperator. |
static boolean |
containsWhitespace(String pText)
Gets whether a text contains at least one whitespace character. |
static String |
convertMemberNameToText(String pMember)
Converts a member name in a human readable format e.g. |
static String |
convertMemberNameToText(String pMember,
boolean pReplaceSpecialCharacterSequences)
Converts a member name in a human readable format e.g. |
static String |
convertMethodNameToText(String pMethod)
Converts a method name in a human readable format. |
static String |
convertMethodNameToText(String pMethod,
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 vaild name. |
static int |
countCharacter(String pText,
char pChar)
Counts the number of a specific characters in a text. |
static String |
firstCharLower(String pText)
Lowercase the first character. |
static String |
firstCharUpper(String pText)
Uppercase the first character. |
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 sText)
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,
StringUtil.TextType pType)
Gets only specific characters from a string. |
static boolean |
isEmpty(String pText)
Gets whether the given text contains no characters. |
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 |
padLeft(Object pText,
int pWidth)
It formats a string with left Padding over pWidth characters. |
static String |
padRight(Object pText,
int pWidth)
It formats a string with right Padding over pWidth characters. |
static int[] |
parseInteger(String pValues,
String pDelimiter)
Gets the int values from a string with delimiters. |
static String |
quote(String pText,
char pQuote)
Adds a quote character to the begin and end of text. |
static String |
removeCharacters(String pText,
char[] pRemove)
Removes specific characters from a 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 pText)
Gets a String without any white space. |
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 |
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 int[] getQuotedBoundaries(String sText)
unitTest("Test", Application.class, " Application.class");
unitTest("Test\", Application.class", Application.class");
unitTest("Test", Application.class", Application.class);
sText - 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.
Examples:
SomeDataWorkScreen, 3 -> SomDatWorScr
ContractsEducation, 3 -< ConEdu
ContractsEducation, 5 -< ContrEduca
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 getFirstWord(String pText)
pText - the text
public static ArrayUtil<String> separateList(String pList,
String pDelimiter,
boolean pTrim)
pList - string with valuespDelimiter - delimiter to separatepTrim - true to trim the separated values
public static ArrayUtil<String> separate(String pText,
String pStartDelimiter,
String pEndDelimiter,
boolean pIncludeDelimiter)
pText - the textpStartDelimiter - the start delimiterpEndDelimiter - the end delimiterpIncludeDelimiter - true to include the delimiters in the result for every found part
public static int[] parseInteger(String pValues,
String pDelimiter)
pValues - the string with numbers and delimiterspDelimiter - the delimiter
null if the values are null or empty
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.
public static boolean like(String pSource,
String pSearch)
pSource - any stringpSearch - search pattern with or without wildcards.
true if, and only if, the string matches the patternpublic static String formatInitCap(String pName)
pName - the unformatted text
public static String formatInitCap(String pName,
boolean pRemoveSpaces)
pName - the unformatted or formatted textpRemoveSpaces - 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 prefixpName - the unformatted method name
public static String convertToMemberName(String pName)
pName - the text
public static String convertToMethodName(String pPrefix,
String pName)
pPrefix - the method prefix e.g. get, set, is, has, ...pName - the text
public static String convertToName(String pText)
pText - any text
public static String convertMethodNameToText(String pMethod)
getMyMethodName is converted to My Method Name.
No special character sequences are replaced e.g. ue is not replaced with ü (german umlaut).
pMethod - the method name
convertMethodNameToText(String, boolean)
public static String convertMethodNameToText(String pMethod,
boolean pReplaceSpecialCharacterSequences)
getMyMethodName is converted to My Method Name.
pMethod - the method namepReplaceSpecialCharacterSequences - true to replace e.g. ue to ü (german umlaut)
public static String convertMemberNameToText(String pMember)
myMethodName is converted to My Method Name.
No special character sequences are replaced e.g. ue is not replaced with ü (german umlaut).
pMember - the member name
convertMethodNameToText(String, boolean)
public static String convertMemberNameToText(String pMember,
boolean pReplaceSpecialCharacterSequences)
myMethodName is converted to My Method Name.
pMember - the member namepReplaceSpecialCharacterSequences - true to replace e.g. ue to ü (german umlaut)
public static String getText(String pText,
StringUtil.TextType pType)
pText - any textpType - the character return type
public static String removeCharacters(String pText,
char[] pRemove)
pText - a stringpRemove - the characters which should be removed
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 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.
public static String removeQuotes(String pText,
String pQuote)
'text' will be translated to text
pText - the quoted textpQuote - 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 textpStartQuote - 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 quote(String pText,
char pQuote)
pText - the text to protectpQuote - the quote character
public static String replace(String pText,
String pOld,
String pNew)
pOld in this string with pNew.
pText - the original textpOld - the text to replacepNew - the replacemenet
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 boolean isEmpty(String pText)
pText - a text
true if pText is null or has 0 characters (whitespaces will be ignored)
public static String concat(String pDelimiter,
String... pElements)
pDelimiter - the delimiter.pElements - the elements to concat.
public static String padRight(Object pText,
int pWidth)
pText - the text to format.pWidth - the width in characters to pad right.
public static String padLeft(Object pText,
int pWidth)
pText - the text to format.pWidth - the width in characters to pad left.
public static boolean containsWhitespace(String pText)
pText - the text
true if at least one whitespace character was found, false otherwisepublic static String removeWhiteSpaces(String pText)
pText - the text.
public static String stripTags(String pText)
<>.
Examples:
<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 int countCharacter(String pText,
char pChar)
pText - the textpChar - the character to search
pChar in pTextpublic static String firstCharUpper(String pText)
pText - the text
public static String firstCharLower(String pText)
pText - the text
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||