You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/10/20 15:52:54 UTC

[GitHub] [kafka] Fleshgrinder commented on a change in pull request #9369: KAFKA-4715: Ignore case of CompressionType and OffsetResetStrategy

Fleshgrinder commented on a change in pull request #9369:
URL: https://github.com/apache/kafka/pull/9369#discussion_r508639180



##########
File path: clients/src/main/java/org/apache/kafka/clients/consumer/OffsetResetStrategy.java
##########
@@ -16,6 +16,40 @@
  */
 package org.apache.kafka.clients.consumer;
 
+import java.util.Locale;
+import java.util.Objects;
+
+/**
+ * @see ConsumerConfig#AUTO_OFFSET_RESET_CONFIG
+ * @see ConsumerConfig#AUTO_OFFSET_RESET_DOC
+ */
 public enum OffsetResetStrategy {
-    LATEST, EARLIEST, NONE
+    LATEST, EARLIEST, NONE;
+
+    // Enums are singletons, this means that this conversion happens once the
+    // first time a variant is actually used, and never again.
+    private final String id = name().toLowerCase(Locale.ROOT);

Review comment:
       We can move the code to `toString` but than the `toLowerCase` conversion is executed every time `toString` is invoked. This way the conversion happens once: the first time the enum is used. From there on out the string stays and never needs to be recomputed. Meaning:
   
   ```java
   System.out.println(OffsetResetStrategy.LATEST); // first access, `id` member is populated with `toLowerCase` result
   System.out.println(OffsetResetStrategy.LATEST); // just uses `id`
   System.out.println(OffsetResetStrategy.LATEST); // just uses `id`
   System.out.println(OffsetResetStrategy.LATEST); // just uses `id`
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org