summaryrefslogtreecommitdiff
path: root/src/main/java/core/time
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/core/time')
-rw-r--r--src/main/java/core/time/VSLamportTime.java60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/main/java/core/time/VSLamportTime.java b/src/main/java/core/time/VSLamportTime.java
index be1226b..2973225 100644
--- a/src/main/java/core/time/VSLamportTime.java
+++ b/src/main/java/core/time/VSLamportTime.java
@@ -1,50 +1,54 @@
package core.time;
/**
- * The class VSLamportTime, defines how the lamport timestamps are represented.
+ * Immutable record representing a Lamport timestamp in the distributed system.
+ * Lamport timestamps provide a partial ordering of events in a distributed system.
+ *
+ * <p>Each timestamp contains:</p>
+ * <ul>
+ * <li>Global time - the simulation time when this timestamp was created</li>
+ * <li>Lamport time - the logical clock value following Lamport's algorithm</li>
+ * </ul>
+ *
+ * <p>This record automatically provides {@code equals()}, {@code hashCode()},
+ * and {@code toString()} implementations.</p>
*
+ * @param globalTime the global simulation time when this timestamp was recorded
+ * @param lamportTime the Lamport logical clock value
+ *
* @author Paul C. Buetow
*/
-public class VSLamportTime implements VSTime {
- /** Specified the global time of the lamport timestamp. It's used for
- * correct painting position in the simulator canvas paint area.
- */
- private long globalTime;
-
- /** Specified the process' local lamport time. */
- private long lamportTime;
-
+public record VSLamportTime(long globalTime, long lamportTime) implements VSTime {
+
/**
- * A simple constructor.
+ * Gets the global time (implements VSTime interface).
*
- * @param globalTime The global time.
- * @param lamportTime The local lamport time.
- */
- public VSLamportTime(long globalTime, long lamportTime) {
- this.globalTime = globalTime;
- this.lamportTime = lamportTime;
- }
-
- /* (non-Javadoc)
- * @see core.time.VSTime#getGlobalTime()
+ * @return the global simulation time
*/
+ @Override
public long getGlobalTime() {
return globalTime;
}
-
+
/**
- * Gets the lamport time.
+ * Gets the Lamport time value.
*
- * @return The process' local lamport time
+ * @return the Lamport logical clock value
+ * @deprecated Use {@link #lamportTime()} instead
*/
+ @Deprecated
public long getLamportTime() {
return lamportTime;
}
-
- /* (non-Javadoc)
- * @see core.time.VSTime#toString()
+
+ /**
+ * Returns a string representation of this Lamport timestamp.
+ * Format: "(lamportTime)"
+ *
+ * @return string representation of the Lamport time
*/
+ @Override
public String toString() {
return "(" + lamportTime + ")";
}
-}
+} \ No newline at end of file