org.eclipse.gemini.blueprint.service.importer.support.internal.collection
Class DynamicCollection<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by org.eclipse.gemini.blueprint.service.importer.support.internal.collection.DynamicCollection<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>
Direct Known Subclasses:
DynamicList, DynamicSet

public class DynamicCollection<E>
extends AbstractCollection<E>

Collection which can be increased or reduced at runtime while iterating. Iterators returned by this implementation are consistent - it is guaranteed that DynamicCollection.DynamicIterator.next() will obey the result of the previously called DynamicCollection.DynamicIterator.hasNext() even though the collection content has been modified. This collection is thread-safe with the condition that there is at most one writing thread at a point in time. There are no restrains on the number of readers.

Author:
Costin Leau

Nested Class Summary
protected  class DynamicCollection.DynamicIterator
          Dynamic consistent iterator.
 
Field Summary
protected  Map<DynamicCollection.DynamicIterator,Object> iterators
          should have been a list but there is no 'WeakReference'-based implementation in the JDK
protected  Object iteratorsLock
          If it interacts with the storage, the *storage* lock needs to be acquired first
protected  List<E> storage
          this list is not-synchronized by default
 
Constructor Summary
DynamicCollection()
           
DynamicCollection(Collection<? extends E> c)
           
DynamicCollection(int size)
           
 
Method Summary
 boolean add(E o)
           
protected  void add(int index, E o)
           
 boolean addAll(Collection<? extends E> c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
protected  int indexOf(Object o)
          Hook used by wrapping collections to determine the position of the object being removed while iterating.
 boolean isEmpty()
           
 Iterator<E> iterator()
           
protected  E remove(int index)
           
 boolean remove(Object o)
           
 int size()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 String toString()
           
 
Methods inherited from class java.util.AbstractCollection
removeAll, retainAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Field Detail

iteratorsLock

protected final Object iteratorsLock
If it interacts with the storage, the *storage* lock needs to be acquired first


storage

protected final List<E> storage
this list is not-synchronized by default


iterators

protected final Map<DynamicCollection.DynamicIterator,Object> iterators
should have been a list but there is no 'WeakReference'-based implementation in the JDK

Constructor Detail

DynamicCollection

public DynamicCollection()

DynamicCollection

public DynamicCollection(int size)

DynamicCollection

public DynamicCollection(Collection<? extends E> c)
Method Detail

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in class AbstractCollection<E>

clear

public void clear()
Specified by:
clear in interface Collection<E>
Overrides:
clear in class AbstractCollection<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in class AbstractCollection<E>

add

public boolean add(E o)
Specified by:
add in interface Collection<E>
Overrides:
add in class AbstractCollection<E>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Overrides:
addAll in class AbstractCollection<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Overrides:
contains in class AbstractCollection<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>
Overrides:
containsAll in class AbstractCollection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Overrides:
isEmpty in class AbstractCollection<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Overrides:
remove in class AbstractCollection<E>

remove

protected E remove(int index)

add

protected void add(int index,
                   E o)

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<E>
Overrides:
toArray in class AbstractCollection<E>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<E>
Overrides:
toArray in class AbstractCollection<E>

toString

public String toString()
Overrides:
toString in class AbstractCollection<E>

indexOf

protected int indexOf(Object o)
Hook used by wrapping collections to determine the position of the object being removed while iterating.

Parameters:
o -
Returns:


Copyright © 2006-2012. All Rights Reserved.