diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-20 17:18:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-20 17:18:45 +0300 |
| commit | 5e16f7f37c984d7ee1d1f0484cf0a8154bbb849d (patch) | |
| tree | b163049ab785dcfba3bc46cb159156e1c8566bf1 /src/main/java/events/implementations/VSProcessCrashEvent.java | |
| parent | 28beef18a728ec4c35e47378c514ad826c2f9a31 (diff) | |
Improve code quality: Replace instanceof with polymorphism and extract constants
Major improvements:
1. Replace instanceof checks with polymorphic methods in VSAbstractEvent hierarchy
- Added isInternalEvent(), isMessageReceiveEvent(), etc. methods
- Added getEventPriority() for clean event ordering
- Added shouldIncreaseTimestamps() to control timestamp behavior
- Refactored VSTask to use these polymorphic methods
2. Extract magic numbers and strings to constants
- Created VSConstants class for centralized configuration values
- Added event priority constants (PRIORITY_HIGHEST, PRIORITY_HIGH, etc.)
- Extracted string constants like CLASS_PREFIX
- Moved magic numbers to named constants (PERCENTAGE_RANGE, etc.)
3. Update tests to work with new polymorphic approach
- Fixed mocking in VSTaskTest to return correct values
- All 132 tests passing
These changes improve maintainability, reduce coupling, and make the codebase
more self-documenting. The polymorphic approach eliminates type checking and
makes it easier to add new event types.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/main/java/events/implementations/VSProcessCrashEvent.java')
| -rw-r--r-- | src/main/java/events/implementations/VSProcessCrashEvent.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/main/java/events/implementations/VSProcessCrashEvent.java b/src/main/java/events/implementations/VSProcessCrashEvent.java index a68e8a1..1f9fc49 100644 --- a/src/main/java/events/implementations/VSProcessCrashEvent.java +++ b/src/main/java/events/implementations/VSProcessCrashEvent.java @@ -11,6 +11,17 @@ import simulator.VSMain; */ public class VSProcessCrashEvent extends VSAbstractEvent implements VSCopyableEvent { + + @Override + public boolean isProcessCrashEvent() { + return true; + } + + @Override + public int getEventPriority() { + return PRIORITY_HIGH; + } + /* (non-Javadoc) * @see events.VSCopyableEvent#initCopy(events.VSAbstractEvent) */ |
