Skip to content

Commit 6b4f989

Browse files
committed
refactor(liveobjects): delegate no-arg counter mutators to their Number overloads
The parameterless increment()/decrement() on both DefaultLiveCounterPathObject and DefaultLiveCounterInstance duplicated the full body of their Number counterparts with a hardcoded 1. Make them delegate to increment(1)/decrement(1) instead. All spec checks live in the parameterized overload, and the default-of-1 spec points (RTPO17a1/RTPO18a1, RTINS14a1/RTINS15a1) are preserved on the delegating methods. Pure refactor, no behaviour change.
1 parent 4a939ca commit 6b4f989

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

liveobjects/src/main/kotlin/io/ably/lib/liveobjects/instance/types/DefaultLiveCounterInstance.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,16 @@ internal class DefaultLiveCounterInstance(
3636
return counter.value() // RTINS4b via RTLC5c; RTTS10b non-null
3737
}
3838

39-
override fun increment(): CompletableFuture<Void> {
40-
channelObject.throwIfInvalidWriteApiConfiguration() // RTINS14b
41-
return channelObject.asyncVoidApi { counter.increment(1) } // RTINS14a1 default, RTINS14c -> RTLC12
42-
}
39+
// RTINS14a1 - default amount of 1; delegates to increment(Number)
40+
override fun increment(): CompletableFuture<Void> = increment(1)
4341

4442
override fun increment(amount: Number): CompletableFuture<Void> {
4543
channelObject.throwIfInvalidWriteApiConfiguration() // RTINS14b
4644
return channelObject.asyncVoidApi { counter.increment(amount) } // RTINS14c -> RTLC12
4745
}
4846

49-
override fun decrement(): CompletableFuture<Void> {
50-
channelObject.throwIfInvalidWriteApiConfiguration() // RTINS15b
51-
return channelObject.asyncVoidApi { counter.decrement(1) } // RTINS15a1 default, RTINS15c -> RTLC13
52-
}
47+
// RTINS15a1 - default amount of 1; delegates to decrement(Number)
48+
override fun decrement(): CompletableFuture<Void> = decrement(1)
5349

5450
override fun decrement(amount: Number): CompletableFuture<Void> {
5551
channelObject.throwIfInvalidWriteApiConfiguration() // RTINS15b

liveobjects/src/main/kotlin/io/ably/lib/liveobjects/path/types/DefaultLiveCounterPathObject.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@ internal class DefaultLiveCounterPathObject(
2727
return counter.value() // RTPO7c via RTLC5c
2828
}
2929

30-
override fun increment(): CompletableFuture<Void> {
31-
channelObject.throwIfInvalidWriteApiConfiguration() // RTPO17b / RTO26
32-
val resolvedValue = resolveValueAtCurrentPath() ?: throw pathNotResolvedError(path) // RTPO17c / RTPO3c2
33-
if (resolvedValue !is ResolvedValue.CounterRef) {
34-
throw typeMismatchError("Cannot increment a non-LiveCounter object at path: \"$path\"") // RTPO17e
35-
}
36-
return channelObject.asyncVoidApi { resolvedValue.counter.increment(1) } // RTPO17a1 default, RTPO17d -> RTLC12
37-
}
30+
// RTPO17a1 - default amount of 1; delegates to increment(Number)
31+
override fun increment(): CompletableFuture<Void> = increment(1)
3832

3933
override fun increment(amount: Number): CompletableFuture<Void> {
4034
channelObject.throwIfInvalidWriteApiConfiguration() // RTPO17b / RTO26
@@ -45,14 +39,8 @@ internal class DefaultLiveCounterPathObject(
4539
return channelObject.asyncVoidApi { resolvedValue.counter.increment(amount) } // RTPO17d -> RTLC12
4640
}
4741

48-
override fun decrement(): CompletableFuture<Void> {
49-
channelObject.throwIfInvalidWriteApiConfiguration() // RTPO18b / RTO26
50-
val resolvedValue = resolveValueAtCurrentPath() ?: throw pathNotResolvedError(path) // RTPO18c / RTPO3c2
51-
if (resolvedValue !is ResolvedValue.CounterRef) {
52-
throw typeMismatchError("Cannot decrement a non-LiveCounter object at path: \"$path\"") // RTPO18e
53-
}
54-
return channelObject.asyncVoidApi { resolvedValue.counter.decrement(1) } // RTPO18a1 default, RTPO18d -> RTLC13
55-
}
42+
// RTPO18a1 - default amount of 1; delegates to decrement(Number)
43+
override fun decrement(): CompletableFuture<Void> = decrement(1)
5644

5745
override fun decrement(amount: Number): CompletableFuture<Void> {
5846
channelObject.throwIfInvalidWriteApiConfiguration() // RTPO18b / RTO26

0 commit comments

Comments
 (0)