Skip to content

Commit 54ae53f

Browse files
committed
- Implemented ResolvedValue class for resolving value at given path
- Marked PathObject#getValue as nullable when value doesn't exist at given path
1 parent f74ae1d commit 54ae53f

12 files changed

Lines changed: 86 additions & 26 deletions

lib/src/main/java/io/ably/lib/object/ValueType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public enum ValueType {
2323
LIVE_MAP,
2424
/** Corresponds to a {@code LiveCounter} object. Spec: RTTS2a8 */
2525
LIVE_COUNTER,
26-
/** Returned when path resolution fails or the resolved value has none of the known types; never produced by an {@code Instance} in normal operation. Spec: RTTS2a9 */
26+
/** Returned by {@code PathObject#getType()} only when a value is present but matches none of the known types. Never produced by an {@code Instance} in normal operation. Spec: RTTS2a9 */
2727
UNKNOWN,
2828
}

lib/src/main/java/io/ably/lib/object/path/PathObject.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,22 @@
4343
public interface PathObject {
4444

4545
/**
46-
* Returns the {@link ValueType} of the value resolved at this path currently.
47-
* Use this instead of dedicated {@code isLiveMap}/{@code isLiveCounter}/etc. checks.
46+
* Returns the {@link ValueType} of the value currently resolved at this path, or
47+
* {@code null} when the path does not resolve to any value. Use this instead of
48+
* dedicated {@code isLiveMap}/{@code isLiveCounter}/etc. checks.
4849
*
49-
* <p>Returns {@link ValueType#UNKNOWN} when the path does not resolve or the
50-
* resolved value falls into none of the known categories.
50+
* <p>A {@code null} result means there is no value at this path - nothing is stored
51+
* there (e.g. an absent or removed map entry). This is deliberately distinct from
52+
* {@link ValueType#UNKNOWN}, which is returned only when a value <em>is</em> present
53+
* but its type matches none of the known categories. In other words: {@code null}
54+
* means "no value", {@code UNKNOWN} means "a value of an unrecognized type".
5155
*
5256
* <p>Spec: RTTS4b
5357
*
54-
* @return the resolved value type at this path
58+
* @return the resolved value type at this path, or {@code null} if the path does
59+
* not resolve to a value
5560
*/
56-
@NotNull ValueType getType();
61+
@Nullable ValueType getType();
5762

5863
/**
5964
* Returns a dot-delimited string representation of the stored path segments.

liveobjects/src/main/kotlin/io/ably/lib/object/path/DefaultPathObject.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import io.ably.lib.`object`.path.types.LiveCounterPathObject
2222
import io.ably.lib.`object`.path.types.LiveMapPathObject
2323
import io.ably.lib.`object`.path.types.NumberPathObject
2424
import io.ably.lib.`object`.path.types.StringPathObject
25+
import io.ably.lib.`object`.value.ResolvedValue
26+
import io.ably.lib.`object`.value.valueType
2527

2628
/**
2729
* Default implementation of [PathObject], the untyped node in the path-addressed view of
@@ -35,33 +37,34 @@ import io.ably.lib.`object`.path.types.StringPathObject
3537
*/
3638
internal open class DefaultPathObject(
3739
internal val channelObject: DefaultRealtimeObject,
40+
internal val path: String
3841
) : PathObject {
3942

40-
override fun path(): String = TODO("Not yet implemented")
43+
override fun path(): String = path
4144

42-
override fun getType(): ValueType = TODO("Not yet implemented")
45+
override fun getType(): ValueType? = resolveValueAtPath(path)?.valueType()
4346

4447
override fun instance(): Instance? = TODO("Not yet implemented")
4548

4649
override fun compactJson(): JsonElement? = TODO("Not yet implemented")
4750

48-
override fun exists(): Boolean = TODO("Not yet implemented")
51+
override fun exists(): Boolean = resolveValueAtPath(path) != null
4952

50-
override fun asLiveMap(): LiveMapPathObject = DefaultLiveMapPathObject(channelObject)
53+
override fun asLiveMap(): LiveMapPathObject = DefaultLiveMapPathObject(channelObject, path)
5154

52-
override fun asLiveCounter(): LiveCounterPathObject = DefaultLiveCounterPathObject(channelObject)
55+
override fun asLiveCounter(): LiveCounterPathObject = DefaultLiveCounterPathObject(channelObject, path)
5356

54-
override fun asNumber(): NumberPathObject = DefaultNumberPathObject(channelObject)
57+
override fun asNumber(): NumberPathObject = DefaultNumberPathObject(channelObject, path)
5558

56-
override fun asString(): StringPathObject = DefaultStringPathObject(channelObject)
59+
override fun asString(): StringPathObject = DefaultStringPathObject(channelObject, path)
5760

58-
override fun asBoolean(): BooleanPathObject = DefaultBooleanPathObject(channelObject)
61+
override fun asBoolean(): BooleanPathObject = DefaultBooleanPathObject(channelObject, path)
5962

60-
override fun asBinary(): BinaryPathObject = DefaultBinaryPathObject(channelObject)
63+
override fun asBinary(): BinaryPathObject = DefaultBinaryPathObject(channelObject, path)
6164

62-
override fun asJsonObject(): JsonObjectPathObject = DefaultJsonObjectPathObject(channelObject)
65+
override fun asJsonObject(): JsonObjectPathObject = DefaultJsonObjectPathObject(channelObject, path)
6366

64-
override fun asJsonArray(): JsonArrayPathObject = DefaultJsonArrayPathObject(channelObject)
67+
override fun asJsonArray(): JsonArrayPathObject = DefaultJsonArrayPathObject(channelObject, path)
6568

6669
override fun subscribe(listener: PathObjectListener): Subscription = subscribe(listener, null)
6770

@@ -71,4 +74,9 @@ internal open class DefaultPathObject(
7174
// TODO - remove PathObjectListener from list
7275
}
7376
}
77+
78+
protected fun resolveValueAtPath(path: String): ResolvedValue? {
79+
// TODO - resolve the path against the live objects graph and return the value at that position
80+
return null
81+
}
7482
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import io.ably.lib.`object`.path.DefaultPathObject
1111
*/
1212
internal class DefaultBinaryPathObject(
1313
channelObject: DefaultRealtimeObject,
14-
) : DefaultPathObject(channelObject), BinaryPathObject {
14+
path: String,
15+
) : DefaultPathObject(channelObject, path), BinaryPathObject {
1516

1617
@Suppress("RedundantNullableReturnType")
1718
override fun value(): ByteArray? = TODO("Not yet implemented")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import io.ably.lib.`object`.path.DefaultPathObject
1111
*/
1212
internal class DefaultBooleanPathObject(
1313
channelObject: DefaultRealtimeObject,
14-
) : DefaultPathObject(channelObject), BooleanPathObject {
14+
path: String,
15+
) : DefaultPathObject(channelObject, path), BooleanPathObject {
1516

1617
@Suppress("RedundantNullableReturnType")
1718
override fun value(): Boolean? = TODO("Not yet implemented")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import io.ably.lib.`object`.path.DefaultPathObject
1212
*/
1313
internal class DefaultJsonArrayPathObject(
1414
channelObject: DefaultRealtimeObject,
15-
) : DefaultPathObject(channelObject), JsonArrayPathObject {
15+
path: String,
16+
) : DefaultPathObject(channelObject, path), JsonArrayPathObject {
1617

1718
@Suppress("RedundantNullableReturnType")
1819
override fun value(): JsonArray? = TODO("Not yet implemented")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import io.ably.lib.`object`.path.DefaultPathObject
1212
*/
1313
internal class DefaultJsonObjectPathObject(
1414
channelObject: DefaultRealtimeObject,
15-
) : DefaultPathObject(channelObject), JsonObjectPathObject {
15+
path: String,
16+
) : DefaultPathObject(channelObject, path), JsonObjectPathObject {
1617

1718
@Suppress("RedundantNullableReturnType")
1819
override fun value(): JsonObject? = TODO("Not yet implemented")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import java.util.concurrent.CompletableFuture
1414
*/
1515
internal class DefaultLiveCounterPathObject(
1616
channelObject: DefaultRealtimeObject,
17-
) : DefaultPathObject(channelObject), LiveCounterPathObject {
17+
path: String,
18+
) : DefaultPathObject(channelObject, path), LiveCounterPathObject {
1819

1920
@Suppress("RedundantNullableReturnType")
2021
override fun value(): Double? = TODO("Not yet implemented")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import java.util.concurrent.CompletableFuture
1414
*/
1515
internal class DefaultLiveMapPathObject(
1616
channelObject: DefaultRealtimeObject,
17-
) : DefaultPathObject(channelObject), LiveMapPathObject {
17+
path: String,
18+
) : DefaultPathObject(channelObject, path), LiveMapPathObject {
1819

1920
override fun get(key: String): PathObject = TODO("Not yet implemented")
2021

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import io.ably.lib.`object`.path.DefaultPathObject
1111
*/
1212
internal class DefaultNumberPathObject(
1313
channelObject: DefaultRealtimeObject,
14-
) : DefaultPathObject(channelObject), NumberPathObject {
14+
path: String,
15+
) : DefaultPathObject(channelObject, path), NumberPathObject {
1516

1617
@Suppress("RedundantNullableReturnType")
1718
override fun value(): Number? = TODO("Not yet implemented")

0 commit comments

Comments
 (0)