absurdfarce commented on code in PR #2060:
URL:
https://github.com/apache/cassandra-java-driver/pull/2060#discussion_r2501775764
##########
core/src/main/java/com/datastax/oss/driver/api/core/tracker/RequestIdGenerator.java:
##########
@@ -67,11 +68,15 @@ default String getCustomPayloadKey() {
default Statement<?> getDecoratedStatement(
@NonNull Statement<?> statement, @NonNull String requestId) {
- Map<String, ByteBuffer> customPayload =
- NullAllowingImmutableMap.<String, ByteBuffer>builder()
- .putAll(statement.getCustomPayload())
- .put(getCustomPayloadKey(),
ByteBuffer.wrap(requestId.getBytes(StandardCharsets.UTF_8)))
- .build();
- return statement.setCustomPayload(customPayload);
+
+ Map<String, ByteBuffer> existing = new
HashMap<>(statement.getCustomPayload());
+ String key = getCustomPayloadKey();
+
+ // Add or overwrite
+ existing.put(key,
ByteBuffer.wrap(requestId.getBytes(StandardCharsets.UTF_8)));
+
+ Map<String, ByteBuffer> unmodifiableMap =
Collections.unmodifiableMap(existing);
+
+ return statement.setCustomPayload(unmodifiableMap);
Review Comment:
I don't know that I want to hold things up any but I'd argue ImmutableMap is
more concise (and avoids the need to create at least one of the intermediate
maps here):
```java
default Statement<?> getDecoratedStatement(
@NonNull Statement<?> statement, @NonNull String requestId) {
return statement.setCustomPayload(
ImmutableMap.<String,ByteBuffer>builder()
.putAll(statement.getCustomPayload())
.put(getCustomPayloadKey(),
ByteBuffer.wrap(requestId.getBytes(StandardCharsets.UTF_8)))
.buildKeepingLast());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]