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.
public | Creates a new instance without any elements. |
public | ConcurrentPrependAccumulator( Creates a new instance and adds the elements from the argument iterable to it. |
public | ConcurrentPrependAccumulator( Creates a new instance and adds the argument array of elements to it. |
public void | add( Prepends an element to this accumulator. |
public void | Prepends all elements from the argument iterable to this accumulator. |
public boolean | addIfEmpty( Prepends an element if and only if the accumulator is currently empty. |
public void | clear() Clears this accumulator. |
public PeekableIterable< | 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 boolean | isEmpty() Checks if there are any elements in this accumulator. |
public PeekableIterable< | iterable() Gets an iterable to the elements in this accumulator. |
public Iterator< | iterator() Returns an iterator over elements of type T . |
public T | peek() Gets the first element in this accumulator. |
public T | take() Removes the first element from 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.
true
if the accumulator is empty.
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.
This method doesn't remove the element itself, but just returns it.
null
if it is null
or 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())