pt.unl.fct.di.novasys.babel.crdts.state.utils

Class Timestamp

  • All Implemented Interfaces:
    Comparable<Timestamp>


    public class Timestamp
    extends Object
    implements Comparable<Timestamp>
    Represents a timestamp to enable ordering of operations. The timestamp is composed as a replica identifier (replicaID) and a monotonic increasing counter (counter).
    • Field Detail

      • serializer

        public static pt.unl.fct.di.novasys.network.ISerializer<Timestamp> serializer
        A serializer to serialize a given timestamp.
    • Constructor Detail

      • Timestamp

        public Timestamp(ReplicaID replicaID,
                         int counter)
        Creates a new timestamp.
        Parameters:
        replicaID - replica identifier
        counter - the counter (must be bigger than zero).
      • Timestamp

        public Timestamp(ReplicaID replicaID)
        Creates a new timestamp with the counter as zero.
        Parameters:
        replicaID - replica identifier
    • Method Detail

      • getCount

        public int getCount()
        Get the current counter value.
        Returns:
        the counter value.
      • getReplicaID

        public ReplicaID getReplicaID()
        Get the replica identifier
        Returns:
        the replica identifier
      • isSmaller

        public boolean isSmaller(Timestamp ts)
        Checks if a given timestamp is smaller than the current counter
        Parameters:
        ts - timestamp to compare
        Returns:
        true if it is, or false otherwhise
      • isSmallerOrEqual

        public boolean isSmallerOrEqual(Timestamp ts)
        Checks if a given timestamp is smaller or equal than the current counter
        Parameters:
        ts - timestamp to compare
        Returns:
        true if it is, or false otherwhise
      • isBigger

        public boolean isBigger(Timestamp ts)
        Checks if a given timestamp is bigger than the current counter
        Parameters:
        ts - timestamp to compare
        Returns:
        true if it is, or false otherwhise
      • isBiggerOrEqual

        public boolean isBiggerOrEqual(Timestamp ts)
        Checks if a given timestamp is bigger or equal than the current counter
        Parameters:
        ts - timestamp to compare
        Returns:
        true if it is, or false otherwhise
      • isEqual

        public boolean isEqual(Timestamp ts)
        Checks if a given timestamp is equal than the current counter
        Parameters:
        ts - timestamp to compare
        Returns:
        true if it is, or false otherwhise
      • copy

        public Timestamp copy()
        Creates a copy of this timestamp. Modifying the copy doesn't alter the orginal one.
        Returns:
        a copy of the timestamp.
      • hashCode

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

        public int compareTo(Timestamp o)
        Compares a timestamp passed as argument with this timestamp. This method offers a total order between any two timestamps. If the counter of both timestamps is equal, a tiebreaker is done on the replicas identifiers.
        Specified by:
        compareTo in interface Comparable<Timestamp>
      • max

        public static Timestamp max(Timestamp ts1,
                                    Timestamp ts2)
        Compares two timestamps. If they are equal, the first timestamp is returned
        Parameters:
        ts1 - the first timestamp
        ts2 - the second timestamp
        Returns:
        the bigger timestamp

Copyright © 2024. All rights reserved.