Package org.mpi_sws.jmc.util
Class LamportVectorClock
java.lang.Object
org.mpi_sws.jmc.util.LamportVectorClock
- All Implemented Interfaces:
PartialOrder<LamportVectorClock>
Represents a Lamport vector clock used by the algorithm. It is of variable length.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a component of the Lamport vector clock.Nested classes/interfaces inherited from interface org.mpi_sws.jmc.util.PartialOrder
PartialOrder.Relation -
Constructor Summary
ConstructorsConstructorDescriptionLamportVectorClock(int size) Creates a new Lamport vector clock with the given size.LamportVectorClock(int[] vector) Creates a new Lamport vector clock with the given vector.LamportVectorClock(LamportVectorClock other, int index) Creates a new Lamport vector clock with the given vector, incrementing the value at the given index. -
Method Summary
Modifier and TypeMethodDescriptioncompare(LamportVectorClock other) Compares two objects of type T - the current instance and the other object.booleanequals(LamportVectorClock other) Returns the string representation of the vector clock.intgetSize()Returns the size of the vector clock.int[]Returns the vector clock.booleanhappensBefore(LamportVectorClock other) Checks if this vector clock happens before the other vector clock.intmax()Returns the maximum value in the vector clock.voidupdate(LamportVectorClock other) Updates the vector clock with the given vector clock.
-
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
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
Updates the vector clock with the given vector clock.- Parameters:
other- The other vector clock.
-
happensBefore
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
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
Description copied from interface:PartialOrderCompares two objects of type T - the current instance and the other object.- Specified by:
comparein interfacePartialOrder<LamportVectorClock>- Parameters:
other- the other object to compare to.- Returns:
- The relation between the two objects.
-