net.sf.molae.pipe.genimpl
Class IndexedList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by net.sf.molae.pipe.genimpl.IndexedList<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>

public class IndexedList<E>
extends AbstractList<E>

A list with an index to its entries. This list is performant for fixed-size lists. add and remove should not be used. Duplicate entries are allowed.

Since:
1.1

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
IndexedList(List<E> base)
          Constructs an indexed list object.
 
Method Summary
 boolean add(E o)
           
 void add(int index, E element)
           
 void clear()
           
 boolean contains(Object o)
           
 E get(int index)
           
 Map<E,Integer> getPositions()
          Returns the positions map.
 int indexOf(Object o)
           
protected  void putPosition(int index, E element)
          Checks if the specified element is a new element in the list or at the first position and changes the position map accordingly.
protected  void recalculatePositions()
          Recalculates the index map.
 E remove(int index)
           
 boolean remove(Object o)
           
 E set(int index, E element)
           
 int size()
           
 
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, 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
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

IndexedList

public IndexedList(List<E> base)
Constructs an indexed list object.

Parameters:
base - the base list containing the list entries
Method Detail

getPositions

public Map<E,Integer> getPositions()
Returns the positions map.

Returns:
the positions map.

recalculatePositions

protected void recalculatePositions()
Recalculates the index map.


putPosition

protected void putPosition(int index,
                           E element)
Checks if the specified element is a new element in the list or at the first position and changes the position map accordingly.

Parameters:
index - index of new element
element - newly entered element

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractCollection<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface List<E>
Overrides:
contains in class AbstractCollection<E>

add

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

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove in class AbstractCollection<E>

clear

public void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class AbstractList<E>

get

public E get(int index)
Specified by:
get in interface List<E>
Specified by:
get in class AbstractList<E>

set

public E set(int index,
             E element)
Specified by:
set in interface List<E>
Overrides:
set in class AbstractList<E>

add

public void add(int index,
                E element)
Specified by:
add in interface List<E>
Overrides:
add in class AbstractList<E>

remove

public E remove(int index)
Specified by:
remove in interface List<E>
Overrides:
remove in class AbstractList<E>

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<E>
Overrides:
indexOf in class AbstractList<E>