Class Versioned<V>

  • Type Parameters:
    V - value type.

    public class Versioned<V>
    extends Object
    Versioned value.
    • 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​(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 Object