Class ChangeWithValue<DATATYPE>

java.lang.Object
com.helger.commons.state.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 Details

    • 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 Details

    • isChanged

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

      @Nullable public DATATYPE get()
      Specified by:
      get in interface IWrapper<DATATYPE>
      Specified by:
      get in interface Supplier<DATATYPE>
      Returns:
      The currently wrapped object. May be null.
    • 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.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString 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.