com.sun.sgs.app.util
Class ScalableList.ScalableListIterator<E>

java.lang.Object
  extended by com.sun.sgs.app.util.ScalableList.ScalableIterator<E>
      extended by com.sun.sgs.app.util.ScalableList.ScalableListIterator<E>
Type Parameters:
E - the type of element
All Implemented Interfaces:
Serializable, Iterator<E>, ListIterator<E>
Enclosing class:
ScalableList<E>

static class ScalableList.ScalableListIterator<E>
extends ScalableList.ScalableIterator<E>
implements ListIterator<E>

A class which implements a ListIterator for the ScalableList data structure. This iterator allows bi-directional traversal and other operations native to the ListIterator interface.


Field Summary
 
Fields inherited from class com.sun.sgs.app.util.ScalableList.ScalableIterator
currentNode, cursor, listNodeReferenceValue, owner, wasNextCalled
 
Constructor Summary
ScalableList.ScalableListIterator(ScalableList<E> list)
          Constructor which starts the iterations at the specified ListNode.
ScalableList.ScalableListIterator(ScalableList<E> list, ScalableList.ListNode<E> startingNode, int startingIndex)
          Constructor which creates a ScalableListIterator given the list, a startingNode and a startingIndex denoting the starting point.
ScalableList.ScalableListIterator(ScalableList<E> list, com.sun.sgs.app.util.ScalableList.SearchResult<E> searchResult)
          Constructor which creates a ScalableListIterator given the list and a searchResult denoting the starting point.
 
Method Summary
 void add(E o)
          Inserts the specified element into the list.
(package private)  void doRemove()
          Performs the remove and updates the references if necessary
 boolean hasPrevious()
          Returns true if this list iterator has more elements when traversing the list in the reverse direction.
(package private) static
<E> boolean
isPrevWithinRange(int offset, ScalableList.ListNode<E> currentListNode)
          Performs a check to see that the index for prev() is still within range of the sub list.
 E next()
          Retrieves the next element.
 int nextIndex()
          Returns the index of the element that would be returned by a subsequent call to next.
 E previous()
          Returns the previous element in the list.
 int previousIndex()
          Returns the index of the element that would be returned by a subsequent call to previous.
 void remove()
          Removes from the underlying collection the last element returned by the iterator.
 void set(E o)
          Replaces the last element returned by next or previous with the specified element (optional operation).
 
Methods inherited from class com.sun.sgs.app.util.ScalableList.ScalableIterator
checkDataIntegrity, getAbsoluteIndex, getCurrentIndex, getCursorBasedOnPreviousAction, hasNext, isNextWithinRange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.ListIterator
hasNext
 

Constructor Detail

ScalableList.ScalableListIterator

ScalableList.ScalableListIterator(ScalableList<E> list)
Constructor which starts the iterations at the specified ListNode.

Parameters:
list - the ScalableList over which to iterate

ScalableList.ScalableListIterator

ScalableList.ScalableListIterator(ScalableList<E> list,
                                  ScalableList.ListNode<E> startingNode,
                                  int startingIndex)
Constructor which creates a ScalableListIterator given the list, a startingNode and a startingIndex denoting the starting point. This constructor is used primarily for when the user specifies an index that is one larger than the highest index value.

Parameters:
list - a reference to the ScalableList
startingIndex - the starting index (relative)
startingNode - the starting node

ScalableList.ScalableListIterator

ScalableList.ScalableListIterator(ScalableList<E> list,
                                  com.sun.sgs.app.util.ScalableList.SearchResult<E> searchResult)
Constructor which creates a ScalableListIterator given the list and a searchResult denoting the starting point.

Parameters:
list -
searchResult -
Method Detail

isPrevWithinRange

static <E> boolean isPrevWithinRange(int offset,
                                     ScalableList.ListNode<E> currentListNode)
Performs a check to see that the index for prev() is still within range of the sub list.

Type Parameters:
E - the type of element stored
Parameters:
offset - the offset
currentListNode - the current ListNode being examined
Returns:
true if the offset exists in the sub list and false otherwise

nextIndex

public int nextIndex()
Returns the index of the element that would be returned by a subsequent call to next. (Returns list size if the list iterator is at the end of the list.)

Specified by:
nextIndex in interface ListIterator<E>
Returns:
the index of the element that would be returned by a subsequent call to next, or list size if list iterator is at end of list.

previousIndex

public int previousIndex()
Returns the index of the element that would be returned by a subsequent call to previous. (Returns -1 if the list iterator is at the beginning of the list.)

Specified by:
previousIndex in interface ListIterator<E>
Returns:
the index of the element that would be returned by a subsequent call to previous, or -1 if list iterator is at beginning of list.

hasPrevious

public boolean hasPrevious()
Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if previous would return an element rather than throwing an exception.)

Specified by:
hasPrevious in interface ListIterator<E>
Returns:
true if the list iterator has more elements when traversing the list in the reverse direction.
Throws:
ConcurrentModificationException - if the ListNode has been modified or removed

previous

public E previous()
Returns the previous element in the list. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Specified by:
previous in interface ListIterator<E>
Returns:
the previous element in the list
Throws:
NoSuchElementException - if the iteration has no previous element
ConcurrentModificationException - if the ListNode has been modified or removed

set

public void set(E o)
Replaces the last element returned by next or previous with the specified element (optional operation). This process will automatically remove the old element from the data manager if it was not a ManagedObject.

Specified by:
set in interface ListIterator<E>
Parameters:
o - the element with which to replace the last element returned by next or previous.
Throws:
IllegalStateException - if the operation is called without next or previous being called

remove

public void remove()
Removes from the underlying collection the last element returned by the iterator. This can only be called once per call to next.

Specified by:
remove in interface Iterator<E>
Specified by:
remove in interface ListIterator<E>
Overrides:
remove in class ScalableList.ScalableIterator<E>
Throws:
IllegalStateException - if the method is not preceded by next() or prev()

doRemove

void doRemove()
Performs the remove and updates the references if necessary

Overrides:
doRemove in class ScalableList.ScalableIterator<E>

next

public E next()
Retrieves the next element.

Specified by:
next in interface Iterator<E>
Specified by:
next in interface ListIterator<E>
Overrides:
next in class ScalableList.ScalableIterator<E>
Returns:
the next element

add

public void add(E o)
Inserts the specified element into the list. The element is inserted immediately before the next element that would be returned by next, if any, and after the next element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Specified by:
add in interface ListIterator<E>
Parameters:
o - the element to insert.
Throws:
IndexOutOfBoundsException - if the index which the element is to be added is out of bounds

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved