Skip to content

Commit 9bcae0d

Browse files
authored
Use HashMap.computeIfAbsent instead of get/put (#36990)
1 parent 1831cba commit 9bcae0d

File tree

1 file changed

+9
-5
lines changed
  • runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker

1 file changed

+9
-5
lines changed

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/WindmillSink.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,15 @@ public long add(WindowedValue<T> data) throws IOException {
264264
}
265265
}
266266

267-
Windmill.KeyedMessageBundle.Builder keyedOutput = productionMap.get(key);
268-
if (keyedOutput == null) {
269-
keyedOutput = Windmill.KeyedMessageBundle.newBuilder().setKey(key);
270-
productionMap.put(key, keyedOutput);
271-
}
267+
Windmill.KeyedMessageBundle.Builder keyedOutput =
268+
productionMap.computeIfAbsent(
269+
key,
270+
(k) -> {
271+
Windmill.KeyedMessageBundle.Builder builder =
272+
Windmill.KeyedMessageBundle.newBuilder();
273+
builder.setKey(k);
274+
return builder;
275+
});
272276

273277
try {
274278
messageBuilder

0 commit comments

Comments
 (0)