|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tc.util.StringUtil
public class StringUtil
String utility methods.
Field Summary | |
---|---|
static java.lang.String |
EMPTY
The empty string |
static java.lang.String |
LINE_SEPARATOR
|
static java.lang.String |
NULL_STRING
A string representing a null value: " |
static char |
SPACE
A space character |
static java.lang.String |
SPACE_STRING
A space string |
Constructor Summary | |
---|---|
StringUtil()
|
Method Summary | |
---|---|
static java.lang.String |
getNonNull(java.lang.String s)
Get a non-null version of the String. |
static java.lang.String |
getNonNull(java.lang.String s,
java.lang.String nullToken)
For a string s, if non-null return s, else return nullToken. |
static java.lang.String |
indentLines(java.lang.String source)
Indent lines using a single tab by inserting them into source after line breaks and returning a new String. |
static java.lang.StringBuffer |
indentLines(java.lang.StringBuffer source,
int indentLevel)
Indent lines using tabs by inserting them into source and returning source. |
static java.lang.StringBuffer |
indentLines(java.lang.StringBuffer source,
int indentLevel,
char indentChar)
Indent lines in the StringBuffer (line breaks found at \n) with indentChar repeated indentLevel times. |
static java.lang.String |
indentLines(java.lang.String source,
int indentLevel)
Indent lines using tabs by inserting them into source after line breaks and returning a new String. |
static int |
indexOfStringBuffer(java.lang.StringBuffer source,
java.lang.String search,
int start)
Find index of "search" in "source", starting at "start" index. |
static java.lang.String |
reduce(java.lang.String source)
Reduces the size that a string occupies to the minimal possible by ensuring that the back-end char array contains exactly the characters that are needed, and no more. |
static java.lang.String |
replaceAll(java.lang.String source,
java.lang.String search,
java.lang.String replace,
boolean skipQuotedStrings)
Simple search/replace for non-pattern strings. |
static java.lang.String |
safeToString(java.lang.Object object)
Normal toString(), but convert null to the NULL_STRING . |
static java.lang.String |
toPaddedString(long value,
int radix,
int paddedWidth)
Format value to string using radix, then prepend with 0's out to paddedWidth. |
static java.lang.String |
toString(java.lang.Object[] objs)
Helper method to convert object array [a, b, c] to comma-separated string "a, b, c". |
static java.lang.String |
toString(java.lang.Object[] objs,
java.lang.String separator,
java.lang.String prefix,
java.lang.String postfix)
Creates a String representation of an array of objects by calling toString on each one. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char SPACE
public static final java.lang.String SPACE_STRING
public static final java.lang.String EMPTY
public static final java.lang.String NULL_STRING
public static final java.lang.String LINE_SEPARATOR
Constructor Detail |
---|
public StringUtil()
Method Detail |
---|
public static final java.lang.String safeToString(java.lang.Object object)
NULL_STRING
.
public static java.lang.String indentLines(java.lang.String source)
source
- Source string, may NOT be null
java.lang.NullPointerException
- If source is nullpublic static java.lang.String indentLines(java.lang.String source, int indentLevel)
source
- Source string, may NOT be nullindentLevel
- Number of tabs to insert, must be >= 0
java.lang.IllegalArgumentException
- If indentLevel < 0
java.lang.NullPointerException
- If source is nullpublic static java.lang.StringBuffer indentLines(java.lang.StringBuffer source, int indentLevel)
source
- Source buffer, may be nullindentLevel
- Number of tabs to insert, must be >= 0
java.lang.IllegalArgumentException
- If indentLevel < 0public static java.lang.StringBuffer indentLines(java.lang.StringBuffer source, int indentLevel, char indentChar)
source
- Source buffer, may be nullindentLevel
- Number of chars to indent, must be >= 0indentChar
- Indent character (usually ' ' or '\t')
java.lang.IllegalArgumentException
- If indentLevel < 0public static int indexOfStringBuffer(java.lang.StringBuffer source, java.lang.String search, int start)
source
- Source buffer, must be non-nullsearch
- Search string, must be non-nullstart
- Start index, should be 0<=startjava.lang.NullPointerException
- If source or search is nullpublic static final java.lang.String toString(java.lang.Object[] objs, java.lang.String separator, java.lang.String prefix, java.lang.String postfix)
toString
on each one. Formatting is
controlled by the parameters.
objs
- (required) the array of objects to displayseparator
- (optional) a string to place between each objectprefix
- (optional) a string to prefix each object withpostfix
- (optional) a string to append to each object
public static final java.lang.String toString(java.lang.Object[] objs)
objs
- Array of objects, can be null
public static final java.lang.String toPaddedString(long value, int radix, int paddedWidth)
value
- Long value, must be >= 0radix
- The radix to use when representing the valuepaddedWidth
- The width to pad to by prepending 0
public static final java.lang.String replaceAll(java.lang.String source, java.lang.String search, java.lang.String replace, boolean skipQuotedStrings)
source
- the original string to perform the search/replace on, a modified version of this is returned, if null
then null will be returned immediatelysearch
- the string to search for in source
, if null then null is returned immediatelyreplace
- the string to replace search
occurrences in source
, if null then the
search string is simply removed from source and not replaced with anythingskipQuotedStrings
- if true then quoted strings will be skipped over
source
, or null if source
or search
are nullpublic static final java.lang.String reduce(java.lang.String source)
source
- the string that needs to be reduced
public static final java.lang.String getNonNull(java.lang.String s, java.lang.String nullToken)
s
- The starting stringnullToken
- The null token
public static final java.lang.String getNonNull(java.lang.String s)
s
- The string
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |