Skip to content

Commit e1f3b39

Browse files
CopilotbedaHovorka
andcommitted
Convert EditingContext getter/setter methods to properties
- Convert getCurrentMaxSpeed/setCurrentMaxSpeed to currentMaxSpeed property - Convert getCurrentTrackLength/setCurrentTrackLength to currentTrackLength property - Convert getCurrentNameString/setCurrentNameString to currentNameString property - Update all call sites in source and tests to use property syntax - All tests pass (629/659 active tests) - Code quality checks pass (ktlint, detekt) Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
1 parent 490a558 commit e1f3b39

5 files changed

Lines changed: 32 additions & 74 deletions

File tree

src/main/kotlin/cz/vutbr/fit/interlockSim/context/DefaultContext.kt

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,20 @@ abstract class DefaultContext :
9292
/**
9393
* Current maximum speed for path elements
9494
*/
95-
private var currentMaxSpeed: Double = PathElement.COMMON_MAX_SPEED
95+
override var currentMaxSpeed: Double = PathElement.COMMON_MAX_SPEED
9696

9797
/**
9898
* Current track length for new track elements
9999
*/
100-
private var currentTrackLength: Double = Track.COMMON_TRACK_LENGTH
100+
override var currentTrackLength: Double = Track.COMMON_TRACK_LENGTH
101101

102102
/**
103103
* Railway network grid structure
104104
*/
105105
private val railwayNetGrid: DefaultRailWayNetGrid
106106

107107
/**
108-
* Name string for train generation
108+
* Name string for train generation (backing field for currentNameString)
109109
*/
110110
private var nameString: String? = null
111111

@@ -536,7 +536,7 @@ abstract class DefaultContext :
536536
s1,
537537
p,
538538
s2,
539-
SimpleTrackBlock(nodeCell, nodeCell2, Track.MIN_LENGTH, getCurrentMaxSpeed())
539+
SimpleTrackBlock(nodeCell, nodeCell2, Track.MIN_LENGTH, currentMaxSpeed)
540540
)
541541
}
542542
}
@@ -872,30 +872,6 @@ abstract class DefaultContext :
872872
return null
873873
}
874874

875-
/**
876-
* Get current maximum speed for path elements
877-
*/
878-
override fun getCurrentMaxSpeed(): Double = currentMaxSpeed
879-
880-
/**
881-
* Get current track length for new elements
882-
*/
883-
override fun getCurrentTrackLength(): Double = currentTrackLength
884-
885-
/**
886-
* Set current maximum speed
887-
*/
888-
override fun setCurrentMaxSpeed(speed: Double) {
889-
currentMaxSpeed = speed
890-
}
891-
892-
/**
893-
* Set current track length
894-
*/
895-
override fun setCurrentTrackLength(length: Double) {
896-
currentTrackLength = length
897-
}
898-
899875
/**
900876
* Report simulation events
901877
*/
@@ -948,22 +924,19 @@ abstract class DefaultContext :
948924
}
949925

950926
/**
951-
* Get current name string for train generation
927+
* Current name string for train generation
952928
*/
953-
override fun getCurrentNameString(): String = nameString ?: randomString()
929+
override var currentNameString: String
930+
get() = nameString ?: randomString()
931+
set(value) {
932+
nameString = value
933+
}
954934

955935
/**
956936
* Generate random name string (single character A-T)
957937
*/
958938
private fun randomString(): String = String(Character.toChars(65 + random.nextInt(20)))
959939

960-
/**
961-
* Set current name string for train generation
962-
*/
963-
override fun setCurrentNameString(name: String) {
964-
this.nameString = name
965-
}
966-
967940
/**
968941
* Get the worker for an entry/exit point
969942
*/

src/main/kotlin/cz/vutbr/fit/interlockSim/context/EditingContext.kt

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,14 @@ interface EditingContext : Context {
5050
fun removeLine(block: TrackBlock)
5151

5252
/**
53-
* @return current maximal speed, which is setting in elements
53+
* Current maximal speed, which is setting in elements
5454
*/
55-
fun getCurrentMaxSpeed(): Double
55+
var currentMaxSpeed: Double
5656

5757
/**
58-
* @param speed maximal speed, which is setting in elements
58+
* Current track length, which is setting in elements
5959
*/
60-
fun setCurrentMaxSpeed(speed: Double)
61-
62-
/**
63-
* @return current track length, which is setting in elements
64-
*/
65-
fun getCurrentTrackLength(): Double
66-
67-
/**
68-
* @param length track length, which is setting in elements
69-
*/
70-
fun setCurrentTrackLength(length: Double)
60+
var currentTrackLength: Double
7161

7262
/**
7363
* Create relation between nodes. In specified places, must be {@link NodeCell}
@@ -82,12 +72,7 @@ interface EditingContext : Context {
8272
)
8373

8474
/**
85-
* @param name which is setting in elements
86-
*/
87-
fun setCurrentNameString(name: String)
88-
89-
/**
90-
* @return name which is setting in elements
75+
* Name which is setting in elements
9176
*/
92-
fun getCurrentNameString(): String
77+
var currentNameString: String
9378
}

src/main/kotlin/cz/vutbr/fit/interlockSim/gui/RailwayNetGridCanvas.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class RailwayNetGridCanvas :
120120
*(toolbarArgs!! as Array<Any>)
121121
) as NodeCell
122122
if (newCell is InOut) {
123-
newCell.setName(editingContext.getCurrentNameString())
123+
newCell.setName(editingContext.currentNameString)
124124
}
125125
editingContext.putCell(clickKey, newCell)
126126
// Clear selection after creating a cell to prevent auto-joining
@@ -143,8 +143,8 @@ class RailwayNetGridCanvas :
143143
SimpleTrackBlock(
144144
selectedCell,
145145
cellAtClick,
146-
editingContext.getCurrentTrackLength(),
147-
editingContext.getCurrentMaxSpeed()
146+
editingContext.currentTrackLength,
147+
editingContext.currentMaxSpeed
148148
)
149149
editingContext.joinCells(selectedPoint, clickKey, trackBlock)
150150
repaint()

src/test/kotlin/cz/vutbr/fit/interlockSim/context/ContextInitializationTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class ContextInitializationTest {
345345
@DisplayName("context preserves name from XML initialization")
346346
fun context_preservesName() {
347347
// Arrange & Act
348-
val contextName = linearTrackContext.getCurrentNameString()
348+
val contextName = linearTrackContext.currentNameString
349349

350350
// Assert
351351
assertThat(contextName)
@@ -363,8 +363,8 @@ class ContextInitializationTest {
363363
@DisplayName("context initialized with valid configuration settings")
364364
fun context_hasValidSettings() {
365365
// Arrange & Act
366-
val maxSpeed = linearTrackContext.getCurrentMaxSpeed()
367-
val trackLength = linearTrackContext.getCurrentTrackLength()
366+
val maxSpeed = linearTrackContext.currentMaxSpeed
367+
val trackLength = linearTrackContext.currentTrackLength
368368

369369
// Assert
370370
assertThat(maxSpeed)
@@ -398,7 +398,7 @@ class ContextInitializationTest {
398398
.isNotNull()
399399

400400
// Railway context: Default settings should be applicable
401-
assertThat(emptyContext.getCurrentMaxSpeed())
401+
assertThat(emptyContext.currentMaxSpeed)
402402
.withMessage("Empty context should have max speed setting")
403403
.isGreaterThan(0.0)
404404
}
@@ -470,13 +470,13 @@ class ContextInitializationTest {
470470
val context2 = factory.createEmptyContext()
471471

472472
// Modify first context
473-
context1.setCurrentNameString("Network A")
473+
context1.currentNameString = "Network A"
474474

475475
// Assert
476-
assertThat(context1.getCurrentNameString())
476+
assertThat(context1.currentNameString)
477477
.withMessage("First context should have modified name")
478478
.isEqualTo("Network A")
479-
assertThat(context2.getCurrentNameString())
479+
assertThat(context2.currentNameString)
480480
.withMessage("Second context should have different name (independent)")
481481
.isNotNull()
482482
}

src/test/kotlin/cz/vutbr/fit/interlockSim/context/DefaultContextTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ class DefaultContextTest {
319319
val newSpeed = 120.0
320320

321321
// Act
322-
context.setCurrentMaxSpeed(newSpeed)
322+
context.currentMaxSpeed = newSpeed
323323

324324
// Assert
325-
assertThat(context.getCurrentMaxSpeed()).isEqualTo(newSpeed)
325+
assertThat(context.currentMaxSpeed).isEqualTo(newSpeed)
326326
}
327327

328328
@Test
@@ -332,10 +332,10 @@ class DefaultContextTest {
332332
val newLength = 500.0
333333

334334
// Act
335-
context.setCurrentTrackLength(newLength)
335+
context.currentTrackLength = newLength
336336

337337
// Assert
338-
assertThat(context.getCurrentTrackLength()).isEqualTo(newLength)
338+
assertThat(context.currentTrackLength).isEqualTo(newLength)
339339
}
340340

341341
@Test
@@ -345,10 +345,10 @@ class DefaultContextTest {
345345
val name = "Test Network"
346346

347347
// Act
348-
context.setCurrentNameString(name)
348+
context.currentNameString = name
349349

350350
// Assert
351-
assertThat(context.getCurrentNameString()).isEqualTo(name)
351+
assertThat(context.currentNameString).isEqualTo(name)
352352
}
353353
}
354354

0 commit comments

Comments
 (0)