consciouscode.util
Class Strings

java.lang.Object
  extended by consciouscode.util.Strings

public final class Strings
extends Object

Utility methods for String manipulation.


Field Summary
static String[] EMPTY_ARRAY
           
 
Constructor Summary
Strings()
           
 
Method Summary
static String cleanup(String string, String emptyValue)
          Trims any whitespace from a String, converting empty results to a specific value.
static boolean containsDigits(String string)
          Determine whether a string has any digit characters.
static String emptyToNull(String string)
          Return null if a String equals "", return the String otherwise.
static boolean equal(String left, String right)
          Compare two Strings for equality.
static String join(Iterator<?> elements, String separator)
          Deprecated. Use Apache Commons StringUtils.join(Iterator,String)
static void join(Iterator<?> elements, String separator, StringBuffer buffer)
          Concatenates elements into a StringBuffer, inserting separator between elements.
static String join(Object elements, String separator)
          Concatenates a collection of elements into one String, inserting separator between elements.
static void join(Object elements, String separator, StringBuffer buffer)
          Concatenates elements into a StringBuffer, inserting separator between elements.
static double parseDouble(String stringValue, double defaultResult)
          Attempts to parse a String into a double.
static float parseFloat(String stringValue, float defaultResult)
          Attempts to parse a String into a float.
static int parseInt(String stringValue, int defaultResult)
          Attempts to parse a String into an int.
static ArrayList<String> splitAndCleanup(String joinedStrings, String delim)
          Splits a single string into a sequence.
static ArrayList<String> splitAndCleanup(String joinedStrings, String delim, String emptyValue)
          Splits a single string into a sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

public static final String[] EMPTY_ARRAY
Constructor Detail

Strings

public Strings()
Method Detail

equal

public static boolean equal(String left,
                            String right)
Compare two Strings for equality. If only one argument is null, return false.


emptyToNull

public static String emptyToNull(String string)
Return null if a String equals "", return the String otherwise.


cleanup

public static String cleanup(String string,
                             String emptyValue)
Trims any whitespace from a String, converting empty results to a specific value.

Parameters:
emptyValue - is the result if string is null or empty after being trimmed.

join

public static String join(Object elements,
                          String separator)
Concatenates a collection of elements into one String, inserting separator between elements.

Each element is converted to a String value using Object.toString(). Empty strings are not removed.

Parameters:
elements - must be one of: Iterator, Enumeration, Collection, Map, Object[], or primitive array.
See Also:
IteratorUtils.getIterator(java.lang.Object)

join

@Deprecated
public static String join(Iterator<?> elements,
                                     String separator)
Deprecated. Use Apache Commons StringUtils.join(Iterator,String)

Concatenates elements into one String, inserting separator between elements.

Each element is converted to a String value using Object.toString(). Empty strings are not removed.


join

public static void join(Object elements,
                        String separator,
                        StringBuffer buffer)
Concatenates elements into a StringBuffer, inserting separator between elements.

Each element is converted to a String value using Object.toString(). Empty strings are not removed.

Parameters:
elements - must be one of: Iterator, Enumeration, Collection, Map, Object[], or primitive array.
See Also:
IteratorUtils.getIterator(java.lang.Object)

join

public static void join(Iterator<?> elements,
                        String separator,
                        StringBuffer buffer)
Concatenates elements into a StringBuffer, inserting separator between elements.

Each element is converted to a String value using Object.toString(). Empty strings are not removed.


splitAndCleanup

public static ArrayList<String> splitAndCleanup(String joinedStrings,
                                                String delim)
Splits a single string into a sequence. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.

Each element string is trimmed of leading and trailing whitespace. Any empty strings are removed from the list.

This method is primarily a wrapper around a StringTokenizer.

See Also:
splitAndCleanup(String, String, String)

splitAndCleanup

public static ArrayList<String> splitAndCleanup(String joinedStrings,
                                                String delim,
                                                String emptyValue)
Splits a single string into a sequence. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.

Each element string is trimmed of leading and trailing whitespace. Any empty strings (after trimming) are replaced by emptyValue and left in the list.

This method is primarily a wrapper around a StringTokenizer.

See Also:
splitAndCleanup(String, String)

containsDigits

public static boolean containsDigits(String string)
Determine whether a string has any digit characters.


parseInt

public static int parseInt(String stringValue,
                           int defaultResult)
Attempts to parse a String into an int.

Returns:
the integer derived from stringValue, or defaultResult if stringValue is null or has an illegal format.
See Also:
Integer.parseInt(java.lang.String)

parseFloat

public static float parseFloat(String stringValue,
                               float defaultResult)
Attempts to parse a String into a float.

Returns:
the float derived from stringValue, or defaultResult if stringValue is null or has an illegal format.
See Also:
Float.parseFloat(java.lang.String)

parseDouble

public static double parseDouble(String stringValue,
                                 double defaultResult)
Attempts to parse a String into a double.

Returns:
the double derived from stringValue, or defaultResult if stringValue is null or has an illegal format.
See Also:
Double.parseDouble(java.lang.String)


Copyright © 2001–2012 Todd V. Jonker. All Rights Reserved.