ch.elca.el4j.util.collections.impl
Class DefaultTransformedList<I,O>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<O>
          extended by ch.elca.el4j.util.collections.impl.DefaultTransformedList<I,O>
Type Parameters:
I - the backing list's element type
O - this list's element type
All Implemented Interfaces:
ExtendedList<O>, ExtendedReorderableList<O>, TransformedList<I,O>, Iterable<O>, Collection<O>, List<O>, RandomAccess

public class DefaultTransformedList<I,O>
extends AbstractList<O>
implements TransformedList<I,O>

Default implementation of TransformedList.

Author:
Adrian Moos (AMS)
File-location:
DefaultTransformedList
Last check-in date:
2009-08-04 14:25:40 +0200 (Di, 04. Aug 2009) by swismer for revision 3874

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DefaultTransformedList(List<? extends I> backing, Function<? super I,O> function)
          Constructor.
 
Method Summary
 FilteredList<O> filtered(Filter<? super O> filter)
          Convenience method returning a filtered view on this collection.
 O get(int index)
          Returns an element of this list.
 List<? extends I> getBacking()
          returns the backing list.
<T> TransformedList<O,T>
mapped(Function<? super O,T> function)
          Convenience method returning a TransformedList view to this list.
 void orderLike(List<? extends O> example)
          Reorders this list's elements by example.
 int size()
          
 void swap(int i, int j)
          exchanges the elements located at indices i and j.
 O[] toArray(Class<O> c)
          
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, subList, toArray, toArray
 

Constructor Detail

DefaultTransformedList

public DefaultTransformedList(List<? extends I> backing,
                              Function<? super I,O> function)
Constructor.

Parameters:
backing - the backing list
function - the transformation function
Method Detail

get

public O get(int index)
Returns an element of this list.

Specified by:
get in interface List<O>
Specified by:
get in class AbstractList<O>
Parameters:
index - the index of the element to return
Returns:
the element

size

public int size()

Specified by:
size in interface Collection<O>
Specified by:
size in interface List<O>
Specified by:
size in class AbstractCollection<O>

swap

public void swap(int i,
                 int j)
exchanges the elements located at indices i and j.

Specified by:
swap in interface ExtendedReorderableList<O>
Parameters:
i - ...
j - ...

orderLike

public void orderLike(List<? extends O> example)
Reorders this list's elements by example. This method makes sure that the result will start with the sublist example as far as element equality is concerned, or throws a NoSuchElementException if this is not possible. In either case, the order of the remaining elements may be affected. This method may require quadratic time.

Formally, if this method completes normally, the condition ∀ i < example.size(); c.apply(this.get(i)).equals(example.get(i)) is true.

Specified by:
orderLike in interface ExtendedReorderableList<O>
Parameters:
example - a list whose elements are in the descired order

toArray

public O[] toArray(Class<O> c)

Specified by:
toArray in interface ExtendedList<O>
Parameters:
c - the element type for the new array
Returns:
an new array containing this list's contents

mapped

public <T> TransformedList<O,T> mapped(Function<? super O,T> function)
Convenience method returning a TransformedList view to this list.

Specified by:
mapped in interface ExtendedList<O>
Parameters:
function - the transformation function to apply to each element
Returns:
see above

getBacking

public List<? extends I> getBacking()
returns the backing list.

Specified by:
getBacking in interface TransformedList<I,O>
Returns:
the backing list.

filtered

public FilteredList<O> filtered(Filter<? super O> filter)
Convenience method returning a filtered view on this collection.

Specified by:
filtered in interface ExtendedList<O>
Parameters:
filter - the filter deciding which elements are included


Copyright © 2005-2011 ELCA. All Rights Reserved.