sbrt.shell.text
Class AbstractListFormat<E>

java.lang.Object
  extended by sbrt.shell.text.AbstractListFormat<E>
Type Parameters:
E - the type of element.
All Implemented Interfaces:
Formatter<java.util.List<? extends E>>, ListFormat<E>, Parser<java.util.List<E>>
Direct Known Subclasses:
PipeListFormat, TabListFormat, WhitespaceListFormat

public abstract class AbstractListFormat<E>
extends java.lang.Object
implements ListFormat<E>

This abstract class is a skeleton implementation of ListFormat. A concrete class with a defined format can be created by simply overriding the constructor of this class.

Author:
This class was written and documented by Jeremiah Wright while in the Wagner lab.

Constructor Summary
AbstractListFormat(java.lang.String delimiter, java.util.regex.Pattern regex, Formatter<E> elementFormatter, Parser<E> elementParser)
          Constructs a new list format from the provided arguments.
AbstractListFormat(java.lang.String delimiter, java.util.regex.Pattern regex, SimpleFormat<E> elementFormat)
          Constructs a new list format from the provided arguments.
 
Method Summary
 java.lang.String format(java.util.List<? extends E> c)
          Returns a formatted string representation of the provided collection.
 java.lang.String getDelimiter()
          Returns the delimiter used to separate elements when producing a formatted string.
 Formatter<E> getElementFormatter()
          Returns the formatter for the elements of this LinkedHashSet format.
 Parser<E> getElementParser()
          Returns the parser for the elements of this set format.
 java.util.regex.Pattern getRegex()
          Returns the regular expression used to separate elements when parsing a formatted string.
 java.util.List<E> parse(java.lang.String list)
          Parses the provided string and returns its corresponding collection of elements as a list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sbrt.shell.text.Formatter
format
 

Constructor Detail

AbstractListFormat

public AbstractListFormat(java.lang.String delimiter,
                          java.util.regex.Pattern regex,
                          SimpleFormat<E> elementFormat)
Constructs a new list format from the provided arguments.

Parameters:
delimiter - the delimiter used to separate elements of lists when producing a formatted string representation.
regex - the regular expression used to parse a string representation of a list with this format. The method call regex.split(String) should return an array containing the string representation of the elements of the provided list string.
elementFormat - the format used for elements the of lists with this format.
Throws:
java.lang.NullPointerException - if any provided argument is null.

AbstractListFormat

public AbstractListFormat(java.lang.String delimiter,
                          java.util.regex.Pattern regex,
                          Formatter<E> elementFormatter,
                          Parser<E> elementParser)
Constructs a new list format from the provided arguments.

Parameters:
delimiter - the delimiter used to separate elements of lists when producing a formatted string representation.
regex - the regular expression used to parse a string representation of a list with this format. The method call regex.split(String) should return an array containing the string representation of the elements of the provided list string.
elementFormatter - the formatter used for elements the of lists with this format.
elementParser - the parser used for elements the of lists with this format.
Throws:
java.lang.NullPointerException - if any provided argument is null.
Method Detail

getDelimiter

public java.lang.String getDelimiter()
Returns the delimiter used to separate elements when producing a formatted string.

Returns:
the delimiter used to separate elements when producing a formatted string.

getRegex

public java.util.regex.Pattern getRegex()
Returns the regular expression used to separate elements when parsing a formatted string.

Returns:
the regular expression used to separate elements when parsing a formatted string.

getElementFormatter

public Formatter<E> getElementFormatter()
Returns the formatter for the elements of this LinkedHashSet format.

Specified by:
getElementFormatter in interface ListFormat<E>
Returns:
the formatter for the elements of this LinkedHashSet format.

getElementParser

public Parser<E> getElementParser()
Returns the parser for the elements of this set format.

Specified by:
getElementParser in interface ListFormat<E>
Returns:
the parser for the elements of this set format.

format

public java.lang.String format(java.util.List<? extends E> c)
Returns a formatted string representation of the provided collection.

Specified by:
format in interface ListFormat<E>
Parameters:
c - the collection to be formatted.
Returns:
a formatted string representation of the provided collection.

parse

public java.util.List<E> parse(java.lang.String list)
Parses the provided string and returns its corresponding collection of elements as a list.

Specified by:
parse in interface ListFormat<E>
Specified by:
parse in interface Parser<java.util.List<E>>
Parameters:
list - the string to be parsed.
Returns:
the provided string and returns its corresponding collection of elements as a list.