com.gargoylesoftware.base.util

Class StringUtil

public class StringUtil extends Object

A collection of utility methods dealing with strings

Version: $Revision: 1.3 $

Author: Mike Bowler

Constructor Summary
StringUtil()
Method Summary
static voidassertNotNull(String fieldName, Object object)
static StringexpandTabs(String inputString, int numberOfSpaces)
Expand each tab character into the specified numbers of spaces.
static Stringjoin(int[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.
static Stringjoin(long[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.
static Stringjoin(float[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.
static Stringjoin(double[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.
static Stringjoin(byte[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.
static Stringjoin(Object[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.
static Stringjoin(Collection collection, String separator)
Create a string based on all the objects in the collection separated by the separator string.
static StringjoinArray(Object array, String separator)
Create a string based on all the objects in the array separated by the separator string.
static StringnCopies(int copyCount, char charToCopy)
Return a string containing the specified number of charToCopy
static Stringreplace(String sourceString, String match, String replace)
Perform text substitutions in the source string
static String[]split(String line, String separator)
Split the specified line into strings, spliting at each instance of separator.
static String[]splitAtFirst(String line, String separator)
Split the specified line into two strings, spliting at the first instance of separator.

Constructor Detail

StringUtil

private StringUtil()

Method Detail

assertNotNull

private static void assertNotNull(String fieldName, Object object)

expandTabs

public static String expandTabs(String inputString, int numberOfSpaces)
Expand each tab character into the specified numbers of spaces.

Parameters: inputString The string to be expanded. numberOfSpaces The number of space characters to be used for each substitution.

Returns: The new string with expanded tabs.

join

public static String join(int[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.

Parameters: array The items that will be concatenated together separator The separator string.

Returns: The new concatenated string.

join

public static String join(long[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.

Parameters: array The items that will be concatenated together separator The separator string.

Returns: The new concatenated string.

join

public static String join(float[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.

Parameters: array The items that will be concatenated together separator The separator string.

Returns: The new concatenated string.

join

public static String join(double[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.

Parameters: array The items that will be concatenated together separator The separator string.

Returns: The new concatenated string.

join

public static String join(byte[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.

Parameters: array The items that will be concatenated together separator The separator string.

Returns: The new concatenated string.

join

public static String join(Object[] array, String separator)
Create a string based on all the objects in the array separated by the separator string.

Parameters: array The items that will be concatenated together separator The separator string.

Returns: The new concatenated string.

join

public static String join(Collection collection, String separator)
Create a string based on all the objects in the collection separated by the separator string.

Parameters: separator The separator string. collection The collection containing the objects to join

Returns: The new concatenated string.

joinArray

private static String joinArray(Object array, String separator)
Create a string based on all the objects in the array separated by the separator string.

Parameters: array The items that will be concatenated together separator The separator string.

Returns: The new concatenated string.

nCopies

public static String nCopies(int copyCount, char charToCopy)
Return a string containing the specified number of charToCopy

Parameters: copyCount The number of times to copy the character. charToCopy The character that will be copied.

Returns: The new string.

replace

public static String replace(String sourceString, String match, String replace)
Perform text substitutions in the source string

Parameters: sourceString The original string match The string to replace replace The new content to replace with

Returns: A new string with all the substitutions done

split

public static String[] split(String line, String separator)
Split the specified line into strings, spliting at each instance of separator.

Parameters: line The line to be split. separator The separator that will be used to split the string.

Returns: An array containing the strings

splitAtFirst

public static String[] splitAtFirst(String line, String separator)
Split the specified line into two strings, spliting at the first instance of separator.

Parameters: line The line to be split. separator The separator that will be used to split the string.

Returns: An array containing the two strings.