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
ConstructorsConstructorDescriptionSuccessWithValue(ISuccessIndicator aSuccessIndicator) ConstructorSuccessWithValue(ISuccessIndicator aSuccessIndicator, DATATYPE aObj) Constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.booleanget()getIfFailure(DATATYPE aSuccessValue) Get the store value if this is a failure.Get the store value if this is a failure.getIfSuccess(DATATYPE aFailureValue) Get the store value if this is a success.Get the store value if this is a success.inthashCode()booleantoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.commons.state.ISuccessIndicator
and, isFailure, or
-
Constructor Details
-
SuccessWithValue
Constructor- Parameters:
aSuccessIndicator- The success indicator. May not benull.
-
SuccessWithValue
Constructor- Parameters:
aSuccessIndicator- The success indicator. May not benull.aObj- The assigned value. May benull.
-
-
Method Details
-
isSuccess
public boolean isSuccess()- Specified by:
isSuccessin interfaceISuccessIndicator- Returns:
trueon success andfalseon failure.
-
get
-
getIfSuccess
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
Get the store value if this is a success. Otherwisenullis returned.- Returns:
- Either the stored value or
null.
-
getIfFailure
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
Get the store value if this is a failure. Otherwisenullis returned.- Returns:
- Either the stored value or
null.
-
equals
-
hashCode
public int hashCode() -
toString
-
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.
-