public class Optional<T>
extends java.lang.Object
| Constructor and Description |
|---|
Optional()
The value defaults to unset.
|
Optional(Optional<T> opt)
Sets the value to a shallow copy of the given optional.
|
Optional(T v)
Sets the value to the given argument.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Unsets this value.
|
T |
get()
Obtains the current value.
|
boolean |
isSet()
Determines whether the value is set.
|
static BooleanOptional |
O(boolean v)
Helper function for creating BooleanOptional instances.
|
static ByteOptional |
O(byte v)
Helper function for creating ByteOptional instances.
|
static DoubleOptional |
O(double v)
Helper function for creating DoubleOptional instances.
|
static FloatOptional |
O(float v)
Helper function for creating FloatOptional instances.
|
static IntOptional |
O(int v)
Helper function for creating IntOptional instances.
|
static LongOptional |
O(long v)
Helper function for creating LongOptional instances.
|
static ShortOptional |
O(short v)
Helper function for creating ShortOptional instances.
|
static <T> Optional<T> |
O(T v)
Helper function for creating Optional instances.
|
void |
set(Optional<T> opt)
If the given argument is set, this optional is set to a shallow copy of the argument,
otherwise this optional is unset.
|
void |
set(T v)
Sets the value to the given argument.
|
public Optional()
public Optional(T v)
v - The initial value.public T get()
java.lang.IllegalStateException - If the value is not set.public void set(T v)
v - The new value.public void set(Optional<T> opt)
opt - The source value.public boolean isSet()
public void clear()
public static <T> Optional<T> O(T v)
T - The type of the Optional.v - The initial value of the Optional.public static BooleanOptional O(boolean v)
v - The initial value of the Optional.public static ByteOptional O(byte v)
v - The initial value of the Optional.public static ShortOptional O(short v)
v - The initial value of the Optional.public static IntOptional O(int v)
v - The initial value of the Optional.public static LongOptional O(long v)
v - The initial value of the Optional.public static FloatOptional O(float v)
v - The initial value of the Optional.public static DoubleOptional O(double v)
v - The initial value of the Optional.