chia7712 commented on code in PR #19869:
URL: https://github.com/apache/kafka/pull/19869#discussion_r2192238337


##########
connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java:
##########
@@ -44,31 +42,31 @@ public class ConnectSchema implements Schema {
     private static final Map<Class<?>, Type> JAVA_CLASS_SCHEMA_TYPES = new 
HashMap<>();

Review Comment:
   Sorry for unclear comment. We used `put` to initialize 
`JAVA_CLASS_SCHEMA_TYPES`, but modern Java offers many powerful functions to 
gracefully initialize the maps as immutable. for example:
   ```java
       private static final Map<Type, List<Class<?>>> SCHEMA_TYPE_CLASSES = 
Collections.unmodifiableMap(new EnumMap<>(Map.of(
           Type.INT8, Collections.singletonList(Byte.class),
           Type.INT16, Collections.singletonList(Short.class),
           Type.INT32, Collections.singletonList(Integer.class),
           Type.INT64, Collections.singletonList(Long.class),
           Type.FLOAT32, Collections.singletonList(Float.class),
           Type.FLOAT64, Collections.singletonList(Double.class)
       )));
       /**
        * Maps known logical types to a list of Java classes that can be used 
to represent them.
        */
       private static final Map<String, List<Class<?>>> LOGICAL_TYPE_CLASSES = 
Map.of(
               Decimal.LOGICAL_NAME, Collections.singletonList(BigDecimal.class)
       );
   
       /**
        * Maps the Java classes to the corresponding {@link Schema.Type}.
        */
       private static final Map<Class<?>, Type> JAVA_CLASS_SCHEMA_TYPES = 
SCHEMA_TYPE_CLASSES.entrySet()
               .stream()
               .flatMap(entry -> entry.getValue().stream().map(klass -> 
Map.entry(klass, entry.getKey())))
               .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, 
Map.Entry::getValue));
   ```
   



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to