Skip to content

Commit 0a108a1

Browse files
committed
1. Added jetbrains-annoations dependency to clearly define interface methods
2. Added internet connectivity check to test setup
1 parent c435f5d commit 0a108a1

14 files changed

Lines changed: 127 additions & 49 deletions

File tree

android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ android {
5151
dependencies {
5252
api(libs.gson)
5353
implementation(libs.bundles.common)
54+
compileOnly(libs.jetbrains)
5455
testImplementation(libs.bundles.tests)
5556
implementation(project(":network-client-core"))
5657
runtimeOnly(project(":network-client-default"))

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ test-retry = "1.6.0"
2222
kotlin = "2.1.10"
2323
coroutine = "1.9.0"
2424
turbine = "1.2.0"
25+
jetbrains-annoations = "26.0.2"
2526

2627
[libraries]
2728
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
@@ -47,6 +48,7 @@ okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhtt
4748
coroutine-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutine" }
4849
coroutine-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutine" }
4950
turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
51+
jetbrains = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annoations" }
5052

5153
[bundles]
5254
common = ["msgpack", "vcdiff-core"]

java/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tasks.withType<Jar> {
2020
dependencies {
2121
api(libs.gson)
2222
implementation(libs.bundles.common)
23+
compileOnly(libs.jetbrains)
2324
implementation(project(":network-client-core"))
2425
if (findProperty("okhttp") == null) {
2526
runtimeOnly(project(":network-client-default"))

lib/src/main/java/io/ably/lib/objects/LiveCounter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.ably.lib.objects;
22

33
import io.ably.lib.types.Callback;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Contract;
46

57
/**
68
* The LiveCounter interface provides methods to interact with a live counter.
@@ -19,7 +21,7 @@ public interface LiveCounter {
1921
*
2022
* @param callback the callback to be invoked upon completion of the operation.
2123
*/
22-
void incrementAsync(Callback<Void> callback);
24+
void incrementAsync(@NotNull Callback<Void> callback);
2325

2426
/**
2527
* Decrements the value of the counter by 1.
@@ -31,12 +33,14 @@ public interface LiveCounter {
3133
*
3234
* @param callback the callback to be invoked upon completion of the operation.
3335
*/
34-
void decrementAsync(Callback<Void> callback);
36+
void decrementAsync(@NotNull Callback<Void> callback);
3537

3638
/**
3739
* Retrieves the current value of the counter.
3840
*
3941
* @return the current value of the counter as a Long.
4042
*/
43+
@NotNull
44+
@Contract(pure = true) // Indicates this method does not modify the state of the object.
4145
Long value();
4246
}

lib/src/main/java/io/ably/lib/objects/LiveMap.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package io.ably.lib.objects;
22

33
import io.ably.lib.types.Callback;
4+
import org.jetbrains.annotations.Contract;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.jetbrains.annotations.Nullable;
7+
import org.jetbrains.annotations.Unmodifiable;
48

59
import java.util.Map;
610

@@ -16,27 +20,34 @@ public interface LiveMap {
1620
* @param keyName the key whose associated value is to be returned.
1721
* @return the value associated with the specified key, or null if the key does not exist.
1822
*/
19-
Object get(String keyName);
23+
@Nullable
24+
Object get(@NotNull String keyName);
2025

2126
/**
2227
* Retrieves all entries (key-value pairs) in the map.
2328
*
2429
* @return an iterable collection of all entries in the map.
2530
*/
31+
@NotNull
32+
@Unmodifiable
2633
Iterable<Map.Entry<String, Object>> entries();
2734

2835
/**
2936
* Retrieves all keys in the map.
3037
*
3138
* @return an iterable collection of all keys in the map.
3239
*/
40+
@NotNull
41+
@Unmodifiable
3342
Iterable<String> keys();
3443

3544
/**
3645
* Retrieves all values in the map.
3746
*
3847
* @return an iterable collection of all values in the map.
3948
*/
49+
@NotNull
50+
@Unmodifiable
4051
Iterable<Object> values();
4152

4253
/**
@@ -45,21 +56,22 @@ public interface LiveMap {
4556
* @param keyName the key to be set.
4657
* @param value the value to be associated with the key.
4758
*/
48-
void set(String keyName, Object value);
59+
void set(@NotNull String keyName, @NotNull Object value);
4960

5061
/**
5162
* Removes the specified key and its associated value from the map.
5263
*
5364
* @param keyName the key to be removed.
54-
* @param value the value associated with the key to be removed.
5565
*/
56-
void remove(String keyName, Object value);
66+
void remove(@NotNull String keyName);
5767

5868
/**
5969
* Retrieves the number of entries in the map.
6070
*
6171
* @return the size of the map.
6272
*/
73+
@Contract(pure = true) // Indicates this method does not modify the state of the object.
74+
@NotNull
6375
Long size();
6476

6577
/**
@@ -69,14 +81,13 @@ public interface LiveMap {
6981
* @param value the value to be associated with the key.
7082
* @param callback the callback to handle the result or any errors.
7183
*/
72-
void setAsync(String keyName, Object value, Callback<Void> callback);
84+
void setAsync(@NotNull String keyName, @NotNull Object value, @NotNull Callback<Void> callback);
7385

7486
/**
7587
* Asynchronously removes the specified key and its associated value from the map.
7688
*
77-
* @param keyName the key to be removed.
78-
* @param value the value associated with the key to be removed.
89+
* @param keyName the key to be removed.
7990
* @param callback the callback to handle the result or any errors.
8091
*/
81-
void removeAsync(String keyName, Object value, Callback<Void> callback);
92+
void removeAsync(@NotNull String keyName, @NotNull Callback<Void> callback);
8293
}

lib/src/main/java/io/ably/lib/objects/LiveObjects.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
import io.ably.lib.objects.batch.BatchContextBuilder;
44
import io.ably.lib.types.Callback;
5+
import org.jetbrains.annotations.NotNull;
6+
57

68
import java.util.Map;
79

810
/**
911
* The LiveObjects interface provides methods to interact with live data objects,
1012
* such as maps and counters, in a real-time environment. It supports both synchronous
1113
* and asynchronous operations for retrieving and creating live objects.
14+
*
15+
* <p>Implementations of this interface must be thread-safe as they may be accessed
16+
* from multiple threads concurrently.
1217
*/
1318
public interface LiveObjects {
1419

@@ -17,91 +22,96 @@ public interface LiveObjects {
1722
*
1823
* @return the root LiveMap instance.
1924
*/
25+
@NotNull
2026
LiveMap getRoot();
2127

2228
/**
2329
* Initiates a batch operation and provides a BatchContext through a callback.
2430
*
25-
* @param batchContextCallback the callback to handle the BatchContext or error.
31+
* @param batchContextCallback the builder to configure the batch operation.
2632
*/
27-
void batch(BatchContextBuilder batchContextCallback);
33+
void batch(@NotNull BatchContextBuilder batchContextCallback);
2834

2935
/**
3036
* Creates a new LiveMap based on an existing LiveMap.
3137
*
3238
* @param liveMap the existing LiveMap to base the new LiveMap on.
3339
* @return the newly created LiveMap instance.
3440
*/
35-
LiveMap createMap(LiveMap liveMap);
41+
@NotNull
42+
LiveMap createMap(@NotNull LiveMap liveMap);
3643

3744
/**
3845
* Creates a new LiveMap based on a LiveCounter.
3946
*
4047
* @param liveCounter the LiveCounter to base the new LiveMap on.
4148
* @return the newly created LiveMap instance.
4249
*/
43-
LiveMap createMap(LiveCounter liveCounter);
50+
@NotNull
51+
LiveMap createMap(@NotNull LiveCounter liveCounter);
4452

4553
/**
4654
* Creates a new LiveMap based on a standard Java Map.
4755
*
4856
* @param map the Java Map to base the new LiveMap on.
4957
* @return the newly created LiveMap instance.
5058
*/
51-
LiveMap createMap(Map<String, Object> map);
59+
@NotNull
60+
LiveMap createMap(@NotNull Map<String, Object> map);
5261

5362
/**
5463
* Creates a new LiveCounter with an initial value.
5564
*
5665
* @param initialValue the initial value of the LiveCounter.
5766
* @return the newly created LiveCounter instance.
5867
*/
59-
LiveCounter createCounter(Long initialValue);
68+
@NotNull
69+
LiveCounter createCounter(@NotNull Long initialValue);
6070

6171
/**
6272
* Asynchronously retrieves the root LiveMap object.
6373
*
6474
* @param callback the callback to handle the result or error.
6575
*/
66-
void getRootAsync(Callback<LiveMap> callback);
76+
void getRootAsync(@NotNull Callback<@NotNull LiveMap> callback);
6777

6878
/**
6979
* Initiates a batch operation asynchronously.
7080
*
71-
* @param batchContextCallback the BatchContextBuilder to build the BatchContext.
81+
* @param batchContextCallback the builder to configure the batch operation.
7282
* @param callback the Callback to handle the completion or error of the batch operation.
7383
*/
74-
void batchAsync(BatchContextBuilder batchContextCallback, Callback<Void> callback);
84+
void batchAsync(@NotNull BatchContextBuilder batchContextCallback, @NotNull Callback<Void> callback);
7585

7686
/**
7787
* Asynchronously creates a new LiveMap based on an existing LiveMap.
7888
*
7989
* @param liveMap the existing LiveMap to base the new LiveMap on.
8090
* @param callback the callback to handle the result or error.
8191
*/
82-
void createMapAsync(LiveMap liveMap, Callback<LiveMap> callback);
92+
void createMapAsync(@NotNull LiveMap liveMap, @NotNull Callback<@NotNull LiveMap> callback);
8393

8494
/**
8595
* Asynchronously creates a new LiveMap based on a LiveCounter.
8696
*
8797
* @param liveCounter the LiveCounter to base the new LiveMap on.
8898
* @param callback the callback to handle the result or error.
8999
*/
90-
void createMapAsync(LiveCounter liveCounter, Callback<LiveMap> callback);
100+
void createMapAsync(@NotNull LiveCounter liveCounter, @NotNull Callback<@NotNull LiveMap> callback);
91101

92102
/**
93103
* Asynchronously creates a new LiveMap based on a standard Java Map.
94104
*
95105
* @param map the Java Map to base the new LiveMap on.
96106
* @param callback the callback to handle the result or error.
97107
*/
98-
void createMapAsync(Map<String, Object> map, Callback<LiveMap> callback);
108+
void createMapAsync(@NotNull Map<String, Object> map, @NotNull Callback<@NotNull LiveMap> callback);
99109

100110
/**
101111
* Asynchronously creates a new LiveCounter with an initial value.
102112
*
103113
* @param initialValue the initial value of the LiveCounter.
104114
* @param callback the callback to handle the result or error.
105115
*/
106-
void createCounterAsync(Long initialValue, Callback<LiveCounter> callback);
116+
void createCounterAsync(@NotNull Long initialValue, @NotNull Callback<@NotNull LiveCounter> callback);
107117
}

lib/src/main/java/io/ably/lib/objects/LiveObjectsPlugin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.ably.lib.objects;
22

3+
import org.jetbrains.annotations.NotNull;
4+
35
/**
46
* The LiveObjectsPlugin interface provides a mechanism to retrieve instances of LiveObjects
57
* associated with specific channel names. This allows for interaction with live data objects
@@ -13,13 +15,12 @@ public interface LiveObjectsPlugin {
1315
* @param channelName the name of the channel for which the LiveObjects instance is to be retrieved.
1416
* @return the LiveObjects instance associated with the specified channel name.
1517
*/
16-
LiveObjects getInstance(String channelName);
17-
18+
LiveObjects getInstance(@NotNull String channelName);
1819

1920
/**
2021
* Disposes of the LiveObjects instance associated with the specified channel name.
2122
*
2223
* @param channelName the name of the channel whose LiveObjects instance is to be removed.
2324
*/
24-
void dispose(String channelName);
25+
void dispose(@NotNull String channelName);
2526
}

lib/src/main/java/io/ably/lib/objects/batch/BatchContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.ably.lib.objects.batch;
22

3+
import org.jetbrains.annotations.NotNull;
34

45
/**
56
* The BatchContext interface represents the context for batch operations
@@ -13,5 +14,6 @@ public interface BatchContext {
1314
*
1415
* @return the root LiveMap instance.
1516
*/
17+
@NotNull
1618
BatchContextLiveMap getRoot();
1719
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.ably.lib.objects.batch;
22

3+
import org.jetbrains.annotations.NotNull;
4+
35
/**
4-
* A functional interface for building and handling a BatchContext.*
6+
* A functional interface for building and handling a BatchContext.
57
*/
68
@FunctionalInterface
79
public interface BatchContextBuilder {
@@ -10,5 +12,5 @@ public interface BatchContextBuilder {
1012
*
1113
* @param batchContext the BatchContext to handle.
1214
*/
13-
void build(BatchContext batchContext);
15+
void build(@NotNull BatchContext batchContext);
1416
}

0 commit comments

Comments
 (0)