Class MdibVersion

    • 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 mdibVersion plus 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 mdibVersion plus a version counter incremented by versionCounter.
      • getSequenceId

        public String getSequenceId()
      • getInstanceId

        public BigInteger getInstanceId()
      • equals

        public boolean equals​(Object rhsObject)
        Compares two MdibVersion objects on equality.
        Overrides:
        equals in class Object
        Parameters:
        rhsObject - the right hand side to compare against with this object.
        Returns:
        true if all version attributes equal true, otherwise false.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • 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) if lhs.instanceId == rhs.instanceId
        • 1 if lhs.instanceId > rhs.instanceId || lhs.instanceId == rhs.instanceId && lhs.version > rhs.version