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
ConstructorsConstructorDescriptionChangeWithValue(IChangeIndicator aChangeIndicator, DATATYPE aObj) Constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.booleanget()getIfChanged(DATATYPE aUnchangedValue) Get the store value if this is a change.Get the store value if this is a changed.getIfUnchanged(DATATYPE aChangedValue) Get the store value if this is unchanged.Get 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.commons.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
@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.
-