T - the generic typepublic class CachedData<T> extends java.lang.Object implements ICachedData
update() must be called to refresh the data before calling hasChanged().| Modifier and Type | Field and Description |
|---|---|
protected T |
currentData
Current data.
|
protected java.util.function.Supplier<T> |
getter
Supplier to fetch the current data.
|
protected T |
lastData
Data at the last update.
|
protected java.util.function.BiPredicate<T,T> |
predicate
Predicate to test if data has changed.
|
| Constructor and Description |
|---|
CachedData(java.util.function.Supplier<T> getter)
Instantiates a new
CachedData. |
CachedData(java.util.function.Supplier<T> getter,
java.util.function.BiPredicate<T,T> predicate)
Instantiates a new
CachedData. |
| Modifier and Type | Method and Description |
|---|---|
T |
get()
Gets the current data.
|
boolean |
hasChanged()
Checks whether the data has changed since the last update.
|
void |
update()
Updates the current data.
|
protected java.util.function.Supplier<T> getter
protected java.util.function.BiPredicate<T,T> predicate
protected T lastData
protected T currentData
public CachedData(java.util.function.Supplier<T> getter, java.util.function.BiPredicate<T,T> predicate)
CachedData.getter - the getterpredicate - the predicatepublic CachedData(java.util.function.Supplier<T> getter)
CachedData.getter - the getterpublic T get()
public void update()
update in interface ICachedDatapublic boolean hasChanged()
hasChanged in interface ICachedData