Package com.helger.commons.state
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 Summary
Constructors Constructor Description ChangeWithValue(IChangeIndicator aChangeIndicator, DATATYPE aObj)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <DATATYPE> ChangeWithValue<DATATYPE>createChanged(DATATYPE aValue)Create a new changed object with the given value.static <DATATYPE> ChangeWithValue<DATATYPE>createUnchanged(DATATYPE aValue)Create a new unchanged object with the given value.booleanequals(Object o)DATATYPEget()DATATYPEgetIfChanged(DATATYPE aUnchangedValue)Get the store value if this is a change.DATATYPEgetIfChangedOrNull()Get the store value if this is a changed.DATATYPEgetIfUnchanged(DATATYPE aChangedValue)Get the store value if this is unchanged.DATATYPEgetIfUnchangedOrNull()Get the store value if this is unchanged.inthashCode()booleanisChanged()StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.state.IChangeIndicator
and, and, isUnchanged, or, or
-
-
-
-
Constructor Detail
-
ChangeWithValue
public ChangeWithValue(@Nonnull IChangeIndicator aChangeIndicator, @Nullable DATATYPE aObj)
Constructor- Parameters:
aChangeIndicator- The change indicator. May not benull.aObj- The assigned value. May benull.
-
-
Method Detail
-
isChanged
public boolean isChanged()
- Specified by:
isChangedin interfaceIChangeIndicator- Returns:
trueif changed andfalseif 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 benull.- 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. Otherwisenullis 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 benull.- 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. Otherwisenullis returned.- Returns:
- Either the stored value or
null.
-
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 benull.- 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 benull.- Returns:
- Never
null.
-
-