V - The type of the object which is referenced.public final class OneTimeAssignment<V> extends Object implements Assignment<V>
The class is thread-safe in the sense that it is not possible for concurrent threads to assign a value to it twice, though relevant cases for concurrent use are probably limited. The motivation is rather to enable fail-fast for erroneous API-usage involving assignments, e.g. builder implementations.
| Modifier and Type | Class and Description |
|---|---|
static class |
OneTimeAssignment.AlreadyAssigned |
ViewableAsOptional.Single<V>, ViewableAsOptional.TooManyElements| Modifier and Type | Method and Description |
|---|---|
static <V> OneTimeAssignment<V> |
defaultTo(Supplier<? extends V> defaultValue)
Create a new non-assigned instance with a default value.
|
static <V> OneTimeAssignment<V> |
defaultTo(V defaultValue)
Create a new non-assigned instance with a default value.
|
V |
get() |
boolean |
isSet()
Determine if this
OneTimeAssignment has been set, either by using set(Object)
or implicitly by a default value, triggered with a call to get(). |
static <V> OneTimeAssignment<V> |
newInstance()
Create a new non-assigned instance.
|
void |
set(V value)
Assigns a value to this reference.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaccept, chainableWith, from, fromtoOptionalpublic static final <V> OneTimeAssignment<V> defaultTo(V defaultValue)
defaultValue - The default value to use in case an assignment
through set(Object) is never performed.defaultTo(Supplier)public static final <V> OneTimeAssignment<V> defaultTo(Supplier<? extends V> defaultValue)
defaultValue - The supplier to acquire the default value to use in case an
assignment through set(Object) is never performed.public static final <V> OneTimeAssignment<V> newInstance()
public void set(V value)
set in interface Assignment<V>value - the value to set.OneTimeAssignment.AlreadyAssigned - if this reference is already assigned a value.public boolean isSet()
OneTimeAssignment has been set, either by using set(Object)
or implicitly by a default value, triggered with a call to get().
For sake of clarity, an invocation of this method does never implicitly assign any default value. An assignment
with no default value requires an invocation of set(Object) for this method to return true.
true if the assignment has a value, false if it has not been assigned yet.public V get()
get in interface Supplier<V>initialized with a default value,
the reference is assigned the default value and this is returned.Copyright © 2019 Digipost. All rights reserved.