summaryrefslogtreecommitdiff
path: root/src/main/java/constants/VSConstants.java
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-20 17:18:45 +0300
committerPaul Buetow <paul@buetow.org>2025-06-20 17:18:45 +0300
commit5e16f7f37c984d7ee1d1f0484cf0a8154bbb849d (patch)
treeb163049ab785dcfba3bc46cb159156e1c8566bf1 /src/main/java/constants/VSConstants.java
parent28beef18a728ec4c35e47378c514ad826c2f9a31 (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/constants/VSConstants.java')
-rw-r--r--src/main/java/constants/VSConstants.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/constants/VSConstants.java b/src/main/java/constants/VSConstants.java
new file mode 100644
index 0000000..17f6770
--- /dev/null
+++ b/src/main/java/constants/VSConstants.java
@@ -0,0 +1,75 @@
+package constants;
+
+/**
+ * Central location for constants used throughout the DS-Sim application.
+ * This class contains configuration values, limits, and other magic numbers
+ * that were previously scattered throughout the codebase.
+ *
+ * @author Paul C. Buetow
+ */
+public final class VSConstants {
+
+ // Prevent instantiation
+ private VSConstants() {}
+
+ /** Process configuration constants */
+ public static final int MIN_PROCESSES = 1;
+ public static final int MAX_PROCESSES = 6;
+ public static final int DEFAULT_PROCESSES = 3;
+
+ /** Percentage calculation */
+ public static final int PERCENTAGE_RANGE = 101;
+
+ /** Message timing constants (in milliseconds) */
+ public static final long DEFAULT_MIN_MESSAGE_TIME = 500;
+ public static final long DEFAULT_MAX_MESSAGE_TIME = 2000;
+
+ /** Simulation duration constants (in seconds) */
+ public static final int DEFAULT_SIMULATION_DURATION = 15;
+ public static final int MIN_SIMULATION_DURATION = 5;
+ public static final int MAX_SIMULATION_DURATION = 120;
+
+ /** Window size defaults */
+ public static final class WindowDefaults {
+ public static final int PREFS_WINDOW_WIDTH = 400;
+ public static final int PREFS_WINDOW_HEIGHT = 400;
+ public static final int LOG_WINDOW_HEIGHT = 300;
+ public static final int SPLIT_PANE_WIDTH = 320;
+ public static final int MAIN_WINDOW_WIDTH = 1024;
+ public static final int MAIN_WINDOW_HEIGHT = 768;
+
+ // Window positioning
+ public static final int X_LOCATION_OFFSET = 40;
+ public static final int Y_LOCATION_OFFSET = 80;
+ public static final int DEFAULT_Y_POSITION = 50;
+ }
+
+ /** UI Layout constants */
+ public static final class UILayout {
+ public static final int SPLITPANE_OFFSET = 20;
+ public static final int TIME_COLUMN_WIDTH = 62;
+ public static final int PID_COLUMN_WIDTH = 40;
+ public static final String DEFAULT_TIME_TEXT = "0000";
+ }
+
+ /** Splash screen constants */
+ public static final class SplashScreen {
+ public static final int DISPLAY_TIME = 3000; // 3 seconds
+ public static final double SPLASH_SCALE_FACTOR = 0.4;
+ public static final int FALLBACK_WIDTH = 300;
+ public static final int FALLBACK_HEIGHT = 100;
+ }
+
+ /** Language key prefixes */
+ public static final class LangKeys {
+ public static final String TASK_PREFIX = "lang.task";
+ public static final String PROCESS_PREFIX = "lang.process";
+ public static final String EVENTS_PREFIX = "lang.events";
+ public static final String PROTOCOL_PREFIX = "lang.protocol";
+ public static final String SERVER_PREFIX = "lang.server";
+ public static final String CLIENT_PREFIX = "lang.client";
+ }
+
+ /** Timestamp monitoring defaults */
+ public static final long DEFAULT_MONITOR_INTERVAL = 1;
+} \ No newline at end of file