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.ObjectThe 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 anOptionwith null-value.booleanequals(java.lang.Object obj)Indicates whether some other object is "equal to" this Option.TgetValue()Gets the value in theOption.inthashCode()Returns hash code of the value this Option is initialized with or -1 if in uninitialized state.booleanisInitialized()Returntrueif this instance is initialized with a null-value or non-null-value, otherwisefalse.static <T> Option<T>of(T value)Returns anOptionwith the specified null-value or non-null-value.static <T> Option<T>uninitialized()Returns anOptioninstance with no-value.
-
-
-
Method Detail
-
of
public static <T> Option<T> of(T value)
Returns anOptionwith the specified null-value or non-null-value.- Type Parameters:
T- The value type.- Parameters:
value- the value.- Returns:
- an
Optionwith the value present.
-
empty
public static <T> Option<T> empty()
Returns anOptionwith null-value.Option.empty()is a syntactic sugar forOption.of(null).- Type Parameters:
T- The value type.- Returns:
- an
Optionwith a null-value.
-
uninitialized
public static <T> Option<T> uninitialized()
Returns anOptioninstance with no-value.- Type Parameters:
T- Type of the non-existent value.- Returns:
- An Option type with no-value.
-
isInitialized
public boolean isInitialized()
Returntrueif this instance is initialized with a null-value or non-null-value, otherwisefalse.- Returns:
trueif 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
Optionand; - both instances are not initialized or;
- both instances are initialized and values are "equal to" each other via
equals().
- Overrides:
equalsin 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:
hashCodein classjava.lang.Object- Returns:
- hash code of the value this Option is initialized with or -1 if in uninitialized state.
-
-