Class ChangeWithValue<DATATYPE>

  • Type Parameters:
    DATATYPE - The data type that is wrapped together with the change indicator
    All Implemented Interfaces:
    IChangeIndicator, IWrapper<DATATYPE>, Supplier<DATATYPE>

    @Immutable
    public class ChangeWithValue<DATATYPE>
    extends Object
    implements IChangeIndicator, IWrapper<DATATYPE>
    Wraps a change indicator and an arbitrary value.
    Author:
    Philip Helger
    • Constructor Detail

      • ChangeWithValue

        public ChangeWithValue​(@Nonnull
                               IChangeIndicator aChangeIndicator,
                               @Nullable
                               DATATYPE aObj)
        Constructor
        Parameters:
        aChangeIndicator - The change indicator. May not be null.
        aObj - The assigned value. May be null.
    • Method Detail

      • isChanged

        public boolean isChanged()
        Specified by:
        isChanged in interface IChangeIndicator
        Returns:
        true if changed and false if unchanged.
      • getIfChanged

        @Nullable
        public DATATYPE getIfChanged​(@Nullable
                                     DATATYPE aUnchangedValue)
        Get the store value if this is a change. Otherwise the passed unchanged value is returned.
        Parameters:
        aUnchangedValue - The unchanged value to be used. May be null.
        Returns:
        Either the stored value or the unchanged value. May be null.
      • getIfChangedOrNull

        @Nullable
        public DATATYPE getIfChangedOrNull()
        Get the store value if this is a changed. Otherwise null is returned.
        Returns:
        Either the stored value or null.
      • getIfUnchanged

        @Nullable
        public DATATYPE getIfUnchanged​(@Nullable
                                       DATATYPE aChangedValue)
        Get the store value if this is unchanged. Otherwise the passed changed value is returned.
        Parameters:
        aChangedValue - The changed value to be used. May be null.
        Returns:
        Either the stored value or the changed value. May be null.
      • getIfUnchangedOrNull

        @Nullable
        public DATATYPE getIfUnchangedOrNull()
        Get the store value if this is unchanged. Otherwise null is returned.
        Returns:
        Either the stored value or null.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • createChanged

        @Nonnull
        public static <DATATYPE> ChangeWithValue<DATATYPE> createChanged​(@Nullable
                                                                         DATATYPE aValue)
        Create a new changed object with the given value.
        Type Parameters:
        DATATYPE - The data type that is wrapped together with the change indicator
        Parameters:
        aValue - The value to be used. May be null.
        Returns:
        Never null.
      • createUnchanged

        @Nonnull
        public static <DATATYPE> ChangeWithValue<DATATYPE> createUnchanged​(@Nullable
                                                                           DATATYPE aValue)
        Create a new unchanged object with the given value.
        Type Parameters:
        DATATYPE - The data type that is wrapped together with the change indicator
        Parameters:
        aValue - The value to be used. May be null.
        Returns:
        Never null.