Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.util
Class StringUtil

java.lang.Object
  extended by org.hyperic.util.StringUtil

public class StringUtil
extends java.lang.Object


Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String arrayToString(boolean[] array)
          Print out an array as a String.
static java.lang.String arrayToString(int[] array)
          Print out an array as a String
static java.lang.String arrayToString(java.lang.Object[] array)
          Print out an array as a String
static java.lang.String arrayToString(java.lang.Object[] array, char delim)
          Print out an array as a String
static java.lang.String capitalize(java.lang.String str)
          Capitalizes the first letter of str.
static java.lang.String dotProximate(java.lang.String str, int maxLen)
          Return a variant of 'str' which contains the beginning and end of the string, but places '...' in the middle to limit the maximum length of the string.
static java.lang.String escapeForRegex(java.lang.String source, boolean wildcard)
          Escapes a minimal set of metacharacters with their regular expression escape codes.
static java.util.List explode(java.lang.String s, java.lang.String delim)
          Split a string on delimiter boundaries, and place each element into an array.
static java.lang.String[] explodeQuoted(java.lang.String arg)
          Split a string up by whitespace, taking into account quoted subcomponents.
static java.lang.String extractQuoted(java.lang.String str)
           
static java.lang.String formatDuration(long duration)
           
static java.lang.String formatDuration(long duration, int scale, boolean minDigits)
           
static java.lang.String getStackTrace(java.lang.Throwable t)
           
static java.lang.String implode(java.util.List objs, java.lang.String delim)
          Create a string formulated by inserting a delimiter in between consecutive array elements.
static java.lang.String iteratorToString(java.util.Iterator i, java.lang.String delim)
          Print out everything in an Iterator in a user-friendly string format.
static java.lang.String iteratorToString(java.util.Iterator i, java.lang.String delim, java.lang.String quoteChar)
          Print out everything in an Iterator in a user-friendly string format.
static java.lang.String listToString(java.util.List list)
          Print out a List in a user-friendly string format.
static java.lang.String listToString(java.util.List list, java.lang.String delim)
          Print out a List in a user-friendly string format.
static java.lang.String normalizePath(java.lang.String s)
           
static java.lang.String pluralize(java.lang.String word)
           
static java.lang.String remove(java.lang.String source, java.lang.String find)
           
static java.lang.String removePrefix(java.lang.String value, java.lang.String prefix)
          Remove a prefix from a string.
static java.lang.String repeatChars(char c, int nTimes)
           
static java.lang.String replace(java.lang.String source, java.lang.String find, java.lang.String replace)
           
static boolean stringDoesNotExist(java.lang.String source, java.lang.String sub)
          Do a case-insensitive search for a substring
 
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 java.lang.String replace(java.lang.String source,
                                       java.lang.String find,
                                       java.lang.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 java.lang.String remove(java.lang.String source,
                                      java.lang.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 java.lang.String iteratorToString(java.util.Iterator i,
                                                java.lang.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 java.lang.String iteratorToString(java.util.Iterator i,
                                                java.lang.String delim,
                                                java.lang.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 java.lang.String listToString(java.util.List list,
                                            java.lang.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.

listToString

public static java.lang.String listToString(java.util.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.

arrayToString

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


arrayToString

public static java.lang.String arrayToString(boolean[] array)
Print out an array as a String. XXX: Isn't this the same as ArrayUtil.toString()?


arrayToString

public static java.lang.String arrayToString(java.lang.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 java.lang.String arrayToString(int[] array)
Print out an array as a String


implode

public static java.lang.String implode(java.util.List objs,
                                       java.lang.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 java.util.List explode(java.lang.String s,
                                     java.lang.String delim)
Split a string on delimiter boundaries, and place each element into an array.

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

extractQuoted

public static java.lang.String extractQuoted(java.lang.String str)

explodeQuoted

public static java.lang.String[] explodeQuoted(java.lang.String arg)
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:
java.lang.IllegalArgumentException - indicating there was a quoting error

removePrefix

public static java.lang.String removePrefix(java.lang.String value,
                                            java.lang.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 java.lang.String pluralize(java.lang.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 java.lang.String getStackTrace(java.lang.Throwable t)
Returns:
The stack trace for the given Throwable as a String.

normalizePath

public static java.lang.String normalizePath(java.lang.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 java.lang.String formatDuration(long duration)

formatDuration

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

repeatChars

public static java.lang.String repeatChars(char c,
                                           int nTimes)

capitalize

public static java.lang.String capitalize(java.lang.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.

dotProximate

public static java.lang.String dotProximate(java.lang.String str,
                                            int maxLen)
Return a variant of 'str' which contains the beginning and end of the string, but places '...' in the middle to limit the maximum length of the string.

Parameters:
str - String to shorten
maxLen - Maximum length of the returned string

stringDoesNotExist

public static boolean stringDoesNotExist(java.lang.String source,
                                         java.lang.String sub)
Do a case-insensitive search for a substring


escapeForRegex

public static java.lang.String escapeForRegex(java.lang.String source,
                                              boolean wildcard)
Escapes a minimal set of metacharacters with their regular expression escape codes.


Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.