uk.co.mullsoft.jean.components
Class CharacterSeparatedString

java.lang.Object
  extended by uk.co.mullsoft.jean.components.CharacterSeparatedString

public class CharacterSeparatedString
extends java.lang.Object

This class provides utility methods to parse and construct character separated Strings; these are a sequence of Strings separated by a specific character so they can be transmitted as a single String. The Strings can contain quoted elements that can contain the separator character.

Note that StringTokenizer has not been used because it cannot handle quotes, and StreamTokenizer has not been used because of the overheads of using streams on a relatively simple example of tokenizing.

Author:
mike.curtis

Method Summary
static java.lang.String allButLast(java.lang.String str, char separator)
          return all but the last element of the string
static java.lang.String construct(byte[] intA, char separator)
          Construct a character separated String from the given float array
static java.lang.String construct(double[] intA, char separator)
          Construct a character separated String from the given double array
static java.lang.String construct(float[] intA, char separator)
          Construct a character separated String from the given float array
static java.lang.String construct(int[] intA, char separator)
          Construct a character separated String from the given int array
static java.lang.String construct(long[] intA, char separator)
          Construct a character separated String from the given long array
static java.lang.String construct(java.lang.String[] strA, char separator)
          Construct a character separated String from the given String array
static java.lang.String last(java.lang.String str, char separator)
          return the last element of the string
static void main(java.lang.String[] args)
          test the parsing and construction.
static java.lang.String[] parse(java.lang.String str, char separator)
          Parse a character separated String into a String array
static byte[] parseBytes(java.lang.String str, char separator)
          Parse a character separated String into a byte array
static double[] parseDoubles(java.lang.String str, char separator)
          Parse a character separated String into a double array
static float[] parseFloats(java.lang.String str, char separator)
          Parse a character separated String into a double array
static int[] parseInts(java.lang.String str, char separator)
          Parse a character separated String into a double array
static long[] parseLongs(java.lang.String str, char separator)
          Parse a character separated String into a long array
static java.lang.String[] parseTrim(java.lang.String str, char separator)
          Parse a character separated String into a String array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public static java.lang.String[] parse(java.lang.String str,
                                       char separator)
Parse a character separated String into a String array

Parameters:
str - a character separated String
separator - the separator character to use
Returns:
a String array each element of which is one of the tokens from the original String

parseTrim

public static java.lang.String[] parseTrim(java.lang.String str,
                                           char separator)
Parse a character separated String into a String array

Parameters:
str - a character separated String
separator - the separator character to use
Returns:
a String array each element of which is one of the tokens from the original String

parseLongs

public static long[] parseLongs(java.lang.String str,
                                char separator)
Parse a character separated String into a long array

Parameters:
str - a character separated String
separator - the separator character to use
Returns:
a long array each element of which is one of the tokens from the original String parsed as a long, null if any of the tokens do not parse.

parseBytes

public static byte[] parseBytes(java.lang.String str,
                                char separator)
Parse a character separated String into a byte array

Parameters:
str - a character separated String
separator - the separator character to use
Returns:
a byte array each element of which is one of the tokens from the original String parsed as a byte, null if any of the tokens do not parse.

parseDoubles

public static double[] parseDoubles(java.lang.String str,
                                    char separator)
Parse a character separated String into a double array

Parameters:
str - a character separated String
separator - the separator character to use the original String parsed as a double, null if any of the tokens do not parse.
Returns:
a long array each element of which is one of the tokens from

parseFloats

public static float[] parseFloats(java.lang.String str,
                                  char separator)
Parse a character separated String into a double array

Parameters:
str - a character separated String
separator - the separator character to use the original String parsed as a double, null if any of the tokens do not parse.
Returns:
a long array each element of which is one of the tokens from

parseInts

public static int[] parseInts(java.lang.String str,
                              char separator)
Parse a character separated String into a double array

Parameters:
str - a character separated String
separator - the separator character to use the original String parsed as a double, null if any of the tokens do not parse.
Returns:
a long array each element of which is one of the tokens from

construct

public static java.lang.String construct(java.lang.String[] strA,
                                         char separator)
Construct a character separated String from the given String array

Parameters:
strA - a String array
separator - the separator character to use
Returns:
a character separated String each token being an element of the array, quoted if it contains the separator character.

construct

public static java.lang.String construct(int[] intA,
                                         char separator)
Construct a character separated String from the given int array

Parameters:
intA - an int array
separator - the separator character to use
Returns:
a character separated String each token being an element of the array, quoted if it contains the separator character.

construct

public static java.lang.String construct(long[] intA,
                                         char separator)
Construct a character separated String from the given long array

Parameters:
intA - a long array
separator - the separator character to use
Returns:
a character separated String each token being an element of the array, quoted if it contains the separator character.

construct

public static java.lang.String construct(double[] intA,
                                         char separator)
Construct a character separated String from the given double array

Parameters:
intA - a double array
separator - the separator character to use
Returns:
a character separated String each token being an element of the array, quoted if it contains the separator character.

construct

public static java.lang.String construct(float[] intA,
                                         char separator)
Construct a character separated String from the given float array

Parameters:
intA - a float array
separator - the separator character to use
Returns:
a character separated String each token being an element of the array, quoted if it contains the separator character.

construct

public static java.lang.String construct(byte[] intA,
                                         char separator)
Construct a character separated String from the given float array

Parameters:
intA - a float array
separator - the separator character to use
Returns:
a character separated String each token being an element of the array, quoted if it contains the separator character.

last

public static java.lang.String last(java.lang.String str,
                                    char separator)
return the last element of the string

Returns:
the last element of the string

allButLast

public static java.lang.String allButLast(java.lang.String str,
                                          char separator)
return all but the last element of the string

Returns:
all but the last element of the string

main

public static void main(java.lang.String[] args)
test the parsing and construction. If a single argument is provided it is parsed; if more than one then they are constructed into a single String

Parameters:
args - one or more string arguments.