Class Versioned<V>

  • Type Parameters:
    V - value type.

    public class Versioned<V>
    extends java.lang.Object
    Versioned value.
    • Constructor Summary

      Constructors 
      Constructor Description
      Versioned​(V value, long version)
      Constructs a new versioned value.
      Versioned​(V value, long version, long creationTime)
      Constructs a new versioned value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long creationTime()
      Returns the system time when this version was created.
      boolean equals​(java.lang.Object other)  
      int hashCode()  
      <U> Versioned<U> map​(java.util.function.Function<V,​U> transformer)
      Maps this instance into another after transforming its value while retaining the same version and creationTime.
      java.lang.String toString()  
      V value()
      Returns the value.
      static <U> U valueOrElse​(Versioned<U> versioned, U defaultValue)
      Returns the value of the specified Versioned object if non-null or else returns a default value.
      static <U> U valueOrNull​(Versioned<U> versioned)
      Returns the value of the specified Versioned object if non-null or else returns null.
      long version()
      Returns the version.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Versioned

        public Versioned​(V value,
                         long version,
                         long creationTime)
        Constructs a new versioned value.
        Parameters:
        value - value
        version - version
        creationTime - milliseconds of the creation event from the Java epoch of 1970-01-01T00:00:00Z
      • Versioned

        public Versioned​(V value,
                         long version)
        Constructs a new versioned value.
        Parameters:
        value - value
        version - version
    • Method Detail

      • value

        public V value()
        Returns the value.
        Returns:
        value.
      • version

        public long version()
        Returns the version.
        Returns:
        version
      • creationTime

        public long creationTime()
        Returns the system time when this version was created.

        Care should be taken when relying on creationTime to implement any behavior in a distributed setting. Due to the possibility of clock skew it is likely that even creationTimes of causally related versions can be out or order.

        Returns:
        creation time
      • map

        public <U> Versioned<U> map​(java.util.function.Function<V,​U> transformer)
        Maps this instance into another after transforming its value while retaining the same version and creationTime.
        Type Parameters:
        U - value type of the returned instance
        Parameters:
        transformer - function for mapping the value
        Returns:
        mapped instance
      • valueOrElse

        public static <U> U valueOrElse​(Versioned<U> versioned,
                                        U defaultValue)
        Returns the value of the specified Versioned object if non-null or else returns a default value.
        Type Parameters:
        U - type of the versioned value
        Parameters:
        versioned - versioned object
        defaultValue - default value to return if versioned object is null
        Returns:
        versioned value or default value if versioned object is null
      • valueOrNull

        public static <U> U valueOrNull​(Versioned<U> versioned)
        Returns the value of the specified Versioned object if non-null or else returns null.
        Type Parameters:
        U - type of the versioned value
        Parameters:
        versioned - versioned object
        Returns:
        versioned value or null if versioned object is null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object