saker.util Documentation TaskDoc JavaDoc Packages
package saker.util
public final class ConcurrentAppendAccumulator<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 appending manner, meaning that iteration order is the same as insertion order.

Iterators returned by this class are weakly consistent.

If the user of this class doesn't care about the iteration order, consider using ConcurrentPrependAccumulator, as that might provide a slightly better concurrent performance.

TThe element type.
Constructors
public
Creates a new instance without any elements.
public
ConcurrentAppendAccumulator(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)
Appends an element to this accumulator.
public void
addAll(Iterable<extends T> elements)
Appends all elements from the argument iterable to this accumulator.
public boolean
addIfEmpty(T item)
Appends an element if and only if the accumulator is currently empty.
public void
Clears this accumulator.
public Iterable<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 T
Gets the current first element of this accumulator.
public boolean
Checks if there are any elements in this accumulator.
public Iterator<T>
Returns an iterator over elements of type T.
public T
Gets the current last element of this accumulator.
public String
Returns a string representation of the object.
Creates a new instance without any elements.
public ConcurrentAppendAccumulator(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)
Appends an element to this accumulator.
itemThe element.
public void addAll(Iterable<extends T> elements) throws NullPointerException
Appends all elements from the argument iterable to this accumulator.
elementsThe iterable of elements.
NullPointerExceptionIf the argument is null.
public boolean addIfEmpty(T item)
Appends an element if and only if the accumulator is currently empty.

If this method succeeds, the accumulator will only contain the element that was just added.

itemThe element to add.
true if the accumulator was empty and the element was successfully added.
saker.util 0.8.3
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 T first()
Gets the current first element of this accumulator.
The first element, or null if it is null or the accumulator is empty.
public boolean isEmpty()
Checks if there are any elements in this accumulator.
true if the accumulator is empty.
public Iterator<T> iterator()
Overridden from: Iterable
Returns an iterator over elements of type T.
an Iterator.
public T last()
Gets the current last element of this accumulator.
The last 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.