saker.build Documentation TaskDoc JavaDoc Packages
public final class ConcurrentPrependAccumulator<Timplements Iterable<T>
Simplified container class that can be concurrently used to add elements to it.

This class can be used by multiple threads to add elements to it. The implementation does not use any synchronization when inserting or retrieving elements from it. Instances of this class can be used when multiple producers need to put their results to a common container.

Good use-case for this class is when lot of threads are doing computations, and are putting their result to a common container.

This class collects the elements in an prepending manner, meaning that iteration order is the reverse of the insertion order.

Iterators returned by this class are weakly consistent.

TThe element type.
Constructors
public
Creates a new instance without any elements.
public
ConcurrentPrependAccumulator(Iterable<extends T> elements)
Creates a new instance and adds the elements from the argument iterable to it.
public
Creates a new instance and adds the argument array of elements to it.
Methods
public void
add(T item)
Prepends an element to this accumulator.
public void
addAll(Iterable<extends T> elements)
Prepends all elements from the argument iterable to this accumulator.
public void
Clears this accumulator.
public PeekableIterable<T>
Clears this accumulator and returns an iterable for the cleared elements.
public Iterator<T>
Clears this accumulator and returns an iterator for the cleared elements.
public boolean
Checks if there are any elements in this accumulator.
public PeekableIterable<T>
Gets an iterable to the elements in this accumulator.
public Iterator<T>
Returns an iterator over elements of type T.
public T
Gets the first element in this accumulator.
public T
Removes the first element from this accumulator.
public String
Returns a string representation of the object.
Creates a new instance without any elements.
public ConcurrentPrependAccumulator(Iterable<extends T> elements) throws NullPointerException
Creates a new instance and adds the elements from the argument iterable to it.
elementsThe initial elements.
NullPointerExceptionIf the argument is null.
Creates a new instance and adds the argument array of elements to it.
elementsThe initial elements.
NullPointerExceptionIf the argument is null.
public void add(T item)
Prepends an element to this accumulator.
itemThe element.
public void addAll(Iterable<extends T> elements) throws NullPointerException
Prepends all elements from the argument iterable to this accumulator.
elementsThe iterable of elements.
NullPointerExceptionIf the argument is null.
public void clear()
Clears this accumulator.
Clears this accumulator and returns an iterable for the cleared elements.

The iterable will always iterate on the same elements, and modifications to this accumulator are not reflected on it.

The iterable for the cleared elements.
Clears this accumulator and returns an iterator for the cleared elements.
The iterator for the cleared elements.
public boolean isEmpty()
Checks if there are any elements in this accumulator.
true if the accumulator is empty.
Gets an iterable to the elements in this accumulator.

The returned iterable will always iterate over the same elements in the same order. Any modifications done on this will not be visible from the returned iterable.

An iterable view of this accumulator.
public Iterator<T> iterator()
Overridden from: Iterable
Returns an iterator over elements of type T.
an Iterator.
public T peek()
Gets the first element in this accumulator.

This method doesn't remove the element itself, but just returns it.

The first element, or null if it is null or the accumulator is empty.
public T take()
Removes the first element from this accumulator.
The removed element, or null if it is null or the accumulator is empty.
public String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.