Package com.helger.commons.state
Class SuccessWithValue<DATATYPE>
- java.lang.Object
-
- com.helger.commons.state.SuccessWithValue<DATATYPE>
-
- Type Parameters:
DATATYPE- The data type that is wrapped together with the success indicator
- All Implemented Interfaces:
ISuccessIndicator,IWrapper<DATATYPE>,Supplier<DATATYPE>
@Immutable public class SuccessWithValue<DATATYPE> extends Object implements ISuccessIndicator, IWrapper<DATATYPE>
Wraps a success indicator and an arbitrary value.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description SuccessWithValue(ISuccessIndicator aSuccessIndicator)ConstructorSuccessWithValue(ISuccessIndicator aSuccessIndicator, DATATYPE aObj)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <DATATYPE> SuccessWithValue<DATATYPE>create(ISuccessIndicator aSuccessIndicator, DATATYPE aValue)Create a new object with the given value.static <DATATYPE> SuccessWithValue<DATATYPE>createFailure(DATATYPE aValue)Create a new failure object with the given value.static <DATATYPE> SuccessWithValue<DATATYPE>createSuccess(DATATYPE aValue)Create a new success object with the given value.booleanequals(Object o)DATATYPEget()DATATYPEgetIfFailure(DATATYPE aSuccessValue)Get the store value if this is a failure.DATATYPEgetIfFailureOrNull()Get the store value if this is a failure.DATATYPEgetIfSuccess(DATATYPE aFailureValue)Get the store value if this is a success.DATATYPEgetIfSuccessOrNull()Get the store value if this is a success.inthashCode()booleanisSuccess()StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.state.ISuccessIndicator
and, isFailure, or
-
-
-
-
Constructor Detail
-
SuccessWithValue
public SuccessWithValue(@Nonnull ISuccessIndicator aSuccessIndicator)
Constructor- Parameters:
aSuccessIndicator- The success indicator. May not benull.
-
SuccessWithValue
public SuccessWithValue(@Nonnull ISuccessIndicator aSuccessIndicator, @Nullable DATATYPE aObj)
Constructor- Parameters:
aSuccessIndicator- The success indicator. May not benull.aObj- The assigned value. May benull.
-
-
Method Detail
-
isSuccess
public boolean isSuccess()
- Specified by:
isSuccessin interfaceISuccessIndicator- Returns:
trueon success andfalseon failure.
-
getIfSuccess
@Nullable public DATATYPE getIfSuccess(@Nullable DATATYPE aFailureValue)
Get the store value if this is a success. Otherwise the passed failure value is returned.- Parameters:
aFailureValue- The failure value to be used. May benull.- Returns:
- Either the stored value or the failure value. May be
null.
-
getIfSuccessOrNull
@Nullable public DATATYPE getIfSuccessOrNull()
Get the store value if this is a success. Otherwisenullis returned.- Returns:
- Either the stored value or
null.
-
getIfFailure
@Nullable public DATATYPE getIfFailure(@Nullable DATATYPE aSuccessValue)
Get the store value if this is a failure. Otherwise the passed success value is returned.- Parameters:
aSuccessValue- The failure value to be used. May benull.- Returns:
- Either the stored value or the failure value. May be
null.
-
getIfFailureOrNull
@Nullable public DATATYPE getIfFailureOrNull()
Get the store value if this is a failure. Otherwisenullis returned.- Returns:
- Either the stored value or
null.
-
create
@Nonnull public static <DATATYPE> SuccessWithValue<DATATYPE> create(@Nonnull ISuccessIndicator aSuccessIndicator, @Nullable DATATYPE aValue)
Create a new object with the given value.- Type Parameters:
DATATYPE- The data type that is wrapped together with the success indicator- Parameters:
aSuccessIndicator- The success indicator. May not benull.aValue- The value to be used. May benull.- Returns:
- Never
null.
-
createSuccess
@Nonnull public static <DATATYPE> SuccessWithValue<DATATYPE> createSuccess(@Nullable DATATYPE aValue)
Create a new success object with the given value.- Type Parameters:
DATATYPE- The data type that is wrapped together with the success indicator- Parameters:
aValue- The value to be used. May benull.- Returns:
- Never
null.
-
createFailure
@Nonnull public static <DATATYPE> SuccessWithValue<DATATYPE> createFailure(@Nullable DATATYPE aValue)
Create a new failure object with the given value.- Type Parameters:
DATATYPE- The data type that is wrapped together with the success indicator- Parameters:
aValue- The value to be used. May benull.- Returns:
- Never
null.
-
-