Class JDataVersionedWrapperLazy

java.lang.Object
com.usatiuk.objects.JDataVersionedWrapperLazy
All Implemented Interfaces:
Data<JDataVersionedWrapper>, MaybeTombstone<JDataVersionedWrapper>, JDataVersionedWrapper

public final class JDataVersionedWrapperLazy extends Object implements JDataVersionedWrapper
Lazy JDataVersionedWrapper implementation. The object is deserialized only when data() is called for the first time. Also allows to set a callback to be called when the data is loaded (e.g. to cache it).
  • Constructor Details

    • JDataVersionedWrapperLazy

      public JDataVersionedWrapperLazy(long version, int estimatedSize, Supplier<JData> producer)
      Creates a new JDataVersionedWrapperLazy object.
      Parameters:
      version - the version number of the object
      estimatedSize - the estimated size of the object in bytes
      producer - a supplier that produces the wrapped object
  • Method Details

    • setCacheCallback

      public void setCacheCallback(Runnable cacheCallback)
      Set a callback to be called when the data is loaded.
      Parameters:
      cacheCallback - the callback to be called
    • data

      public JData data()
      Description copied from interface: JDataVersionedWrapper
      Returns the wrapped object.
      Specified by:
      data in interface JDataVersionedWrapper
      Returns:
      the wrapped object
    • version

      public long version()
      Description copied from interface: JDataVersionedWrapper
      Returns the version number of the object.
      Specified by:
      version in interface JDataVersionedWrapper
      Returns:
      the version number of the object
    • estimateSize

      public int estimateSize()
      Description copied from interface: JDataVersionedWrapper
      Returns the estimated size of the object in bytes.
      Specified by:
      estimateSize in interface JDataVersionedWrapper
      Returns:
      the estimated size of the object in bytes