Package discord4j.common.jackson
Class Possible<T>
- java.lang.Object
-
- discord4j.common.jackson.Possible<T>
-
- Type Parameters:
T
- JSON Property Type
public class Possible<T> extends Object
Represents a JSON property that may be absent, but never null if it's present.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> Possible<T>
absent()
Returns aPossible
with an absent value.boolean
equals(Object o)
T
get()
Returns an instance ofT
if this instance ofPossible
represents a non-absent value.int
hashCode()
boolean
isAbsent()
Checks whether the instance of thisPossible
represents an absent value.static <T> Possible<T>
of(T value)
Returns aPossible
with a non-null, present value.String
toString()
-
-
-
Method Detail
-
of
public static <T> Possible<T> of(T value)
Returns aPossible
with a non-null, present value.- Type Parameters:
T
- JSON Property Type- Parameters:
value
- A non-null value for a newPossible
to represent.- Returns:
- An instance of
Possible
whose value is always present and never null. - Throws:
NullPointerException
- Ifvalue
is null.
-
absent
public static <T> Possible<T> absent()
Returns aPossible
with an absent value.- Type Parameters:
T
- JSON Property Type- Returns:
- An instance of
Possible
whose value is absent, but not necessarily null.
-
get
public T get()
Returns an instance ofT
if this instance ofPossible
represents a non-absent value.- Returns:
- An instance of
T
, if it is present. Guaranteed to never be null. - Throws:
NoSuchElementException
- If the value isabsent
.
-
isAbsent
public boolean isAbsent()
Checks whether the instance of thisPossible
represents an absent value.- Returns:
- True is the value is absent, false otherwise.
-
-