T
- the contained value typepublic final class SingleOption<T>
extends java.lang.Object
The caller may add a single value or exception to this container. Any subsequent add attempt results in IllegalStateException.
The caller may retrieve the value or exception from this container, which is then removed from the container; the caller may add a new value or exception. If the caller attempts to remove a value or exception after a value, it will result in IllegalStateException.
The class is not thread safe.
Modifier and Type | Field and Description |
---|---|
protected java.lang.Throwable |
error
The stored exception.
|
protected boolean |
hasContent
Indicator for having a value or error.
|
protected T |
value
The contained value.
|
Constructor and Description |
---|
SingleOption() |
Modifier and Type | Method and Description |
---|---|
void |
add(T value)
Add a new value to the container.
|
void |
addError(java.lang.Throwable ex)
Add a new error to the container.
|
void |
addOption(rx.Notification<? extends T> o)
Add a new optional value to the container.
|
protected void |
ensureEmpty()
Throws an IllegalStateException if the container is full.
|
protected void |
ensureFull()
Throws an IllegalStateException if the container is empty.
|
boolean |
hasError() |
boolean |
isEmpty() |
rx.Notification<T> |
option() |
T |
take()
Takes the current value or throws a RuntimeException
if there is an error instead.
|
java.lang.Throwable |
takeError()
Takes just the exception from this container.
|
protected boolean hasContent
protected T value
protected java.lang.Throwable error
public void add(T value)
value
- the value to addpublic void addError(java.lang.Throwable ex)
ex
- the exception to addpublic boolean isEmpty()
protected void ensureEmpty()
protected void ensureFull()
public T take()
The container must be full, and gets empty after the call.
public java.lang.Throwable takeError()
public boolean hasError()
public rx.Notification<T> option()
public void addOption(rx.Notification<? extends T> o)
o
- the option to add