From f0b58321ae53f330da86c392661354b87bd9a412 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 20 Jun 2025 20:04:02 +0300 Subject: Modernize codebase to use Java 21 features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Convert VS3Tupel and VSLamportTime to records for immutability - Use switch expressions with pattern matching in VSTimestampTriggeredEvent - Modernize exception handling with pattern matching in VSErrorHandler - Replace anonymous ActionListener with lambda in VSAboutFrame - Use formatted strings instead of concatenation in VSDummyProtocol - Add sealed hierarchy VSEventType for exhaustive pattern matching - Create VSSimulationConfig record for configuration management - Maintain backward compatibility with deprecated methods All 132 unit tests pass successfully with Java 21 features. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/main/java/core/time/VSLamportTime.java | 60 ++++++++++++++++-------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'src/main/java/core/time') 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. + * + *

Each timestamp contains:

+ * + * + *

This record automatically provides {@code equals()}, {@code hashCode()}, + * and {@code toString()} implementations.

* + * @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 -- cgit v1.2.3