Package one.microstream.collections
Class LockedAdder<E>
java.lang.Object
one.microstream.collections.LockedAdder<E>
- All Implemented Interfaces:
Consumer<E>
,CapacityCarrying
,CapacityExtendable
,ExtendedCollection<E>
,OptimizableCollection
,Sized
,XAddingCollection<E>
,Synchronized
,ThreadSafe
public final class LockedAdder<E> extends Object implements XAddingCollection<E>, Synchronized
-
Nested Class Summary
Nested classes/interfaces inherited from interface one.microstream.collections.types.XAddingCollection
XAddingCollection.Creator<E>
-
Constructor Summary
Constructors Constructor Description LockedAdder(XAddingCollection<E> collection)
LockedAdder(XAddingCollection<E> collection, Object lock)
-
Method Summary
Modifier and Type Method Description void
accept(E e)
boolean
add(E e)
Adds the passed element.LockedAdder<E>
addAll(E... elements)
LockedAdder<E>
addAll(E[] elements, int offset, int length)
LockedAdder<E>
addAll(XGettingCollection<? extends E> elements)
long
currentCapacity()
Returns the current amount of elements this instance can hold before a storage rebuild becomes necessary.LockedAdder<E>
ensureCapacity(long minimalCapacity)
LockedAdder<E>
ensureFreeCapacity(long minimalFreeCapacity)
Ensures that the next minimalFreeCapacity elements can be actually added in a fast way, meaning for example no internal storage rebuild will be necessary.boolean
hasVolatileElements()
Tells if this collection contains volatile elements.
An element is volatile, if it can become no longer reachable by the collection without being removed from the collection.boolean
isEmpty()
boolean
isFull()
long
maximumCapacity()
Returns the maximum amount of elements this carrier instance can contain.
The actual value may be depend on the configuration of the concrete instance or may depend only on the implementation of the carrier (meaning it is constant for all instances of the implementation, e.g.boolean
nullAdd()
boolean
nullAllowed()
Defines if null-elements are allowed inside the collection or not.long
optimize()
Optimizes the internal storage of this collection and returns the storage size of the collection after the process is complete.long
remainingCapacity()
long
size()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface one.microstream.collections.interfaces.CapacityExtendable
currentFreeCapacity
-
Constructor Details
-
Method Details
-
nullAdd
public final boolean nullAdd()- Specified by:
nullAdd
in interfaceXAddingCollection<E>
-
add
Description copied from interface:XAddingCollection
Adds the passed element.- Specified by:
add
in interfaceXAddingCollection<E>
- Parameters:
e
- to add- Returns:
true
if element was added;false
if not
-
addAll
- Specified by:
addAll
in interfaceXAddingCollection<E>
-
addAll
- Specified by:
addAll
in interfaceXAddingCollection<E>
-
addAll
- Specified by:
addAll
in interfaceXAddingCollection<E>
-
accept
-
ensureFreeCapacity
Description copied from interface:CapacityExtendable
Ensures that the next minimalFreeCapacity elements can be actually added in a fast way, meaning for example no internal storage rebuild will be necessary.- Specified by:
ensureFreeCapacity
in interfaceCapacityExtendable
- Parameters:
minimalFreeCapacity
- the capacity to ensure- Returns:
- this
-
ensureCapacity
- Specified by:
ensureCapacity
in interfaceCapacityExtendable
-
currentCapacity
public final long currentCapacity()Description copied from interface:CapacityExtendable
Returns the current amount of elements this instance can hold before a storage rebuild becomes necessary.For carrier implementations that don't have a concept of storage rebuilding (like linked list for example) this method returns the same value as
CapacityCarrying.maximumCapacity()
.- Specified by:
currentCapacity
in interfaceCapacityExtendable
- Returns:
- the current capacity of this instance before a rebuild is required.
-
maximumCapacity
public final long maximumCapacity()Description copied from interface:CapacityCarrying
Returns the maximum amount of elements this carrier instance can contain.
The actual value may be depend on the configuration of the concrete instance or may depend only on the implementation of the carrier (meaning it is constant for all instances of the implementation, e.g.Integer.MAX_VALUE
)- Specified by:
maximumCapacity
in interfaceCapacityCarrying
- Returns:
- the maximum amount of elements this carrier instance can contain.
-
isFull
public final boolean isFull()- Specified by:
isFull
in interfaceCapacityCarrying
- Returns:
- true if the current capacity cannot be increased any more.
-
remainingCapacity
public final long remainingCapacity()- Specified by:
remainingCapacity
in interfaceCapacityCarrying
- Returns:
- the amount of elements this carrier instance can collect before reaching its maximimum capacity.
-
optimize
public final long optimize()Description copied from interface:OptimizableCollection
Optimizes the internal storage of this collection and returns the storage size of the collection after the process is complete.- Specified by:
optimize
in interfaceOptimizableCollection
- Returns:
- the storage size of the collection after the optimzation.
-
hasVolatileElements
public final boolean hasVolatileElements()Description copied from interface:ExtendedCollection
Tells if this collection contains volatile elements.
An element is volatile, if it can become no longer reachable by the collection without being removed from the collection. Examples areWeakReference
ofSoftReference
or implementations of collection entries that remove the element contained in an entry by some means outside the collection.
Note thatWeakReference
instances that are added to a a simple (non-volatile) implementation of a collection do not make the collection volatile, as the elements themselves (the reference instances) are still strongly referenced.- Specified by:
hasVolatileElements
in interfaceExtendedCollection<E>
- Returns:
true
if the collection contains volatile elements.
-
nullAllowed
public final boolean nullAllowed()Description copied from interface:ExtendedCollection
Defines if null-elements are allowed inside the collection or not.- Specified by:
nullAllowed
in interfaceExtendedCollection<E>
- Returns:
true
if null is allowed inside the collection;false
if not
-
isEmpty
- Specified by:
isEmpty
in interfaceSized
- Throws:
UnsupportedOperationException
-
size
- Specified by:
size
in interfaceSized
- Throws:
UnsupportedOperationException
-