|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.teiid.core.util.StringUtil
public final class StringUtil
This is a common place to put String utility methods.
Nested Class Summary | |
---|---|
static interface |
StringUtil.Constants
|
Field Summary | |
---|---|
static Comparator |
CASE_INSENSITIVE_ORDER
|
static Comparator |
CASE_SENSITIVE_ORDER
|
static String |
LINE_SEPARATOR
The String that should be used to separate lines; defaults to #NEW_LINE |
static String |
LINE_SEPARATOR_PROPERTY_NAME
The name of the System property that specifies the string that should be used to separate lines. |
static String |
SINGLE_QUOTE
The String "'" |
Method Summary | ||
---|---|---|
static String |
collapseWhitespace(String raw)
Removes extraneous whitespace from a string. |
|
static String |
computeDisplayableForm(String str)
Compute a displayable form of the specified string. |
|
static String |
computeDisplayableForm(String str,
String defaultValue)
Compute a displayable form of the specified string. |
|
static String |
computeDisplayableFormOfConstant(String text)
|
|
static String |
computeDisplayableFormOfConstant(String text,
String defaultValue)
|
|
static String |
computePluralForm(String str)
|
|
static String |
computePluralForm(String str,
String defaultValue)
|
|
static String |
createFileName(String str)
Create a valid filename from the given String. |
|
static Pattern |
createPattern(String pattern,
boolean isCaseSensitive)
Creates a regular expression pattern from the pattern string (which is our old 'StringMatcher' format). |
|
static String |
enclosedInSingleQuotes(String aString)
Utility to return a string enclosed in ''. |
|
static boolean |
endsWithIgnoreCase(String text,
String suffix)
Tests if the string ends with the specified suffix. |
|
static boolean |
equalsIgnoreCase(String s1,
String s2)
|
|
static String |
firstLetterUppercase(String str)
Make the first letter uppercase |
|
static String |
getFirstToken(String str,
String delimiter)
Return the first token in the string. |
|
static String |
getLastToken(String str,
String delimiter)
Return the last token in the string. |
|
static String[] |
getLines(String value)
|
|
static String |
getLineSeparator()
|
|
static String |
getStackTrace(Throwable t)
|
|
static int |
getTokenCount(String str,
String delimiter)
Return the number of tokens in a string that are seperated by the delimiter. |
|
static List |
getTokens(String str,
String delimiter)
Return the tokens in a string in a list. |
|
static int |
indexOfIgnoreCase(String text,
String str)
Returns the index within this string of the first occurrence of the specified substring. |
|
static boolean |
isBoolean(String text)
Returns whether the specified text represents a boolean value, i.e., whether it equals "true" or "false" (case-insensitive). |
|
static boolean |
isDigit(char c)
|
|
static boolean |
isDigits(String str)
Determine if the string passed in has all digits as its contents |
|
static boolean |
isEmpty(String text)
Returns whether the specified text is either empty or null. |
|
static boolean |
isLetter(char c)
|
|
static boolean |
isLetterOrDigit(char c)
|
|
static boolean |
isValid(String str)
|
|
static String |
join(List strings,
String delimiter)
Join string pieces and separate with a delimiter. |
|
static int |
occurrences(String input,
String token)
Return the number of occurrences of token string that occurs in input string. |
|
static String |
replace(String source,
String search,
String replace)
|
|
static String |
replaceAll(String source,
String search,
String replace)
|
|
static List<String> |
split(String str,
String splitter)
Split a string into pieces based on delimiters. |
|
static List<String> |
splitOnEntireString(String target,
String delimiter)
Break a string into pieces based on matching the full delimiter string in the text. |
|
static List |
splitPreservingQuotedSubstring(String str,
String splitter)
Split a string into pieces based on delimiters preserving spaces in quoted substring as on element in the returned list. |
|
static boolean |
startsWithIgnoreCase(String text,
String prefix)
Tests if the string starts with the specified prefix. |
|
static String |
toFixedLength(String input,
int desiredLength)
If input == null OR input.length() < desiredLength, pad to desiredLength with spaces. |
|
static String |
toLowerCase(String str)
|
|
static String |
toString(Object[] array)
Return a stringified version of the array, using a ',' as a delimiter |
|
static String |
toString(Object[] array,
String delim)
Return a stringified version of the array. |
|
static String |
toUpperCase(String str)
|
|
static String |
truncString(String in,
int len)
Simple static method to tuncate Strings to given length. |
|
static
|
valueOf(String value,
Class type)
Convert the given value to specified type. |
|
static String |
wrap(String str,
int maxCharPerLine)
Simple utility method to wrap a string by inserting line separators creating multiple lines each with length no greater than the user specified maximum. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String SINGLE_QUOTE
public static final String LINE_SEPARATOR_PROPERTY_NAME
public static final String LINE_SEPARATOR
#NEW_LINE
public static final Comparator CASE_INSENSITIVE_ORDER
public static final Comparator CASE_SENSITIVE_ORDER
Method Detail |
---|
public static String getLineSeparator()
public static String enclosedInSingleQuotes(String aString)
public static String join(List strings, String delimiter)
strings
- String pieces to joindelimiter
- Delimiter to put between string pieces
split(java.lang.String, java.lang.String)
public static String toString(Object[] array, String delim)
array
- the arraydelim
- the delimiter to use between array components
public static String toString(Object[] array)
array
- the array
toString(Object[], String)
public static List<String> split(String str, String splitter)
str
- Full stringsplitter
- Characters to split on
join(java.util.List, java.lang.String)
public static List<String> splitOnEntireString(String target, String delimiter)
target
- The text to break up.delimiter
- The sub-string which is used to break the target.
public static List splitPreservingQuotedSubstring(String str, String splitter)
str
- Full stringsplitter
- Characters to split on
join(java.util.List, java.lang.String)
public static String replace(String source, String search, String replace)
public static String replaceAll(String source, String search, String replace)
public static String truncString(String in, int len)
in
- the string that may need tuncating.len
- the lenght that the string should be truncated to.
null
if input String is null
.public static String wrap(String str, int maxCharPerLine)
str
- the string that may need tuncating.maxCharPerLine
- the max number of characters per line
public static List getTokens(String str, String delimiter)
str
- String to be tokenizeddelimiter
- Characters which are delimit tokens
public static int getTokenCount(String str, String delimiter)
str
- String to be tokenizeddelimiter
- Characters which are delimit tokens
public static int occurrences(String input, String token)
input
- token
-
public static String getLastToken(String str, String delimiter)
str
- String to be tokenizeddelimiter
- Characters which are delimit tokens
public static String getFirstToken(String str, String delimiter)
str
- String to be tokenizeddelimiter
- Characters which are delimit tokens
public static String computeDisplayableForm(String str)
str
- String to be converted; may be null
str
, or an empty string if
str
is either null or zero-length; never nullpublic static String computeDisplayableForm(String str, String defaultValue)
An exception is "MetaMatrix", which is always treated as a single word
str
- String to be converted; may be nulldefaultValue
- the default result if the input is either null or zero-length.
str
, or the default value if
str
is either null or zero-length.public static String computeDisplayableFormOfConstant(String text)
public static String computeDisplayableFormOfConstant(String text, String defaultValue)
public static String computePluralForm(String str)
public static String computePluralForm(String str, String defaultValue)
public static String getStackTrace(Throwable t)
public static boolean isBoolean(String text)
public static boolean isEmpty(String text)
Returns whether the specified text is either empty or null.
text
- The text to check; may be null;
public static int indexOfIgnoreCase(String text, String str)
isthis.startsWith(str, k)
true
.
text
- any string.str
- any string.
-1
is returned. If the text or
str argument is null or empty then -1
is returned.public static boolean startsWithIgnoreCase(String text, String prefix)
text
- the string to test.prefix
- the prefix.
true
if the character sequence represented by the
argument is a prefix of the character sequence represented by
this string; false
otherwise.
Note also that true
will be returned if the
prefix is an empty string or is equal to the text
String
object as determined by the
Object.equals(Object)
method. If the text or
prefix argument is null false
is returned.public static boolean endsWithIgnoreCase(String text, String suffix)
text
- the string to test.suffix
- the suffix.
true
if the character sequence represented by the
argument is a suffix of the character sequence represented by
this object; false
otherwise. Note that the
result will be true
if the suffix is the
empty string or is equal to this String
object
as determined by the Object.equals(Object)
method. If the text or
suffix argument is null false
is returned.public static boolean isDigits(String str)
str
-
public static Pattern createPattern(String pattern, boolean isCaseSensitive)
pattern
- The search patternisCaseSensitive
- Set to true
to create a case insensitve pattern
public static String collapseWhitespace(String raw)
raw
-
public static String toFixedLength(String input, int desiredLength)
input
- Input textdesiredLength
- Desired length
public static boolean isLetter(char c)
public static boolean isDigit(char c)
public static boolean isLetterOrDigit(char c)
public static boolean isValid(String str)
public static String toUpperCase(String str)
public static String toLowerCase(String str)
public static String createFileName(String str)
str
- The String to convert to a valid filename.defaultName
- The default name to use if only special characters exist.
public static String firstLetterUppercase(String str)
str
-
public static <T> T valueOf(String value, Class type)
value
- type
-
public static String[] getLines(String value)
public static boolean equalsIgnoreCase(String s1, String s2)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |