Package org.onosproject.store.service
Class Versioned<V>
- java.lang.Object
-
- org.onosproject.store.service.Versioned<V>
-
- Type Parameters:
V
- value type.
public class Versioned<V> extends Object
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(Object other)
int
hashCode()
<U> Versioned<U>
map(Function<V,U> transformer)
Maps this instance into another after transforming its value while retaining the same version and creationTime.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.
-
-
-
Constructor Detail
-
Versioned
public Versioned(V value, long version, long creationTime)
Constructs a new versioned value.- Parameters:
value
- valueversion
- versioncreationTime
- 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
- valueversion
- 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 objectdefaultValue
- 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
-
-