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

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

public class ListIteratorDecoratorSwitchable<E>
extends Object
implements ListIterator<E>

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

Author:
Omnaest

Field Summary
protected  int currentActiveListIteratorIndexPosition
           
protected  List<ListIterator<E>> listIteratorList
           
 
Constructor Summary
ListIteratorDecoratorSwitchable(Iterable<ListIterator<E>> iteratorList)
           
ListIteratorDecoratorSwitchable(ListIterator<E>... iterators)
           
 
Method Summary
 void add(E e)
           
 ListIterator<E> getActiveListIterator()
          Returns the currently active ListIterator instance or null, if no instance is active.
 List<ListIterator<E>> getListIteratorList()
           
 boolean hasActiveListIterator()
          Returns true, if there is an active Iterator instance set
 boolean hasNext()
           
 boolean hasNextListIteratorToSwitchTo()
          Returns true if switchToNext() will find another active ListIterator
 boolean hasPrevious()
           
 boolean hasPreviousListIteratorToSwitchTo()
          Returns true if switchToPrevious() will find another active ListIterator
 E next()
           
 int nextIndex()
           
 E previous()
           
 int previousIndex()
           
 void remove()
           
 void set(E e)
           
 ListIteratorDecoratorSwitchable<E> switchTo(int listIteratorIndexPosition)
          Switches to the ListIterator instance which has the given list iterator index position within the getListIteratorList()
 ListIteratorDecoratorSwitchable<E> switchTo(ListIterator<E> listIterator)
          Similar to switchTo(int) but resolving the right ListIterator instance using the given ListIterator.
 ListIteratorDecoratorSwitchable<E> switchToNext()
          Switches the active ListIterator to the next ListIterator
 ListIteratorDecoratorSwitchable<E> switchToNextIteratorWhichHasNext()
          Switches to the next ListIterator instance which returns true for ListIterator.hasNext(), but only if the getActiveListIterator() does not return true for ListIterator.hasNext() itself already.
 ListIteratorDecoratorSwitchable<E> switchToPrevious()
          Switches the active ListIterator to the previous ListIterator
 ListIteratorDecoratorSwitchable<E> switchToPreviousIteratorWhichHasPrevious()
          Switches to the next ListIterator instance which returns true for ListIterator.hasNext(), but only if the getActiveListIterator() does not return true for ListIterator.hasNext() itself already.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listIteratorList

protected final List<ListIterator<E>> listIteratorList

currentActiveListIteratorIndexPosition

protected int currentActiveListIteratorIndexPosition
Constructor Detail

ListIteratorDecoratorSwitchable

public ListIteratorDecoratorSwitchable(Iterable<ListIterator<E>> iteratorList)
Parameters:
iteratorList -
See Also:
ListIteratorDecoratorSwitchable

ListIteratorDecoratorSwitchable

public ListIteratorDecoratorSwitchable(ListIterator<E>... iterators)
Method Detail

hasNext

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

next

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

hasPrevious

public boolean hasPrevious()
Specified by:
hasPrevious in interface ListIterator<E>

previous

public E previous()
Specified by:
previous in interface ListIterator<E>

nextIndex

public int nextIndex()
Specified by:
nextIndex in interface ListIterator<E>

previousIndex

public int previousIndex()
Specified by:
previousIndex in interface ListIterator<E>

remove

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

set

public void set(E e)
Specified by:
set in interface ListIterator<E>

add

public void add(E e)
Specified by:
add in interface ListIterator<E>

getActiveListIterator

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

Returns:

switchTo

public ListIteratorDecoratorSwitchable<E> switchTo(int listIteratorIndexPosition)
Switches to the ListIterator instance which has the given list iterator index position within the getListIteratorList()

Parameters:
listIteratorIndexPosition -
Returns:
this

switchTo

public ListIteratorDecoratorSwitchable<E> switchTo(ListIterator<E> listIterator)
Similar to switchTo(int) but resolving the right ListIterator instance using the given ListIterator. This means if the given ListIterator instance is not contained within the internal List, it will not be activated.

Parameters:
listIterator -
Returns:
this
See Also:
getListIteratorList()

switchToNext

public ListIteratorDecoratorSwitchable<E> switchToNext()
Switches the active ListIterator to the next ListIterator

Returns:
this

switchToPrevious

public ListIteratorDecoratorSwitchable<E> switchToPrevious()
Switches the active ListIterator to the previous ListIterator

Returns:
this

switchToNextIteratorWhichHasNext

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

Returns:
this

switchToPreviousIteratorWhichHasPrevious

public ListIteratorDecoratorSwitchable<E> switchToPreviousIteratorWhichHasPrevious()
Switches to the next ListIterator instance which returns true for ListIterator.hasNext(), but only if the getActiveListIterator() does not return true for ListIterator.hasNext() itself already.

Returns:
this

hasPreviousListIteratorToSwitchTo

public boolean hasPreviousListIteratorToSwitchTo()
Returns true if switchToPrevious() will find another active ListIterator

Returns:

hasNextListIteratorToSwitchTo

public boolean hasNextListIteratorToSwitchTo()
Returns true if switchToNext() will find another active ListIterator

Returns:

hasActiveListIterator

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

Returns:

getListIteratorList

public List<ListIterator<E>> getListIteratorList()
Returns:
the iteratorList


Copyright © 2013. All Rights Reserved.