Class LamportVectorClock

java.lang.Object
org.mpi_sws.jmc.util.LamportVectorClock
All Implemented Interfaces:
PartialOrder<LamportVectorClock>

public class LamportVectorClock extends Object implements PartialOrder<LamportVectorClock>
Represents a Lamport vector clock used by the algorithm. It is of variable length.
  • Constructor Details

    • LamportVectorClock

      public LamportVectorClock(int size)
      Creates a new Lamport vector clock with the given size.
      Parameters:
      size - The size of the vector clock.
    • LamportVectorClock

      public LamportVectorClock(int[] vector)
      Creates a new Lamport vector clock with the given vector.
      Parameters:
      vector - The vector clock.
    • LamportVectorClock

      public LamportVectorClock(LamportVectorClock other, int index)
      Creates a new Lamport vector clock with the given vector, incrementing the value at the given index.
      Parameters:
      other - The vector clock.
      index - The index of the component to increment.
  • Method Details

    • getVector

      public int[] getVector()
      Returns the vector clock.
      Returns:
      The vector clock.
    • getSize

      public int getSize()
      Returns the size of the vector clock.
      Returns:
      The size of the vector clock.
    • update

      public void update(LamportVectorClock other)
      Updates the vector clock with the given vector clock.
      Parameters:
      other - The other vector clock.
    • happensBefore

      public boolean happensBefore(LamportVectorClock other)
      Checks if this vector clock happens before the other vector clock. (less than or equal to)
      Parameters:
      other - The other vector clock.
      Returns:
      True if this vector clock happened before the other vector clock, false otherwise.
    • equals

      public boolean equals(LamportVectorClock other)
      Returns the string representation of the vector clock.
      Returns:
      The string representation of the vector clock.
    • max

      public int max()
      Returns the maximum value in the vector clock.
      Returns:
      The maximum value in the vector clock.
    • compare

      public PartialOrder.Relation compare(LamportVectorClock other)
      Description copied from interface: PartialOrder
      Compares two objects of type T - the current instance and the other object.
      Specified by:
      compare in interface PartialOrder<LamportVectorClock>
      Parameters:
      other - the other object to compare to.
      Returns:
      The relation between the two objects.