org.schmant.support.util
Class FlatteningList<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by org.schmant.support.util.FlatteningList<T>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess

public class FlatteningList<T>
extends ArrayList<T>

This is a list of object that flattens all collections and arrays added to. All objects contained in an added array or collection are extracted and added to the list at the place of the array or collection. Objects that themselves are arrays or lists are flattened again, recursively.

This list is often used to contain values for tasks that have interpreted properties that can have several values.

Some script language implementations have their own array types. A ScriptExecutor can register a FlatteningListDecorator with the registerDecorator(FlatteningListDecorator) method to make the FlatteningList able to flatten its array types too.

Since:
1.0
Author:
Karl Gustafsson
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FlatteningList()
           
FlatteningList(int capacity)
           
 
Method Summary
 void add(int index, Object o, ObjectTransformer<T> transformer)
           
 void add(int index, T o)
           
 void add(Object o, ObjectTransformer<T> transformer)
          Add one or several objects.
 boolean add(T o)
           
 boolean addAll(Collection<? extends T> c)
           
 boolean addAll(int index, Collection<? extends T> c)
           
static void registerDecorator(FlatteningListDecorator d)
          Register a decorator.
 T set(int index, T o)
           
 
Methods inherited from class java.util.ArrayList
clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

FlatteningList

public FlatteningList()

FlatteningList

public FlatteningList(int capacity)
Method Detail

registerDecorator

public static void registerDecorator(FlatteningListDecorator d)
Register a decorator.

Parameters:
d - The decorator

add

public boolean add(T o)
Specified by:
add in interface Collection<T>
Specified by:
add in interface List<T>
Overrides:
add in class ArrayList<T>

add

public void add(int index,
                T o)
         throws UnsupportedOperationException
Specified by:
add in interface List<T>
Overrides:
add in class ArrayList<T>
Throws:
UnsupportedOperationException

add

public void add(Object o,
                ObjectTransformer<T> transformer)
Add one or several objects. Each added object is transformed into the target type by the supplied transformer.

Parameters:
o - The object or objects to add.
transformer - The transformer used to transform each added object into the target type.

addAll

public boolean addAll(Collection<? extends T> c)
Specified by:
addAll in interface Collection<T>
Specified by:
addAll in interface List<T>
Overrides:
addAll in class ArrayList<T>

add

public void add(int index,
                Object o,
                ObjectTransformer<T> transformer)

addAll

public boolean addAll(int index,
                      Collection<? extends T> c)
               throws UnsupportedOperationException
Specified by:
addAll in interface List<T>
Overrides:
addAll in class ArrayList<T>
Throws:
UnsupportedOperationException - Always!

set

public T set(int index,
             T o)
      throws UnsupportedOperationException
Specified by:
set in interface List<T>
Overrides:
set in class ArrayList<T>
Throws:
UnsupportedOperationException - Always!