Package com.azure.android.core.util
Class Option<T>
- java.lang.Object
-
- com.azure.android.core.util.Option<T>
-
- Type Parameters:
T
- The value type.
public final class Option<T> extends java.lang.Object
The Option type to describe tri-state. Every Option instance is in one of the three states: a state representing a non-null-value, null-value, or no-value.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> Option<T>
empty()
Returns anOption
with null-value.boolean
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this Option.T
getValue()
Gets the value in theOption
.int
hashCode()
Returns hash code of the value this Option is initialized with or -1 if in uninitialized state.boolean
isInitialized()
Returntrue
if this instance is initialized with a null-value or non-null-value, otherwisefalse
.static <T> Option<T>
of(T value)
Returns anOption
with the specified null-value or non-null-value.static <T> Option<T>
uninitialized()
Returns anOption
instance with no-value.
-
-
-
Method Detail
-
of
public static <T> Option<T> of(T value)
Returns anOption
with the specified null-value or non-null-value.- Type Parameters:
T
- The value type.- Parameters:
value
- the value.- Returns:
- an
Option
with the value present.
-
empty
public static <T> Option<T> empty()
Returns anOption
with null-value.Option.empty()
is a syntactic sugar forOption.of(null)
.- Type Parameters:
T
- The value type.- Returns:
- an
Option
with a null-value.
-
uninitialized
public static <T> Option<T> uninitialized()
Returns anOption
instance with no-value.- Type Parameters:
T
- Type of the non-existent value.- Returns:
- An Option type with no-value.
-
isInitialized
public boolean isInitialized()
Returntrue
if this instance is initialized with a null-value or non-null-value, otherwisefalse
.- Returns:
true
if a value has been initialized, otherwisefalse
-
equals
public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this Option. The other object is considered equal if:- it is also an
Option
and; - both instances are not initialized or;
- both instances are initialized and values are "equal to" each other via
equals()
.
- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- an object to be tested for equality- Returns:
- {code true} if the other object is "equal to" this object otherwise
false
- it is also an
-
hashCode
public int hashCode()
Returns hash code of the value this Option is initialized with or -1 if in uninitialized state.The value 0 will be returned when initialized with
null
.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- hash code of the value this Option is initialized with or -1 if in uninitialized state.
-
-