V - value type.public class Versioned<V>
extends java.lang.Object
| Constructor and Description |
|---|
Versioned(V value,
long version)
Constructs a new versioned value.
|
Versioned(V value,
long version,
long creationTime)
Constructs a new versioned value.
|
| Modifier and Type | Method and 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.
|
public Versioned(V value, long version, long creationTime)
value - valueversion - versioncreationTime - milliseconds of the creation event
from the Java epoch of 1970-01-01T00:00:00Zpublic Versioned(V value, long version)
value - valueversion - versionpublic V value()
public long version()
public long creationTime()
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.
public <U> Versioned<U> map(java.util.function.Function<V,U> transformer)
U - value type of the returned instancetransformer - function for mapping the valuepublic static <U> U valueOrElse(Versioned<U> versioned, U defaultValue)
U - type of the versioned valueversioned - versioned objectdefaultValue - default value to return if versioned object is nullpublic static <U> U valueOrNull(Versioned<U> versioned)
U - type of the versioned valueversioned - versioned objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object