Interface ReferenceWrapper<T>
- Type Parameters:
T- type of reference
- All Known Implementing Classes:
ReferenceWrapper.AtomicReferenceWrapper,ReferenceWrapper.PrimitiveReferenceWrapper
public interface ReferenceWrapper<T>
Wrapper of a reference.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classReferenceWrapperimplementation based onAtomicReference.static final classReferenceWrapperimplementation based on primitive reference. -
Method Summary
Modifier and TypeMethodDescriptionaccumulateAndGet(T updateValue, @NonNull BinaryOperator<T> accumulatorFunction) Gets the value after what it gets updated using the specified function and update value.static <T> ReferenceWrapper<T>create()Creates new simple reference wrapper with initial value set tonull.static <T> ReferenceWrapper<T>create(T value) Creates new simple reference wrapper.static <T> ReferenceWrapper<T>Creates new atomic reference wrapper with initial value set tonull.static <T> ReferenceWrapper<T>createAtomic(T value) Creates new atomic reference wrapper.get()Gets the value.getAndAccumulate(T updateValue, @NonNull BinaryOperator<T> accumulatorFunction) Updates the current value using specified function and update value after what the new value is returned.Sets the value to the one given returning the previous one.getAndUpdate(@NonNull UnaryOperator<T> updateFunction) Updates the current value using the specified function after what the new value is returned.voidSets the value.updateAndGet(@NonNull UnaryOperator<T> updateFunction) Gets the value after what it gets updated using the specified function.
-
Method Details
-
create
Creates new simple reference wrapper.- Type Parameters:
T- type of reference- Parameters:
value- initial reference of int wrapper- Returns:
- created reference wrapper
-
create
Creates new simple reference wrapper with initial value set tonull.- Type Parameters:
T- type of reference- Returns:
- created reference wrapper
-
createAtomic
Creates new atomic reference wrapper.- Type Parameters:
T- type of reference- Parameters:
value- initial value of reference wrapper- Returns:
- created reference wrapper
-
createAtomic
Creates new atomic reference wrapper with initial value set tonull.- Type Parameters:
T- type of reference- Returns:
- created reference wrapper
-
get
T get()Gets the value.- Returns:
- value
-
set
Sets the value.- Parameters:
newValue- value to be set
-
getAndSet
Sets the value to the one given returning the previous one.- Parameters:
newValue- value to be set- Returns:
- previous value
-
getAndUpdate
Updates the current value using the specified function after what the new value is returned.- Parameters:
updateFunction- function to be used for updating the value- Returns:
- value before update
-
updateAndGet
Gets the value after what it gets updated using the specified function.- Parameters:
updateFunction- function to be used for updating the value- Returns:
- value after update
-
getAndAccumulate
Updates the current value using specified function and update value after what the new value is returned.- Parameters:
updateValue- update value (will be passed as the second function parameter)accumulatorFunction- function to be used for updating the value- Returns:
- value before update
-
accumulateAndGet
Gets the value after what it gets updated using the specified function and update value.- Parameters:
updateValue- update value (will be passed as the second function parameter)accumulatorFunction- function to be used for updating the value- Returns:
- value after update
-