org.jcoderz.commons.logging
Class CollectionFormat

java.lang.Object
  extended by java.text.Format
      extended by org.jcoderz.commons.logging.CollectionFormat
All Implemented Interfaces:
Serializable, Cloneable

public class CollectionFormat
extends Format

This format is used for formatting a collection. The begin/end pair can be set as well as the separator for the collection items and the formatter for the items.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
Format.Field
 
Constructor Summary
CollectionFormat(Format elementFormat)
          Creates a new instance of this and sets default values for the Strings denoting the begin or end of the collection as well as the separator for the collection items.
CollectionFormat(Format elementFormat, String begin, String end, String separator)
          Creates a new instance of this and configures values for the Strings denoting the begin or end of the collection as well as the separator for the collection items.
 
Method Summary
 StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
          Formats a collection of strings.
 Object parseObject(String source, ParsePosition pos)
           
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionFormat

public CollectionFormat(Format elementFormat)
Creates a new instance of this and sets default values for the Strings denoting the begin or end of the collection as well as the separator for the collection items.

Parameters:
elementFormat - the Format to use for formatting each collection element.

CollectionFormat

public CollectionFormat(Format elementFormat,
                        String begin,
                        String end,
                        String separator)
Creates a new instance of this and configures values for the Strings denoting the begin or end of the collection as well as the separator for the collection items. If teh begin and empty markers are both empty or null, then this might fail to parse empty lists.

Parameters:
elementFormat - the Format to use for formatting each collection element. Must not be null.
begin - The string to set as start of the collection, might be null, then there will be no marker for the start of the collection.
end - The string to set as end of the collection, might be null, then there will be no marker for the end of the collection.
separator - The string to set as separator between collection elements, might be null, then ther will be no separator between the elements.
Method Detail

parseObject

public Object parseObject(String source,
                          ParsePosition pos)
Specified by:
parseObject in class Format
Parameters:
source - The string to parse.
pos - The current position within source
Returns:
null if an error occurs, the collection being parsed from the source string else.
See Also:
Parses the supplied string for creating a list of object. If an error occurs the position is unchanged, the error position is set to the position where it occurred and null is returrned. This expects the configured list begin sequence to start at the current position, the list item to be delimited with the configured delimiter, the latter not being parsed by the list item parser, and the list being terminated by the list end sequence. If the list end sequence is set to null or empty string, then empty lists are not detected.

format

public StringBuffer format(Object obj,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Formats a collection of strings.

Specified by:
format in class Format
Parameters:
obj - the Object to format. Must be a Collection
toAppendTo - the StringBuffer where to append to the formatted Collection.
pos - the field position.
Returns:
StringBuffer where the formatted collection has been appended to.
Throws:
IllegalArgumentException - if obj is not a Collection.
See Also:
Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)


Copyright 2007 The jCoderZ Project.