Skip to content

Commit 409a43e

Browse files
authoredJan 4, 2025
MINOR: Collection/Option usage simplification via methods introduced in Java 9 & 11 (#18305)
Relevant methods: 1. `List.of`, `Set.of`, `Map.of` and similar (introduced in Java 9) 2. Optional: `isEmpty` (introduced in Java 11), `stream` (introduced in Java 9). Reviewers: Mickael Maison <mimaison@users.noreply.github.com>
1 parent ca511cd commit 409a43e

File tree

87 files changed

+194
-271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+194
-271
lines changed
 

‎clients/src/main/java/org/apache/kafka/clients/NetworkClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ public long maybeUpdate(long now) {
12191219
return metadataTimeout;
12201220
}
12211221

1222-
if (!metadataAttemptStartMs.isPresent())
1222+
if (metadataAttemptStartMs.isEmpty())
12231223
metadataAttemptStartMs = Optional.of(now);
12241224

12251225
// Beware that the behavior of this method and the computation of timeouts for poll() are
@@ -1412,7 +1412,7 @@ private long maybeUpdate(long now, Node node) {
14121412
if (canSendRequest(nodeConnectionId, now)) {
14131413
Optional<AbstractRequest.Builder<?>> requestOpt = clientTelemetrySender.createRequest();
14141414

1415-
if (!requestOpt.isPresent())
1415+
if (requestOpt.isEmpty())
14161416
return Long.MAX_VALUE;
14171417

14181418
AbstractRequest.Builder<?> request = requestOpt.get();

‎clients/src/main/java/org/apache/kafka/common/Uuid.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
2222
import java.util.Base64;
23-
import java.util.Collections;
24-
import java.util.HashSet;
2523
import java.util.List;
2624
import java.util.Set;
2725

@@ -51,11 +49,7 @@ public class Uuid implements Comparable<Uuid> {
5149
/**
5250
* The set of reserved UUIDs that will never be returned by the randomUuid method.
5351
*/
54-
public static final Set<Uuid> RESERVED = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
55-
METADATA_TOPIC_ID,
56-
ZERO_UUID,
57-
ONE_UUID
58-
)));
52+
public static final Set<Uuid> RESERVED = Set.of(ZERO_UUID, ONE_UUID);
5953

6054
private final long mostSignificantBits;
6155
private final long leastSignificantBits;

0 commit comments

Comments
 (0)