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.
public | Creates a new instance without any elements. |
public | ConcurrentAppendAccumulator( Creates a new instance and adds the elements from the argument iterable to it. |
public | ConcurrentAppendAccumulator( Creates a new instance and adds the argument array of elements to it. |
public void | add( Appends an element to this accumulator. |
public void | Appends all elements from the argument iterable to this accumulator. |
public boolean | addIfEmpty( Appends an element if and only if the accumulator is currently empty. |
public void | clear() Clears this accumulator. |
public Iterable< | Clears this accumulator and returns an iterable for the cleared elements. |
public Iterator< | Clears this accumulator and returns an iterator for the cleared elements. |
public T | first() Gets the current first element of this accumulator. |
public boolean | isEmpty() Checks if there are any elements in this accumulator. |
public Iterator< | iterator() Returns an iterator over elements of type T . |
public T | last() Gets the current last element of this accumulator. |
public String | toString() Returns a string representation of the object. |
null
.null
.null
.If this method succeeds, the accumulator will only contain the element that was just added.
true
if the accumulator was empty and the element was successfully added.The iterable will always iterate on the same elements, and modifications to this accumulator are not reflected on it.
null
if it is null
or the accumulator is empty.true
if the accumulator is empty.null
if it is null
or the accumulator is empty.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())