Class 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 Detail

      • SuccessWithValue

        public SuccessWithValue​(@Nonnull
                                ISuccessIndicator aSuccessIndicator)
        Constructor
        Parameters:
        aSuccessIndicator - The success indicator. May not be null.
      • SuccessWithValue

        public SuccessWithValue​(@Nonnull
                                ISuccessIndicator aSuccessIndicator,
                                @Nullable
                                DATATYPE aObj)
        Constructor
        Parameters:
        aSuccessIndicator - The success indicator. May not be null.
        aObj - The assigned value. May be null.
    • Method Detail

      • isSuccess

        public boolean isSuccess()
        Specified by:
        isSuccess in interface ISuccessIndicator
        Returns:
        true on success and false on 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 be null.
        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. Otherwise null is 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 be null.
        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. Otherwise null is returned.
        Returns:
        Either the stored value or null.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • 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 be null.
        aValue - The value to be used. May be null.
        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 be null.
        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 be null.
        Returns:
        Never null.