Class VersionedReference<T>

java.lang.Object
com.simsilica.lemur.core.VersionedReference<T>

public class VersionedReference<T> extends Object
Tracks an update version of a VersionedObject and can provide basic change tracking for a caller. Calling code can hold a VersionedReference to some value and call update() to update the local version field and detect if the version has changed since the last check.

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 Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Returns the current version of the referenced object.
    long
    Returns the version of the referenced object that last time update() was called.
    long
    Returns the current version of the referenced object.
    boolean
    Returns true if the current version of the object differs from the version the last time update() was called.
    boolean
    Updates the referenced version to the current version and returns true if the referenced version was changed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getLastVersion

      public long getLastVersion()
      Returns the version of the referenced object that last time update() was called.
    • getObjectVersion

      public long getObjectVersion()
      Returns the current version of the referenced object.
    • needsUpdate

      public boolean needsUpdate()
      Returns true if the current version of the object differs from the version the last time update() was called.
    • update

      public boolean update()
      Updates the referenced version to the current version and returns true if the referenced version was changed.
    • get

      public T get()
      Returns the current version of the referenced object.