stomp.util
Class StringHelper

java.lang.Object
  |
  +--stomp.util.StringHelper

public class StringHelper
extends java.lang.Object

Utility class to help with String manipulation

Author:
Eric Lindauer

Constructor Summary
StringHelper()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String s)
           
static java.lang.String[] collectionToQuotedStrings(java.util.Collection objs)
          Converts a collection of objects into an array of their string representations enclosed in quotes when the strings do not look like numbers or dates
static java.lang.String[] collectionToStrings(java.util.Collection objs)
          Converts a collection of objects into an array of their string representations
static boolean endsWithAQuote(java.lang.String str)
          Determines whether the given string ends with a quote
static boolean isDate(java.lang.String suspect)
          Determines whether the given string represents a date
static boolean isNumber(java.lang.String suspect)
          Determines whether the given string represents a number
static java.lang.String join(byte[] bytes, java.lang.String delimiter)
          Glues given bytes together with the given delimiter in between the joined elements.
static java.lang.String join(byte[] bytes, java.lang.String delimiter, int offset, int length)
          Glues given bytes together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( bytes, delimiter, 0, bytes.length) will join all the elements in the array
static java.lang.String join(double[] doubles, java.lang.String delimiter)
          Glues given doubles together with the given delimiter in between the joined elements.
static java.lang.String join(double[] doubles, java.lang.String delimiter, int offset, int length)
          Glues given doubles together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( doubles, delimiter, 0, doubles.length) will join all the elements in the array
static java.lang.String join(float[] floats, java.lang.String delimiter)
          Glues given floats together with the given delimiter in between the joined elements.
static java.lang.String join(float[] floats, java.lang.String delimiter, int offset, int length)
          Glues given floats together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( floats, delimiter, 0, floats.length) will join all the elements in the array
static java.lang.String join(int[] ints, java.lang.String delimiter)
          Glues given integers together with the given delimiter in between the joined elements.
static java.lang.String join(int[] ints, java.lang.String delimiter, int offset, int length)
          Glues given integers together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( ints, delimiter, 0, ints.length) will join all the elements in the array
static java.lang.String join(long[] longs, java.lang.String delimiter)
          Glues given longs together with the given delimiter in between the joined elements.
static java.lang.String join(long[] longs, java.lang.String delimiter, int offset, int length)
          Glues given longs together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( longs, delimiter, 0, longs.length) will join all the elements in the array
static java.lang.String join(java.lang.Object[] objs, java.lang.String delimiter)
          Glues given string elements together with the given delimiter in between the joined elements.
static java.lang.String join(java.lang.Object[] objs, java.lang.String delimiter, int offset, int length)
          Glues given string elements together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( strs, delimiter, 0, strs.length) will join all the elements in the array
static java.lang.String join(short[] shorts, java.lang.String delimiter)
          Glues given shorts together with the given delimiter in between the joined elements.
static java.lang.String join(short[] shorts, java.lang.String delimiter, int offset, int length)
          Glues given shorts together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( shorts, delimiter, 0, shorts.length) will join all the elements in the array
static java.lang.String join(java.lang.String[] strs, java.lang.String delimiter)
          Glues given string elements together with the given delimiter in between the joined elements.
static java.lang.String join(java.lang.String[] strs, java.lang.String delimiter, int offset, int length)
          Glues given string elements together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( strs, delimiter, 0, strs.length) will join all the elements in the array
static java.lang.StringBuffer replace(java.lang.String string, java.lang.String find, java.lang.String replace)
          replaces all instance of find with replace and returns the resultant String in a StringBuffer
static java.lang.String simpleNameOf(java.lang.Class theClass)
           
static java.lang.String simpleNameOf(java.lang.String name)
           
static java.lang.String[] split(java.lang.String str, java.lang.String delimiter)
          Parses the given string for the fields delimited by the given delimiter
static java.lang.String[] split(java.lang.String str, java.lang.String delimiter, boolean withRegardsToQuotes)
          Parses the given string for the fields delimited by the given delimiter possibly with regards for the quotes around the fields (if requested)
static boolean startsWithAQuote(java.lang.String str)
          Determines whether the given string starts with a quote
static boolean stringArraysEqual(java.lang.String[] a, java.lang.String[] b)
          Determines if the two string arrays are equal by comparing corresponding array elements
static java.lang.String stripQuotes(java.lang.String str)
          Strips the beginning and ending quotes off the given string
static java.lang.String wrapString(java.lang.String message, int preferredLineLength)
          Wraps the given string (by inserting new-line charactes) trying to keep line length to the given preferred line length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringHelper

public StringHelper()
Method Detail

replace

public static java.lang.StringBuffer replace(java.lang.String string,
                                             java.lang.String find,
                                             java.lang.String replace)
replaces all instance of find with replace and returns the resultant String in a StringBuffer


capitalize

public static java.lang.String capitalize(java.lang.String s)
Returns:
the same string with the first letter capitalized

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String delimiter)
Parses the given string for the fields delimited by the given delimiter

Parameters:
str - Original string to parse
delimiter - The delimiter to distingish the fields
Returns:
Array of delimited fields

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String delimiter,
                                       boolean withRegardsToQuotes)
Parses the given string for the fields delimited by the given delimiter possibly with regards for the quotes around the fields (if requested)

Parameters:
str - A string to parse
delimiter - The delimiter to distingish the fields
withRegardsToQuotes - Whether a special attention to quotes is needed
Returns:
Array of delimited fields

join

public static java.lang.String join(java.lang.String[] strs,
                                    java.lang.String delimiter)
Glues given string elements together with the given delimiter in between the joined elements. This call is analogues to split( strs, delimiter, 0, strs.length)

Parameters:
strs - Array of string elements that need to be joined
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(java.lang.String[] strs,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given string elements together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( strs, delimiter, 0, strs.length) will join all the elements in the array

Parameters:
strs - Array of string elements that need to be joined
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

join

public static java.lang.String join(java.lang.Object[] objs,
                                    java.lang.String delimiter)
Glues given string elements together with the given delimiter in between the joined elements. This call is analogues to split( strs, delimiter, 0, strs.length)

Parameters:
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(java.lang.Object[] objs,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given string elements together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( strs, delimiter, 0, strs.length) will join all the elements in the array

Parameters:
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

join

public static java.lang.String join(byte[] bytes,
                                    java.lang.String delimiter)
Glues given bytes together with the given delimiter in between the joined elements. This call is analogues to split( bytes, delimiter, 0, bytes.length)

Parameters:
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(byte[] bytes,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given bytes together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( bytes, delimiter, 0, bytes.length) will join all the elements in the array

Parameters:
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

join

public static java.lang.String join(short[] shorts,
                                    java.lang.String delimiter)
Glues given shorts together with the given delimiter in between the joined elements. This call is analogues to split( shorts, delimiter, 0, shorts.length)

Parameters:
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(short[] shorts,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given shorts together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( shorts, delimiter, 0, shorts.length) will join all the elements in the array

Parameters:
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

join

public static java.lang.String join(int[] ints,
                                    java.lang.String delimiter)
Glues given integers together with the given delimiter in between the joined elements. This call is analogues to split( ints, delimiter, 0, ints.length)

Parameters:
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(int[] ints,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given integers together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( ints, delimiter, 0, ints.length) will join all the elements in the array

Parameters:
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

join

public static java.lang.String join(long[] longs,
                                    java.lang.String delimiter)
Glues given longs together with the given delimiter in between the joined elements. This call is analogues to split( longs, delimiter, 0, longs.length)

Parameters:
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(long[] longs,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given longs together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( longs, delimiter, 0, longs.length) will join all the elements in the array

Parameters:
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

join

public static java.lang.String join(float[] floats,
                                    java.lang.String delimiter)
Glues given floats together with the given delimiter in between the joined elements. This call is analogues to split( floats, delimiter, 0, floats.length)

Parameters:
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(float[] floats,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given floats together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( floats, delimiter, 0, floats.length) will join all the elements in the array

Parameters:
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

join

public static java.lang.String join(double[] doubles,
                                    java.lang.String delimiter)
Glues given doubles together with the given delimiter in between the joined elements. This call is analogues to split( doubles, delimiter, 0, doubles.length)

Parameters:
delimiter - A delimiter to use in between the joined elements
Returns:
A string that contains all the joined elements

join

public static java.lang.String join(double[] doubles,
                                    java.lang.String delimiter,
                                    int offset,
                                    int length)
Glues given doubles together with the given delimiter in between the joined elements starting with the offset element and joining length number of elements within the given array of elements.
split( doubles, delimiter, 0, doubles.length) will join all the elements in the array

Parameters:
delimiter - A delimiter to use in between the joined elements
offset - Index of the starting element to be joined
length - Number of elements to join from the given array of elements
Returns:
A string that contains the joined elements

collectionToStrings

public static java.lang.String[] collectionToStrings(java.util.Collection objs)
Converts a collection of objects into an array of their string representations

Parameters:
objs - A collection of objects
Returns:
An array of the objects' string representations

collectionToQuotedStrings

public static java.lang.String[] collectionToQuotedStrings(java.util.Collection objs)
Converts a collection of objects into an array of their string representations enclosed in quotes when the strings do not look like numbers or dates

Parameters:
objs - A collection of objects
Returns:
An array of the objects' string representations

stripQuotes

public static java.lang.String stripQuotes(java.lang.String str)
Strips the beginning and ending quotes off the given string

Parameters:
str - A string to strip the quotes off
Returns:
A string without the beginning and ending quotes

startsWithAQuote

public static boolean startsWithAQuote(java.lang.String str)
Determines whether the given string starts with a quote

Parameters:
str - A string to examine
Returns:
True if the string starts with a quote; false -- otherwise

endsWithAQuote

public static boolean endsWithAQuote(java.lang.String str)
Determines whether the given string ends with a quote

Parameters:
str - A string to examine
Returns:
True if the string ends with a quote; false -- otherwise

isNumber

public static boolean isNumber(java.lang.String suspect)
Determines whether the given string represents a number

Parameters:
suspect - A string to examine
Returns:
True if the given string represents a number; false -- otherwise

isDate

public static boolean isDate(java.lang.String suspect)
Determines whether the given string represents a date

Parameters:
suspect - A string to examine
Returns:
True if the given string represents a date; false -- otherwise

stringArraysEqual

public static boolean stringArraysEqual(java.lang.String[] a,
                                        java.lang.String[] b)
Determines if the two string arrays are equal by comparing corresponding array elements

Parameters:
a - First array to compare
b - Second array to compare
Returns:
True if the arrays are equal; false -- otherwise

simpleNameOf

public static java.lang.String simpleNameOf(java.lang.Class theClass)

simpleNameOf

public static java.lang.String simpleNameOf(java.lang.String name)

wrapString

public static java.lang.String wrapString(java.lang.String message,
                                          int preferredLineLength)
Wraps the given string (by inserting new-line charactes) trying to keep line length to the given preferred line length. Also, starts every new sentence on a new line.

Parameters:
message - A string to wrap
preferredLineLength - A preferred length of lines in the wrapped string