Class Variant<T,U>
- java.lang.Object
-
- org.opendaylight.yangtools.concepts.Variant<T,U>
-
- Type Parameters:
T
- First alternative typeU
- Second alternative type
- All Implemented Interfaces:
Immutable
,MutationBehaviour<Immutable>
- Direct Known Subclasses:
CheckedValue
@Beta @NonNullByDefault public class Variant<T,U> extends Object implements Immutable
Utility holder of a two-variant value. The class design treats both variants as equal.- Author:
- Robert Varga
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MoreObjects.ToStringHelper
addToString(MoreObjects.ToStringHelper helper)
boolean
equals(@Nullable Object obj)
protected T
first()
T
getFirst()
U
getSecond()
int
hashCode()
boolean
isFirst()
boolean
isSecond()
static <T,U>
Variant<T,U>ofFirst(T value)
Create a new instance containing specified value.static <T,U>
Variant<T,U>ofSecond(U value)
Create a new instance containing specified value.protected U
second()
String
toString()
Optional<T>
tryFirst()
Optional<U>
trySecond()
-
-
-
Method Detail
-
first
protected final T first()
-
second
protected final U second()
-
ofFirst
public static <T,U> Variant<T,U> ofFirst(T value)
Create a new instance containing specified value.- Type Parameters:
T
- First alternative typeU
- Second alternative type- Parameters:
value
- Value- Returns:
- A new instance
- Throws:
NullPointerException
- ifvalue
is null
-
ofSecond
public static <T,U> Variant<T,U> ofSecond(U value)
Create a new instance containing specified value.- Type Parameters:
T
- First alternative typeU
- Second alternative type- Parameters:
value
- Value- Returns:
- A new instance
- Throws:
NullPointerException
- ifvalue
is null
-
isFirst
public final boolean isFirst()
-
getFirst
public final T getFirst()
-
isSecond
public final boolean isSecond()
-
getSecond
public final U getSecond()
-
addToString
protected MoreObjects.ToStringHelper addToString(MoreObjects.ToStringHelper helper)
-
-