Class CSN

    • Constructor Detail

      • CSN

        public CSN​(String str)
        Create a new CSN from a String.
        Parameters:
        str - the string from which to create a CSN
        Throws:
        org.forgerock.i18n.LocalizedIllegalArgumentException - If the provided string is not a valid toString() representation of a CSN
      • CSN

        public CSN​(long timeStamp,
                   int seqNum,
                   int serverId)
        Create a new CSN.
        Parameters:
        timeStamp - timeStamp for the CSN
        seqNum - sequence number
        serverId - identity of server
    • Method Detail

      • valueOf

        public static CSN valueOf​(String s)
        Parses the provided toString() representation of a CSN.
        Parameters:
        s - The string to be parsed.
        Returns:
        The parsed CSN.
        Throws:
        org.forgerock.i18n.LocalizedIllegalArgumentException - If the provided string is not a valid toString() representation of a CSN
        See Also:
        toString()
      • valueOf

        public static CSN valueOf​(ByteSequence bs)
        Decodes the provided toByteString() representation of a change number.
        Parameters:
        bs - The byte sequence to be parsed.
        Returns:
        The decoded CSN.
        See Also:
        toByteString()
      • getTime

        public long getTime()
        Getter for the time.
        Returns:
        the time
      • getTimeSec

        public long getTimeSec()
        Get the timestamp associated to this CSN in seconds.
        Returns:
        timestamp associated to this CSN in seconds
      • getSeqnum

        public int getSeqnum()
        Getter for the sequence number.
        Returns:
        the sequence number
      • getServerId

        public int getServerId()
        Getter for the server ID.
        Returns:
        the server ID
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toByteString

        public ByteString toByteString()
        Encodes this CSN as a byte string.

        NOTE: this representation must not be modified otherwise interop with earlier protocol versions will be broken.

        Returns:
        The encoded representation of this CSN.
        See Also:
        valueOf(ByteSequence)
      • toByteString

        public void toByteString​(ByteStringBuilder builder)
        Encodes this CSN into the provided byte string builder.

        NOTE: this representation must not be modified otherwise interop with earlier protocol versions will be broken.

        Parameters:
        builder - The byte string builder.
        See Also:
        valueOf(ByteSequence)
      • toString

        public String toString()
        Convert the CSN to a printable String.

        NOTE: this representation must not be modified otherwise interop with earlier protocol versions will be broken.

        Overrides:
        toString in class Object
        Returns:
        the string
      • toStringUI

        public String toStringUI()
        Convert the CSN to a printable String with a user friendly format.
        Returns:
        the string
      • compare

        public static int compare​(CSN csn1,
                                  CSN csn2)
        Compares this CSN with the provided CSN for order and returns a negative number if csn1 is older than csn2, zero if they have the same age, or a positive number if csn1 is newer than csn2.
        Parameters:
        csn1 - The first CSN to be compared, which may be null.
        csn2 - The second CSN to be compared, which may be null.
        Returns:
        A negative number if csn1 is older than csn2, zero if they have the same age, or a positive number if csn1 is newer than csn2.
      • diffSeqNum

        public static int diffSeqNum​(CSN csn1,
                                     CSN csn2)
        Computes the difference in number of changes between 2 CSNs. First one is expected to be newer than second one. If this is not the case, 0 will be returned.
        Parameters:
        csn1 - the first CSN
        csn2 - the second CSN
        Returns:
        the difference
      • isOlderThan

        public boolean isOlderThan​(CSN csn)
        Returns true if this CSN is older than the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is older than the provided CSN.
      • isOlderThanOrEqualTo

        public boolean isOlderThanOrEqualTo​(CSN csn)
        Returns true if this CSN is older than or equal to the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is older than or equal to the provided CSN.
      • isNewerThanOrEqualTo

        public boolean isNewerThanOrEqualTo​(CSN csn)
        Returns true if this CSN is newer than or equal to the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is newer than or equal to the provided CSN.
      • isNewerThan

        public boolean isNewerThan​(CSN csn)
        Returns true if this CSN is newer than the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is newer than the provided CSN.
      • compareTo

        public int compareTo​(CSN csn)
        Compares this CSN with the provided CSN for order and returns a negative number if this CSN is older than csn, zero if they have the same age, or a positive number if this CSN is newer than csn.
        Specified by:
        compareTo in interface Comparable<CSN>
        Parameters:
        csn - The CSN to be compared.
        Returns:
        A negative number if this CSN is older than csn, zero if they have the same age, or a positive number if this CSN is newer than csn.