public class VersionedReference<T>
extends java.lang.Object
This is an upside-down way of doing change notification that does not have the event overhead or listener-leak potential of a typical event/listener framework. It is not appropriate for all cases but can be used in cases where values are often changed frequently and/or it's ok to ignore stacks of events in favor of the latest value. Common applications are things like sliders, document models, etc. for which some view will update itself only when the watched object changes, but otherwise doesn't care about the specific granularity of events.
Constructor and Description |
---|
VersionedReference(VersionedObject<T> object) |
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns the current version of the referenced object.
|
long |
getLastVersion()
Returns the version of the referenced object that last
time update() was called.
|
long |
getObjectVersion()
Returns the current version of the referenced object.
|
boolean |
needsUpdate()
Returns true if the current version of the object
differs from the version the last time update() was called.
|
boolean |
update()
Updates the referenced version to the current version and
returns true if the referenced version was changed.
|
public VersionedReference(VersionedObject<T> object)
public long getLastVersion()
public long getObjectVersion()
public boolean needsUpdate()
public boolean update()
public T get()