Class DataVersion

Object
DataVersion

@PublicApi @Immutable public class DataVersion extends Object

DataVersion is used to identify whether some content has changed and to support incremental updates. It contains two numbers:

  • signature, which is a randomly chosen value that defines the "namespace" for the second number, and
  • version, which is a number that is incremented every time an update to the data happens.

The code that observes VersionedDataSource would typically store last received DataVersion and use it next time in VersionedDataSource.getUpdate(DataVersion).

The code that implements VersionedDataSource, would typically increment version when an incremental update happens and reinitialize signature when non-incremental update happens.

Two instances of DataVersion can be compared — we can tell which one happened before which, but only if their signatures match.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final DataVersion
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataVersion(int signature, int version)
    Constructs DataVersion.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    int
    Signature defines the identity of the version sequence.
    int
    Returns the version within one sequence, identified by signature
    int
     
    Creates a new DataVersion with version incremented by 1.
    increment(int count)
    Creates a new DataVersion with version incremented by the specified amount.
    boolean
    isBefore(DataVersion anotherVersion)
    Returns true if this version is "before" the given version, that is, it has the same signature and lower version.
    boolean
    isComparable(DataVersion anotherVersion)
    Returns true if this version can be compared to the specified version (that is possible only if their signatures match)
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • DataVersion

      public DataVersion(int signature, int version)
      Constructs DataVersion.
  • Method Details

    • isComparable

      public boolean isComparable(@Nullable DataVersion anotherVersion)
      Returns true if this version can be compared to the specified version (that is possible only if their signatures match)
    • isBefore

      public boolean isBefore(@Nullable DataVersion anotherVersion)
      Returns true if this version is "before" the given version, that is, it has the same signature and lower version.
    • increment

      public DataVersion increment()
      Creates a new DataVersion with version incremented by 1.
    • increment

      public DataVersion increment(int count)
      Creates a new DataVersion with version incremented by the specified amount.
    • getSignature

      public int getSignature()
      Signature defines the identity of the version sequence. Only versions within the same signature can be compared.
      Returns:
      the signature of the version sequence
    • getVersion

      public int getVersion()
      Returns the version within one sequence, identified by signature
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object