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

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

static class ScalableList.ScalableIterator<E>
extends Object
implements Serializable, Iterator<E>

This class represents an iterator of the elements of the ScalableList.


Field Summary
protected  ManagedReference<ScalableList.ListNode<E>> currentNode
          The current ListNode of the iterative process
protected  int cursor
          The iteration location of the list
protected  long listNodeReferenceValue
          The value for the current ListNode to determine if any changes have taken place since the last time it was accessed
(package private)  ManagedReference<ScalableList<E>> owner
          A reference to the ScalableList which this iterator is referring to
protected  boolean wasNextCalled
          Flag which only lets one removal happen per call to next()
 
Constructor Summary
ScalableList.ScalableIterator(ScalableList<E> list)
          Constructor used to create a ScalableListIterator for the underlying elements in the ScalableList.
ScalableList.ScalableIterator(ScalableList<E> list, ScalableList.ListNode<E> startingNode)
           
 
Method Summary
(package private)  void checkDataIntegrity()
          Checks whether the data integrity value has changed, and throws a ConcurrentModificationException if so.
(package private)  void doRemove()
          Performs the remove and updates the references if necessary
(package private)  int getAbsoluteIndex(ScalableList.Node<E> node, int size)
          Walks up the tree and collects the sizes to produce an absolute index.
(package private)  int getCurrentIndex()
          Retrieves the index of the current element by walking up the tree to the root and aggregating the counts of each ListNode and TreeNode.
protected  int getCursorBasedOnPreviousAction(boolean next)
          Retrieve the index of interest, based on our previous direction and intended direction
 boolean hasNext()
          Returns whether there is a next element to iterate over.
(package private) static
<E> boolean
isNextWithinRange(int offset, ScalableList.ListNode<E> currentListNode)
          Performs a check to see that the index for next() is still within range of the sub list.
 E next()
          Retrieves the next element.
 void remove()
          Removes from the underlying collection the last element returned by the iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

owner

final ManagedReference<ScalableList<E>> owner
A reference to the ScalableList which this iterator is referring to


currentNode

protected ManagedReference<ScalableList.ListNode<E>> currentNode
The current ListNode of the iterative process


cursor

protected int cursor
The iteration location of the list


wasNextCalled

protected boolean wasNextCalled
Flag which only lets one removal happen per call to next()


listNodeReferenceValue

protected long listNodeReferenceValue
The value for the current ListNode to determine if any changes have taken place since the last time it was accessed

Constructor Detail

ScalableList.ScalableIterator

ScalableList.ScalableIterator(ScalableList<E> list)
Constructor used to create a ScalableListIterator for the underlying elements in the ScalableList.

Parameters:
list - the ScalableList over which to iterate

ScalableList.ScalableIterator

ScalableList.ScalableIterator(ScalableList<E> list,
                              ScalableList.ListNode<E> startingNode)
Method Detail

isNextWithinRange

static <E> boolean isNextWithinRange(int offset,
                                     ScalableList.ListNode<E> currentListNode)
Performs a check to see that the index for next() 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

getCurrentIndex

int getCurrentIndex()
Retrieves the index of the current element by walking up the tree to the root and aggregating the counts of each ListNode and TreeNode. This operation is slightly expensive because of the required percolation up the tree.

Returns:
the absolute index of the current element being examined

getAbsoluteIndex

int getAbsoluteIndex(ScalableList.Node<E> node,
                     int size)
Walks up the tree and collects the sizes to produce an absolute index.

Returns:
the absolute index of the given node

next

public E next()
Retrieves the next element.

Specified by:
next in interface Iterator<E>
Returns:
the next element
Throws:
ConcurrentModificationException - if the ListNode that the iterator is pointing to has been modified to (addition or removal) by someone else
NoSuchElementException - if there is no next element

getCursorBasedOnPreviousAction

protected int getCursorBasedOnPreviousAction(boolean next)
Retrieve the index of interest, based on our previous direction and intended direction

Parameters:
next - whether we intend on travelling in the next direction; true if so, and false otherwise
Returns:
the index corresponding to the cursor

checkDataIntegrity

void checkDataIntegrity()
Checks whether the data integrity value has changed, and throws a ConcurrentModificationException if so.

Throws:
ConcurrentModificationException - if the data integrity value has changed or if it cannot be verified

hasNext

public boolean hasNext()
Returns whether there is a next element to iterate over.

Specified by:
hasNext in interface Iterator<E>
Returns:
true if there is a next element, or false otherwise
Throws:
ConcurrentModificationException - if the ListNode has been modified or removed

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>

doRemove

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


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