org.inria.ns.reflex.util
Class DynamicList.Impl

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by org.inria.ns.reflex.util.DynamicList.Impl
All Implemented Interfaces:
Iterable, Collection, List, Unwrappable, DynamicList
Direct Known Subclasses:
GroupFunction.OuterList
Enclosing interface:
DynamicList

public static class DynamicList.Impl
extends AbstractList
implements DynamicList, Unwrappable

A dynamic list backed by an iterator. This list must be read sequentially. Once an item is read, the previous ones are lost and can't be accessed no longer, except the nearest previous one. That is to say that only 2 items are known by this list.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.util.DynamicList
DynamicList.AbstractCompleted, DynamicList.Completed, DynamicList.Impl
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Unwrappable
Unwrappable.Unwrapper
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.structures.Unwrappable
UNWRAPPER
 
Constructor Summary
DynamicList.Impl(Iterator iterator)
          Create a new list backed by an iterator.
 
Method Summary
 boolean completed()
          Return true when there are no more items in the underlying iterator, false otherwise.
 Object get(int index)
          Retrieve the item at the index specified ; as it is backed by an iterator, this list can be browsed sequentially and doesn't retain any item previously read except the nearest previous one.
 int getCurrent()
          Return the current index.
 int size()
          Return the size of this list, that grows until the last item of the underlying iterator is encountered.
 Object unwrap()
          Return the wrapped iterator.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, 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
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

DynamicList.Impl

public DynamicList.Impl(Iterator iterator)
Create a new list backed by an iterator.

Parameters:
iterator - The underlying iterator.
Method Detail

get

public Object get(int index)
Retrieve the item at the index specified ; as it is backed by an iterator, this list can be browsed sequentially and doesn't retain any item previously read except the nearest previous one.

Specified by:
get in interface List
Specified by:
get in class AbstractList
Throws:
IndexOutOfBoundsException - If the index is out of the range of this list.
NoSuchElementException - If the index has been already read and it is not the previous one neither the current one.
See Also:
AbstractList.get(int)

size

public int size()
Return the size of this list, that grows until the last item of the underlying iterator is encountered.

Specified by:
size in interface Collection
Specified by:
size in interface List
Specified by:
size in class AbstractCollection
Returns:
The size of this list, that is always 1+ the position of the last item if there exists a next item in the underlying iterator.
See Also:
AbstractCollection.size()

getCurrent

public int getCurrent()
Return the current index.

Returns:
The index of the last item available, -1 if not yet read.

completed

public boolean completed()
Return true when there are no more items in the underlying iterator, false otherwise.

Specified by:
completed in interface DynamicList
Returns:
true if the underlying iterator has been browsed entirely, false otherwise.
See Also:
DynamicList.completed()

unwrap

public Object unwrap()
Return the wrapped iterator.

Specified by:
unwrap in interface Unwrappable
Returns:
An Iterator
See Also:
Unwrappable.unwrap()