org.spicefactory.cinnamon.reflect.convert
Class CollectionConverter

java.lang.Object
  extended by org.spicefactory.cinnamon.reflect.convert.AbstractSequenceConverter<Collection<?>>
      extended by org.spicefactory.cinnamon.reflect.convert.CollectionConverter
All Implemented Interfaces:
Converter<Collection<?>>

public class CollectionConverter
extends AbstractSequenceConverter<Collection<?>>

Converter implementation that creates Collection instances of the required target type from any sequence (Collection or Array). This might include conversion of elements of that sequence to the required type.

Author:
Jens Halm

Constructor Summary
CollectionConverter(ReflectionFactory factory)
           
 
Method Summary
protected  void addElement(Collection c, Object element, int index)
          Adds the given element to the sequence (Array or Collection) at the specified index.
protected  Collection<?> createInstance(TypeContext typeContext, int size, Object originalValue)
          Create a new instance for the required target type.
protected  Type getElementType(TypeContext typeContext)
          Return the generic element type of the sequence (Array or Collection).
 
Methods inherited from class org.spicefactory.cinnamon.reflect.convert.AbstractSequenceConverter
convert, getIterator, getSize, supports
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionConverter

public CollectionConverter(ReflectionFactory factory)
Method Detail

createInstance

protected Collection<?> createInstance(TypeContext typeContext,
                                       int size,
                                       Object originalValue)
Description copied from class: AbstractSequenceConverter
Create a new instance for the required target type. The given TypeContext instance gives additional hints on the exact required type of the sequence (i.e. a Set or List or an Array of Numbers).

Specified by:
createInstance in class AbstractSequenceConverter<Collection<?>>
Parameters:
typeContext - the context from which the required type of the new instance be obtained
size - the size of the Array/Collection to create
originalValue - the original value (Array or Collection - mainly for logging purposes)
Returns:
the new instance

getElementType

protected Type getElementType(TypeContext typeContext)
Description copied from class: AbstractSequenceConverter
Return the generic element type of the sequence (Array or Collection).

Specified by:
getElementType in class AbstractSequenceConverter<Collection<?>>
Parameters:
typeContext - the context from which the element type can be obtained
Returns:
the generic element type of the sequence (Array or Collection)

addElement

protected void addElement(Collection c,
                          Object element,
                          int index)
Description copied from class: AbstractSequenceConverter
Adds the given element to the sequence (Array or Collection) at the specified index.

Specified by:
addElement in class AbstractSequenceConverter<Collection<?>>
Parameters:
c - the sequence (Array or Collection) the item should be added to
element - the new element to be added
index - the index at which the element should be added