Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.gemini.blueprint.service.importer.support.internal.collection
Class DynamicCollection.DynamicIterator

    java.lang.Object
      org.eclipse.gemini.blueprint.service.importer.support.internal.collection.DynamicCollection.DynamicIterator

All Implemented Interfaces:
  Iterator<E>

Enclosing class:
  DynamicCollection<E>

    protected class DynamicCollection.DynamicIterator

extends Object
implements Iterator<E>

Dynamic consistent iterator. This iterator is not thread-safe with respect to iteration (it should not be shared against multiple threads) but it is thread safe with respect to the backing storage which might be modified during the iterator life cycle.

Author:
  Costin Leau

Field Summary
`protected int` | `cursor` Cursor pointing to the element that has to be returned by `next()` method.
`protected Boolean` | `hasNext` Iterator variable - not thread-safe/synchronized since only one thread should use the iterator.
`protected Object` | `lock` Lock protecting the cursor and tailGhost which might be affected by the backing collection shrinking.
`protected boolean` | `removalAllowed` Iterator variable - not thread-safe/synchronized since only one thread should use the iterator.
`protected E` | `tailGhost` Temporary object holder.

Constructor Summary
`protected` | `DynamicCollection.DynamicIterator()`

Method Summary
`boolean` | `hasNext()`
`E` | `next()`
`protected int` | `removalIndex(int cursor)`
`void` | `remove()`
`protected boolean` | `unsafeHasNext()` Updates the hasNext field.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### cursor

    protected volatile int cursor

  Cursor pointing to the element that has to be returned by `next()` method. This element needs to be synchronized.

### tailGhost

    protected volatile E tailGhost

  Temporary object holder. Used in case the last element in the collection becomes empty after an iterator #hasNext() method was called but before #next() is invoked since otherwise the iterator needs to return an element but it cannot. Subclasses (such as lists) should implement their own strategy when it comes to assign a value to it to accommodate the collection semantics (ordered vs indexed). This particular field represents the tail of the collection, since no order or indexing is enforced and the iteration can only go forward. The field is assigned when an object is removed and resetted by calls to hasNext() or next(). Thread-safety note: Since this object is affected by the storage shrinking it needs to be synchronized.

### lock

    protected final Object lock

  Lock protecting the cursor and tailGhost which might be affected by the backing collection shrinking.

### hasNext

    protected Boolean hasNext

  Iterator variable - not thread-safe/synchronized since only one thread should use the iterator.

### removalAllowed

    protected boolean removalAllowed

  Iterator variable - not thread-safe/synchronized since only one thread should use the iterator.

Constructor Detail

### DynamicCollection.DynamicIterator

    protected DynamicCollection.DynamicIterator()

Method Detail

### hasNext

    public boolean hasNext()

  Specified by:
    `hasNext` in interface `Iterator<E>`

### unsafeHasNext

    protected boolean unsafeHasNext()

  Updates the hasNext field. Internal unprotected method to avoid nested synchronization blocks. To execute this code, one needs the storage, iteratorsLock and iterator lock.

  Returns:

### next

    public E next()

  Specified by:
    `next` in interface `Iterator<E>`

### remove

    public void remove()

  Specified by:
    `remove` in interface `Iterator<E>`

### removalIndex

    protected int removalIndex(int cursor)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006-2012. All Rights Reserved.