Package com.helger.base.state
Class ChangeWithValue<DATATYPE>
java.lang.Object
com.helger.base.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 Summary
ConstructorsConstructorDescriptionChangeWithValue(@NonNull IChangeIndicator aChangeIndicator, @Nullable DATATYPE aObj) Constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic <DATATYPE> @NonNull ChangeWithValue<DATATYPE> createChanged(@Nullable DATATYPE aValue) Create a new changed object with the given value.static <DATATYPE> @NonNull ChangeWithValue<DATATYPE> createUnchanged(@Nullable DATATYPE aValue) Create a new unchanged object with the given value.boolean@Nullable DATATYPEget()@Nullable DATATYPEgetIfChanged(@Nullable DATATYPE aUnchangedValue) Get the store value if this is a change.@Nullable DATATYPEGet the store value if this is a changed.@Nullable DATATYPEgetIfUnchanged(@Nullable DATATYPE aChangedValue) Get the store value if this is unchanged.@Nullable DATATYPEGet the store value if this is unchanged.inthashCode()booleantoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.base.state.IChangeIndicator
and, and, isUnchanged, or, or
-
Constructor Details
-
ChangeWithValue
Constructor- Parameters:
aChangeIndicator- The change indicator. May not benull.aObj- The assigned value. May benull.
-
-
Method Details
-
isChanged
public boolean isChanged()- Specified by:
isChangedin interfaceIChangeIndicator- Returns:
trueif changed andfalseif unchanged.
-
get
-
getIfChanged
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 benull.- Returns:
- Either the stored value or the unchanged value. May be
null.
-
getIfChangedOrNull
Get the store value if this is a changed. Otherwisenullis returned.- Returns:
- Either the stored value or
null.
-
getIfUnchanged
Get the store value if this is unchanged. Otherwise the passed changed value is returned.- Parameters:
aChangedValue- The changed value to be used. May benull.- Returns:
- Either the stored value or the changed value. May be
null.
-
getIfUnchangedOrNull
Get the store value if this is unchanged. Otherwisenullis returned.- Returns:
- Either the stored value or
null.
-
equals
-
hashCode
public int hashCode() -
toString
-
createChanged
public static <DATATYPE> @NonNull 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 benull.- Returns:
- Never
null.
-
createUnchanged
public static <DATATYPE> @NonNull 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 benull.- Returns:
- Never
null.
-