Skip to content

Commit 112e5f2

Browse files
authored
Merge pull request #1169 from ably/chore-add-tostring
chore: add `toString` method in `ChannelStateChange` class for improved debugging
2 parents 44991c5 + 8d28616 commit 112e5f2

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

lib/src/main/java/io/ably/lib/realtime/ChannelStateListener.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.ably.lib.realtime;
22

33
import io.ably.lib.types.ErrorInfo;
4+
import org.jetbrains.annotations.NotNull;
45

56
/**
67
* An interface whereby a client may be notified of state changes for a channel.
@@ -69,6 +70,17 @@ private ChannelStateChange(ErrorInfo reason, boolean resumed) {
6970
static ChannelStateChange createUpdateEvent(ErrorInfo reason, boolean resumed) {
7071
return new ChannelStateChange(reason, resumed);
7172
}
73+
74+
@Override
75+
public @NotNull String toString() {
76+
return '{' +
77+
"event=" + event +
78+
", current=" + current +
79+
", previous=" + previous +
80+
", reason=" + reason +
81+
", resumed=" + resumed +
82+
'}';
83+
}
7284
}
7385

7486
class Multicaster extends io.ably.lib.util.Multicaster<ChannelStateListener> implements ChannelStateListener {

lib/src/main/java/io/ably/lib/types/Annotation.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.google.gson.JsonSerializer;
1111
import io.ably.lib.util.Log;
1212
import io.ably.lib.util.Serialisation;
13+
import org.jetbrains.annotations.NotNull;
1314
import org.msgpack.core.MessageFormat;
1415
import org.msgpack.core.MessagePacker;
1516
import org.msgpack.core.MessageUnpacker;
@@ -233,6 +234,22 @@ public Annotation deserialize(JsonElement json, Type typeOfT, JsonDeserializatio
233234
}
234235
}
235236

237+
/**
238+
* Generate a String summary of this Message
239+
* @return string
240+
*/
241+
@Override
242+
public @NotNull String toString() {
243+
StringBuilder result = new StringBuilder("{");
244+
super.getDetails(result);
245+
result.append(" name=").append(name);
246+
result.append(" serial=").append(serial);
247+
result.append(" messageSerial=").append(messageSerial);
248+
result.append(" type=").append(type);
249+
result.append('}');
250+
return result.toString();
251+
}
252+
236253
public static class ActionSerializer implements JsonSerializer<AnnotationAction>, JsonDeserializer<AnnotationAction> {
237254
@Override
238255
public AnnotationAction deserialize(JsonElement json, Type t, JsonDeserializationContext ctx)

0 commit comments

Comments
 (0)