|
02/28/2005 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.vignette.portal.util.StringUtils
Various static utility methods for manipulating strings. This class need not be instantiated.
| Method Summary | |
static boolean |
contains(String string1,
String string2)
Determine whether or not the first string contains the second string. |
static String |
convertEncoding(String oldValue,
String oldCharacterEncoding,
String newCharacterEncoding)
Converts a string produced from bytes in one encoding into the string that would have been constructed if the new encoding was used. |
static int |
indexOfIgnoreCase(String string1,
String string2)
Determine if the first string contains the second string. |
static int |
indexOfIgnoreCase(String string1,
String string2,
int fromIndex)
Determine if the first string contains the second string after fromIndex. |
static boolean |
isEmpty(String string)
Determine if the passed in string is empty or null, where not empty is defined as having at least one character. |
static boolean |
isEmptyIgnoreWhitespace(String string)
Determine if the passed in string is empty or null, where not empty is defined as having at least one non-whitespace character. |
static boolean |
parseBoolean(String string,
boolean defaultValue)
Inspect the given string for "true" or "false", ignoring case. |
static byte |
parseByte(String string,
byte defaultValue)
Assuming the specified String represents a byte, returns that byte's value. |
static double |
parseDouble(String string,
double defaultValue)
Assuming the specified String represents a double, returns that double's value. |
static float |
parseFloat(String string,
float defaultValue)
Assuming the specified String represents a float, returns that float's value. |
static int |
parseInt(String string,
int defaultValue)
Assuming the specified String represents a int, returns that int's value. |
static long |
parseLong(String string,
long defaultValue)
Assuming the specified String represents a long, returns that long's value. |
static short |
parseShort(String string,
short defaultValue)
Assuming the specified String represents a short, returns that short's value. |
static String |
removeWhitespace(String input)
Removes whitespace from a string. |
static String |
repeat(int count,
char character)
Returns a string of the given length ( count) consisting entirely of character characters. |
static String |
replace(String input,
String find,
String replace)
Replace all occurrences in 'input' of 'find' with 'replace'. |
static String[] |
split(String string,
String delimiter)
Splits the given string into an array of substrings at the given set of character delimiters. |
static String |
toString(Object object)
Returns the string value of the given object or an empty string if the object is null. |
static String |
toString(Object object,
String defaultValue,
boolean ignoreWhitespace)
Returns the string value of the given object. |
static String |
toString(String initialValue,
String defaultValue,
boolean ignoreWhitespace)
Returns the given initial value or the default value specified in the second parameter should the initial value be empty. |
static String |
trim(Object object)
Trim the string value of the object passed in. |
static String |
truncate(String string,
int length,
boolean absolute)
Returns the first length characters (or less,
if absolute is false) from the
input string. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static String toString(Object object)
object - The object for which to retrieve the String value.
public static String toString(Object object,
String defaultValue,
boolean ignoreWhitespace)
object - The object for which to retrieve the String value.defaultValue - The default value to be returned.ignoreWhitespace - True if whitespace should be ignored when determining if the Object's String value is empty.
public static String toString(String initialValue,
String defaultValue,
boolean ignoreWhitespace)
initialValue - the intended return stringdefaultValue - the default return stringignoreWhitespace - True if whitespace does not count towards the initialValue not being empty.initialValue if it is non-null and (depending on ignoreWhitespace) contains at least
one non-whitespace character, otherwise returns defaultValue.public static String trim(Object object)
object - The object for which the trimmed string value is to be returned.public static boolean isEmpty(String string)
string - The string value to be tested.true if the passed in string is empty or null. Otherwise returns false.public static boolean isEmptyIgnoreWhitespace(String string)
string - The string value to be tested.true if the passed in string is empty or null. Otherwise returns false.
public static boolean contains(String string1,
String string2)
String.indexOf(String string).
If either parameter is null, this method will return false.
If string2 is an empty string, this method will return true (i.e. every string contains an empty string).string1 - The string to be tested as the container of the second string.string2 - The string that is potentially contained inside the first string.true If the first string contains the second string.
public static boolean parseBoolean(String string,
boolean defaultValue)
string - The string to be parsed into a boolean value.defaultValue - The default value to be returned in the event the supplied string cannot be parsed into a boolean.
public static byte parseByte(String string,
byte defaultValue)
string - The string to be parsed into a byte value.defaultValue - The default value to be returned in the event the supplied string cannot be parsed into a byte.
public static short parseShort(String string,
short defaultValue)
string - The string to be parsed into a short value.defaultValue - The default value to be returned in the event the supplied string cannot be parsed into a short.
public static int parseInt(String string,
int defaultValue)
string - The string to be parsed into an int value.defaultValue - The default value to be returned in the event the supplied string cannot be parsed into an int.
public static long parseLong(String string,
long defaultValue)
string - The string to be parsed into a long value.defaultValue - The default value to be returned in the event the supplied string cannot be parsed into a long.
public static float parseFloat(String string,
float defaultValue)
string - The string to be parsed into a float value.defaultValue - The default value to be returned in the event the supplied string cannot be parsed into a float.
public static double parseDouble(String string,
double defaultValue)
string - The string to be parsed into a double value.defaultValue - The default value to be returned in the event the supplied string cannot be parsed into a double.
public static int indexOfIgnoreCase(String string1,
String string2)
string2 is an empty string, 0 is returned.string1 - The string to be tested as the container of the second string.string2 - The string that may be contained in the first string.string2 within string1 or -1 if no occurances are found.
public static int indexOfIgnoreCase(String string1,
String string2,
int fromIndex)
fromIndex.
If so, return the index of the first occurance after fromIndex
(i.e. Return the index of the leftmost occurance of string2 in string1 starting at fromIndex and searching to the right).
The character at fromIndex is included in the search.
The test is not case sensitive.
If string2 is an empty string, fromIndex is returned.string1 - The string to be tested as the container of the second string.string2 - The string that may be contained in the first string.fromIndex - The index from which to begin searching for the next occurance.string2 within string1 starting at fromIndex or -1 if no occurances are found.
public static String[] split(String string,
String delimiter)
string - The string to be split.delimiter - The delimiters to use to split the string in to smaller strings.delimiters.
public static String repeat(int count,
char character)
count) consisting entirely of character characters.count - The number of times to repeat the given charactercharacter - The character to be repeated count times.count length consisting entirely of character characters.
public static String replace(String input,
String find,
String replace)
input - The input string on which to perform the replacment operation.find - The string to be replaced.replace - The string to be used as a replacement for find.public static String removeWhitespace(String input)
input - The input string on which to perform this operation.
public static String convertEncoding(String oldValue,
String oldCharacterEncoding,
String newCharacterEncoding)
throws UnsupportedEncodingException
oldValue - The original string valueoldCharacterEncoding - The original string encodingnewCharacterEncoding - The replacement string encodingString.getBytes(java.lang.String),
String.String(byte[], java.lang.String)
public static String truncate(String string,
int length,
boolean absolute)
length characters (or less,
if absolute is false) from the
input string.string - the string to get characters fromlength - the max number of characters to be returnedabsolute - boolean flag; true to return
exactly length characters from string
or just string if it contains less than
length characters, false to return
as many whole words (non-whitespace character sequences
separated by whitespace) from string as will fit
within length charactersabsolute
is true and length is less than
0 or if absolute is false
and string doesn't begin with any whole words
that are less than length characters in length,
never null
|
02/28/2005 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||