diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-20 20:04:02 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-20 20:04:02 +0300 |
| commit | f0b58321ae53f330da86c392661354b87bd9a412 (patch) | |
| tree | c0be72f57094d13cf8bcb53567614258a6eb43fa /src/main/java/core/time | |
| parent | c3b95267b24d843897b04d6d6a16f62dc8cf1ed2 (diff) | |
Modernize codebase to use Java 21 features
- 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 <noreply@anthropic.com>
Diffstat (limited to 'src/main/java/core/time')
| -rw-r--r-- | src/main/java/core/time/VSLamportTime.java | 60 |
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 |
