Class MdibVersion
- java.lang.Object
-
- org.somda.sdc.biceps.model.participant.MdibVersion
-
public class MdibVersion extends Object
Container for MDIB version attributes.This class models the MDIB version attributes that lack a separate container in the XML Schema. It models sequence id, instance id and version number, enclosed in one class. MdibVersion is an immutable class and provides means to
- create versions with random UUID by
create() - increment versions by
increment(MdibVersion) - set the version counter of an MdibVersion by
setVersionCounter(MdibVersion, BigInteger) - compare versions (see
equals(Object))
- create versions with random UUID by
-
-
Constructor Summary
Constructors Constructor Description MdibVersion(String sequenceId)Constructor that sets a given sequence id.MdibVersion(String sequenceId, BigInteger version)Constructor that sets a given sequence id and version counter.MdibVersion(String sequenceId, BigInteger version, BigInteger instanceId)Constructor that sets all version attributes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<Integer>compareToMdibVersion(MdibVersion rhs)Compares two MDIB versions.static MdibVersioncreate()Creates a new instance with a random sequence id.booleanequals(Object rhsObject)Compares two MdibVersion objects on equality.BigIntegergetInstanceId()StringgetSequenceId()BigIntegergetVersion()inthashCode()static MdibVersionincrement(MdibVersion mdibVersion)Accepts an existing instance and increments the version counter.static MdibVersionsetVersionCounter(MdibVersion mdibVersion, BigInteger versionCounter)Accepts an existing instance and resets the version counter to the given number.StringtoString()
-
-
-
Constructor Detail
-
MdibVersion
public MdibVersion(String sequenceId)
Constructor that sets a given sequence id.Instance id and version counter are initialized with 0.
- Parameters:
sequenceId- the sequence id to set.
-
MdibVersion
public MdibVersion(String sequenceId, BigInteger version)
Constructor that sets a given sequence id and version counter.Instance id is initialized with 0.
- Parameters:
sequenceId- the sequence id to set.version- the version counter to set.
-
MdibVersion
public MdibVersion(String sequenceId, BigInteger version, BigInteger instanceId)
Constructor that sets all version attributes.- Parameters:
sequenceId- the sequence id to set.version- the version counter to set.instanceId- the instance id to set.
-
-
Method Detail
-
create
public static MdibVersion create()
Creates a new instance with a random sequence id.- Returns:
- a new instance.
-
increment
public static MdibVersion increment(MdibVersion mdibVersion)
Accepts an existing instance and increments the version counter.- Parameters:
mdibVersion- the version base.- Returns:
- a new instance with same sequence and instance id as in
mdibVersionplus a version counter incremented by one.
-
setVersionCounter
public static MdibVersion setVersionCounter(MdibVersion mdibVersion, BigInteger versionCounter)
Accepts an existing instance and resets the version counter to the given number.- Parameters:
mdibVersion- the version base.versionCounter- the version counter number to replace.- Returns:
- a new instance with same sequence and instance id as in
mdibVersionplus a version counter incremented byversionCounter.
-
getSequenceId
public String getSequenceId()
-
getVersion
public BigInteger getVersion()
-
getInstanceId
public BigInteger getInstanceId()
-
equals
public boolean equals(Object rhsObject)
Compares two MdibVersion objects on equality.
-
compareToMdibVersion
public Optional<Integer> compareToMdibVersion(@Nullable MdibVersion rhs)
Compares two MDIB versions.As the MDIB version is a triple consisting of at least one non-trivially comparable data type, it cannot be compared the classical way. Hence there is a set of rules that define what to expect depending on the data of that triple. For that reason this compare function introduces a fourth result state, which is Optional.empty(), in case that the non-trivially comparable sequence ids are not equal.
- Parameters:
rhs- right hand side to compare.- Returns:
- depending on the fields of the MDIB version triple:
- Optional.empty() if sequence ids differ from each other
- -1 if
lhs.instanceId < rhs.instanceId || lhs.instanceId == rhs.instanceId && lhs.version < rhs.version - the result of
lhs.version.compareTo(rhs.version)iflhs.instanceId == rhs.instanceId - 1 if
lhs.instanceId > rhs.instanceId || lhs.instanceId == rhs.instanceId && lhs.version > rhs.version
-
-