org.omnaest.utils.structure.iterator
Class IteratorDecoratorSwitchable<E>

java.lang.Object
  extended by org.omnaest.utils.structure.iterator.IteratorDecoratorSwitchable<E>
All Implemented Interfaces:
Iterator<E>

public class IteratorDecoratorSwitchable<E>
extends Object
implements Iterator<E>

This is a switchable Iterator decorator, which holds a List of Iterator instances which it can address. Per default the first available Iterator instance is active.

Author:
Omnaest
See Also:
switchTo(int)

Field Summary
protected  int currentActiveIteratorIndexPosition
           
protected  List<Iterator<E>> iteratorList
           
 
Constructor Summary
IteratorDecoratorSwitchable(Iterable<Iterator<E>> iteratorList)
           
IteratorDecoratorSwitchable(Iterator<E>... iterators)
           
 
Method Summary
 Iterator<E> getActiveIterator()
          Returns the currently active Iterator instance or null, if no instance is active.
 List<Iterator<E>> getIteratorList()
           
 boolean hasActiveIterator()
          Returns true, if there is an active Iterator instance set
 boolean hasNext()
           
 E next()
           
 void remove()
           
 IteratorDecoratorSwitchable<E> switchTo(int iteratorIndexPosition)
          Switches to the Iterator instance which has the given iterator index position within the getIteratorList()
 IteratorDecoratorSwitchable<E> switchTo(Iterator<E> iterator)
          Similar to switchTo(int) but resolving the right Iterator instance using the given Iterator.
 IteratorDecoratorSwitchable<E> switchToNext()
          Switches the active Iterator to the next Iterator
 IteratorDecoratorSwitchable<E> switchToNextIteratorWhichHasNext()
          Switches to the next Iterator instance which returns true for Iterator.hasNext(), but only if the getActiveIterator() does not return true for Iterator.hasNext() itself already.
 IteratorDecoratorSwitchable<E> switchToPrevious()
          Switches the active Iterator to the previous Iterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iteratorList

protected final List<Iterator<E>> iteratorList

currentActiveIteratorIndexPosition

protected int currentActiveIteratorIndexPosition
Constructor Detail

IteratorDecoratorSwitchable

public IteratorDecoratorSwitchable(Iterable<Iterator<E>> iteratorList)
Parameters:
iteratorList -
See Also:
IteratorDecoratorSwitchable

IteratorDecoratorSwitchable

public IteratorDecoratorSwitchable(Iterator<E>... iterators)
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<E>

next

public E next()
Specified by:
next in interface Iterator<E>

remove

public void remove()
Specified by:
remove in interface Iterator<E>

getActiveIterator

public Iterator<E> getActiveIterator()
Returns the currently active Iterator instance or null, if no instance is active.

Returns:

switchTo

public IteratorDecoratorSwitchable<E> switchTo(int iteratorIndexPosition)
Switches to the Iterator instance which has the given iterator index position within the getIteratorList()

Parameters:
iteratorIndexPosition -
Returns:
this

switchTo

public IteratorDecoratorSwitchable<E> switchTo(Iterator<E> iterator)
Similar to switchTo(int) but resolving the right Iterator instance using the given Iterator. This means if the given Iterator instance is not contained within the internal list, it will not be activated.

Parameters:
iterator -
Returns:
this
See Also:
getIteratorList()

switchToNext

public IteratorDecoratorSwitchable<E> switchToNext()
Switches the active Iterator to the next Iterator

Returns:
this

switchToPrevious

public IteratorDecoratorSwitchable<E> switchToPrevious()
Switches the active Iterator to the previous Iterator

Returns:
this

switchToNextIteratorWhichHasNext

public IteratorDecoratorSwitchable<E> switchToNextIteratorWhichHasNext()
Switches to the next Iterator instance which returns true for Iterator.hasNext(), but only if the getActiveIterator() does not return true for Iterator.hasNext() itself already.

Returns:
this

hasActiveIterator

public boolean hasActiveIterator()
Returns true, if there is an active Iterator instance set

Returns:

getIteratorList

public List<Iterator<E>> getIteratorList()
Returns:
the iteratorList


Copyright © 2013. All Rights Reserved.