2004.04.29


com.jdc.type
Class StringHelper

java.lang.Object
  |
  +--jdc.java.lang.Object
        |
        +--com.jdc.lang.ObjectHelper
              |
              +--com.jdc.type.StringHelper

public class StringHelper
extends ObjectHelper

StringHelper is a utility class that provides advanced String manipulation methods to simplify the manipulation of String objects.   The following methods are available:

Decimal/Integer/Numeric methods:

Single Quote (') / Double Quote (") methods:

Note: A null value is never returned by the methods in this class that return a String value.  If a null value is passed to a StringHelper method as a parameter, an empty String value is returned to the caller.

The following default character values are in use unless overridden by the caller:

Version:
1.0
Author:
Jay Damon
See Also:
ObjectHelper, Serialized Form

Constructor Summary
StringHelper()
          Constructs a new StringHelper instance.
StringHelper(String quoteCharacter)
          Constructs a new StringHelper instance with the specified default quote character.
 
Method Summary
 String addCommas(String[] array)
          Returns a comma-delimited String corresponding to String array with the String array values trimmed and a space (blank) added between the comma-delimited values.
 String addCommas(String[] array, boolean trim, boolean addSpace)
          Returns a comma-delimited String corresponding to String array.
 String addDoubleQuotes(String string)
          Returns the String value with double quotes added, if not already present.
 String addParentheses(String string)
          Returns the String value with parentheses added, if not already present.
 String addQuotes(String string)
          Returns the String value with quotes added, if not already present.
 String addSingleQuotes(String string)
          Returns the String value with single quotes added, if not already present.
 int intValue(String string)
          Returns the value of this String as an int.
 boolean isDecimal(String string)
          Returns true if the String field contains a Decimal value.
 boolean isDoubleQuoted(String string)
          Returns true if the String value is enclosed in one or more pairs of double quotes.
 boolean isInteger(String string)
          Returns true if the String field contains an Integer value.
 boolean isQuoted(String string)
          Returns true if the String value is enclosed in one or more pairs of the default quote character.
 boolean isSingleQuoted(String string)
          Returns true if the String value is enclosed in one or more pairs of single quotes.
static void main(String[] args)
          Executes unit tests for the StringHelper class.
 String removeAllQuotes(String string)
          Returns the specified String value with all matching single and double quote characters, if any, removed.
 String removeDoubleQuotes(String string)
          Returns the specified String value with all matching double quote characters, if any, removed.
 String removeParentheses(String string)
          Returns the specified String value with all matching parenthesis characters, if any, removed.
 String removeQuotes(String string)
          Returns the specified String value with all matching quote characters, if any, removed.
 String removeSingleQuotes(String string)
          Returns the specified String value with all matching single quote characters, if any, removed.
 StringHelper setDelimiter(String delimiter)
          Sets the default String delimiter character(s).
 StringHelper setQuote(String quoteCharacter)
          Sets the default quote character.
 String[] toArray(ArrayList list)
          Returns a String array corresponding to the ArrayList.
 
Methods inherited from class com.jdc.lang.ObjectHelper
equals, isNoValue, isValue, noValue, toValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringHelper

public StringHelper()
Constructs a new StringHelper instance.


StringHelper

public StringHelper(String quoteCharacter)
Constructs a new StringHelper instance with the specified default quote character.

Method Detail

addCommas

public String addCommas(String[] array)
Returns a comma-delimited String corresponding to String array with the String array values trimmed and a space (blank) added between the comma-delimited values.

Returns:
A comma-delimited String.

addCommas

public String addCommas(String[] array,
                        boolean trim,
                        boolean addSpace)
Returns a comma-delimited String corresponding to String array. Optionally, you may specify that the String array values be trimmed and/or that a space (blank) be added between the delimited values.

Returns:
A comma-delimited String value.

addDoubleQuotes

public String addDoubleQuotes(String string)
Returns the String value with double quotes added, if not already present. If the String value is already enclosed in double quotes, the original String value is returned with any leading or trailing blanks (spaces) removed.

Returns:
A String value enclosed in double quotes.

addParentheses

public String addParentheses(String string)
Returns the String value with parentheses added, if not already present. If the String value is already enclosed in parentheses, the original String value is returned with any leading or trailing blanks (spaces) removed.

Returns:
A String value enclosed in parentheses.

addQuotes

public String addQuotes(String string)
Returns the String value with quotes added, if not already present. If the String value is already enclosed in quotes, the original String value is returned with any leading or trailing blanks (spaces) removed.

Returns:
A String value enclosed in quotes.

addSingleQuotes

public String addSingleQuotes(String string)
Returns the String value with single quotes added, if not already present. If the String value is already enclosed in single quotes, the original String value is returned with any leading or trailing blanks (spaces) removed.

Returns:
A String value enclosed in single quotes.

intValue

public int intValue(String string)
Returns the value of this String as an int. If the String field does not contain a valid int value, 0 (zero) is returned.

Returns:
The int value represented by the String field.

See Also:
isInteger(java.lang.String)

isDecimal

public boolean isDecimal(String string)
Returns true if the String field contains a Decimal value.

Returns:
True if the String field contains a Decimal value.
False if the String field does not contain a Decimal value.

See Also:
isInteger(java.lang.String)

isDoubleQuoted

public boolean isDoubleQuoted(String string)
Returns true if the String value is enclosed in one or more pairs of double quotes.

Returns:
True if the String value is enclosed in double quotes.
False if the String value is not enclosed in double quotes.

isInteger

public boolean isInteger(String string)
Returns true if the String field contains an Integer value.

Returns:
True if the String field contains an Integer value.
False if the String field does not contain an Integer value.

See Also:
intValue(java.lang.String)

isSingleQuoted

public boolean isSingleQuoted(String string)
Returns true if the String value is enclosed in one or more pairs of single quotes.

Returns:
True if the String value is enclosed in single quotes.
False if the String value is not enclosed in single quotes.

isQuoted

public boolean isQuoted(String string)
Returns true if the String value is enclosed in one or more pairs of the default quote character.

Returns:
True if the String value is enclosed in quotes.
False if the String value is not enclosed in quotes.

removeAllQuotes

public String removeAllQuotes(String string)
Returns the specified String value with all matching single and double quote characters, if any, removed. If the String value is not enclosed in single or double quotes, the original String value is returned.

Returns:
A String value without any quotes.

removeDoubleQuotes

public String removeDoubleQuotes(String string)
Returns the specified String value with all matching double quote characters, if any, removed. If the String value is not enclosed in double quotes, the original String value is returned.

Returns:
A String value without double quotes.

removeParentheses

public String removeParentheses(String string)
Returns the specified String value with all matching parenthesis characters, if any, removed. If the String value is not enclosed in parentheses, the original String value is returned.

Returns:
A String value without parentheses.

removeQuotes

public String removeQuotes(String string)
Returns the specified String value with all matching quote characters, if any, removed. If the String value is not enclosed in quotes, the original String value is returned.

Returns:
A String value without quotes.

removeSingleQuotes

public String removeSingleQuotes(String string)
Returns the specified String value with all matching single quote characters, if any, removed. If the String value is not enclosed in single quotes, the original String value is returned.

Returns:
A String value without single quotes.

setQuote

public StringHelper setQuote(String quoteCharacter)
Sets the default quote character. Valid quote characters are single quote (') and double quote (") only.


setDelimiter

public StringHelper setDelimiter(String delimiter)
Sets the default String delimiter character(s).


toArray

public String[] toArray(ArrayList list)
Returns a String array corresponding to the ArrayList. with the String array values trimmed, i.e. leading and trailing spaces (blanks) are removed.

Returns:
A String array.

main

public static void main(String[] args)
Executes unit tests for the StringHelper class.


2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.