org.rhq.core.clientapi.util
Class StringUtil

java.lang.Object
  extended by org.rhq.core.clientapi.util.StringUtil

public class StringUtil
extends Object


Constructor Summary
StringUtil()
           
 
Method Summary
static String arrayToString(boolean[] array)
          Print out an array as a String
static String arrayToString(int[] array)
          Print out an array as a String
static String arrayToString(Object[] array)
          Print out an array as a String
static String arrayToString(Object[] array, char delim)
          Print out an array as a String
static String capitalize(String str)
          Capitalizes the first letter of str.
static String collectionToString(Collection collection)
           
static String collectionToString(Collection collection, String delim)
           
static List<String> explode(String s, String delim)
          Split a string on delimiter boundaries, and place each element into a List.
static String[] explodeQuoted(String arg)
          Split a string up by whitespace, taking into account quoted subcomponents.
static String[] explodeToArray(String toExplode, String delim)
          Split a string on delimiter boundaries, and place each element into an Array.
static String formatDuration(long duration)
           
static String formatDuration(long duration, int scale, boolean minDigits)
           
static String getFirstStackTrace(Throwable t)
           
static String getStackTrace(Throwable t)
           
static String implode(List objs, String delim)
          Create a string formulated by inserting a delimiter in between consecutive array elements.
static String iteratorToString(Iterator i, String delim)
          Print out everything in an Iterator in a user-friendly string format.
static String iteratorToString(Iterator i, String delim, String quoteChar)
          Print out everything in an Iterator in a user-friendly string format.
static String listToString(List list)
          Print out a List in a user-friendly string format.
static String listToString(List list, String delim)
          Print out a List in a user-friendly string format.
static String normalizePath(String s)
           
static String pluralize(String word)
           
static String remove(String source, String find)
           
static String removePrefix(String value, String prefix)
          Remove a prefix from a string.
static String repeatChars(char c, int nTimes)
           
static String replace(String source, String find, String replace)
           
static String truncate(String s, int truncLength, boolean removeWhiteSpace)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

replace

public static String replace(String source,
                             String find,
                             String replace)
Parameters:
source - The source string to perform replacements on.
find - The substring to find in source.
replace - The string to replace 'find' within source
Returns:
The source string, with all occurrences of 'find' replaced with 'replace'

remove

public static String remove(String source,
                            String find)
Parameters:
source - The source string to perform replacements on.
find - The substring to find in source.
Returns:
The source string, with all occurrences of 'find' removed

iteratorToString

public static String iteratorToString(Iterator i,
                                      String delim)
Print out everything in an Iterator in a user-friendly string format.

Parameters:
i - An iterator to print out.
delim - The delimiter to use between elements.
Returns:
The Iterator's elements in a user-friendly string format.

iteratorToString

public static String iteratorToString(Iterator i,
                                      String delim,
                                      String quoteChar)
Print out everything in an Iterator in a user-friendly string format.

Parameters:
i - An iterator to print out.
delim - The delimiter to use between elements.
quoteChar - The character to quote each element with.
Returns:
The Iterator's elements in a user-friendly string format.

listToString

public static String listToString(List list,
                                  String delim)
Print out a List in a user-friendly string format.

Parameters:
list - A List to print out.
delim - The delimiter to use between elements.
Returns:
The List in a user-friendly string format.

collectionToString

public static String collectionToString(Collection collection,
                                        String delim)

listToString

public static String listToString(List list)
Print out a List in a user-friendly string format.

Parameters:
list - A List to print out.
Returns:
The List in a user-friendly string format.

collectionToString

public static String collectionToString(Collection collection)

arrayToString

public static String arrayToString(Object[] array)
Print out an array as a String


arrayToString

public static String arrayToString(boolean[] array)
Print out an array as a String


arrayToString

public static String arrayToString(Object[] array,
                                   char delim)
Print out an array as a String

Parameters:
array - The array to print out
delim - The delimiter to use between elements.

arrayToString

public static String arrayToString(int[] array)
Print out an array as a String


implode

public static String implode(List objs,
                             String delim)
Create a string formulated by inserting a delimiter in between consecutive array elements.

Parameters:
objs - List of objects to implode (elements may not be null)
delim - String to place inbetween elements
Returns:
A string with objects in the list seperated by delim

explode

public static List<String> explode(String s,
                                   String delim)
Split a string on delimiter boundaries, and place each element into a List.

Parameters:
s - String to split up
delim - Delimiting token, ala StringTokenizer
Returns:
a List comprised of elements split by the tokenizing

explodeToArray

public static String[] explodeToArray(String toExplode,
                                      String delim)
Split a string on delimiter boundaries, and place each element into an Array.

Parameters:
toExplode - String to split up
delim - Delimiting token, ala StringTokenizer
Returns:
an Array comprised of elements split by the tokenizing

explodeQuoted

public static String[] explodeQuoted(String arg)
                              throws IllegalArgumentException
Split a string up by whitespace, taking into account quoted subcomponents. If there is an uneven number of quotes, a parse error will be thrown.

Parameters:
arg - String to parse
Returns:
an array of elements, the argument was split into
Throws:
IllegalArgumentException - indicating there was a quoting error

removePrefix

public static String removePrefix(String value,
                                  String prefix)
Remove a prefix from a string. If value starts with prefix, it will be removed, the resultant string is trimmed and returned.

Returns:
If value starts with prefix, then this method returns value with the prefix removed, and the resultant string trimmed. If value does not start with prefix, value is returned as-is.

pluralize

public static String pluralize(String word)
Returns:
the plural of word. This is done by applying a few rules. These cover most (but not all) cases: 1. If the word ends in s, ss, x, o, or ch, append es 2. If the word ends in a consonant followed by y, drop the y and add ies 3. Append an s and call it a day. The ultimate references is at http://en.wikipedia.org/wiki/English_plural

getStackTrace

public static String getStackTrace(Throwable t)
Returns:
The stack trace for the given Throwable as a String.

getFirstStackTrace

public static String getFirstStackTrace(Throwable t)
Returns:
The stack trace for the given Throwable as a String.

normalizePath

public static String normalizePath(String s)
Parameters:
s - A string that might contain unix-style path separators.
Returns:
The correct path for this platform (i.e, if win32, replace / with \).

formatDuration

public static String formatDuration(long duration)

formatDuration

public static String formatDuration(long duration,
                                    int scale,
                                    boolean minDigits)

repeatChars

public static String repeatChars(char c,
                                 int nTimes)

capitalize

public static String capitalize(String str)
Capitalizes the first letter of str.

Parameters:
str - The string to capitalize.
Returns:
A new string that is str capitalized. Returns null if str is null.

truncate

public static String truncate(String s,
                              int truncLength,
                              boolean removeWhiteSpace)


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.