This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 63e0210  AVRO-2350: Use Switch Statement for Strings in LogicalTypes
63e0210 is described below

commit 63e02101cf94d8ab0e1ae01baafe04c5767aa371
Author: Beluga Behr <[email protected]>
AuthorDate: Mon Mar 11 19:03:19 2019 -0400

    AVRO-2350: Use Switch Statement for Strings in LogicalTypes
---
 .../main/java/org/apache/avro/LogicalTypes.java    | 49 ++++++++++++++--------
 1 file changed, 32 insertions(+), 17 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java 
b/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
index 57dc661..d8f50e2 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
@@ -56,31 +56,46 @@ public class LogicalTypes {
     return fromSchemaImpl(schema, false);
   }
 
-  private static LogicalType fromSchemaImpl(Schema schema, boolean 
throwErrors) {
-    String typeName = schema.getProp(LogicalType.LOGICAL_TYPE_PROP);
+  private static LogicalType fromSchemaImpl(Schema schema,
+      boolean throwErrors) {
+    final LogicalType logicalType;
+    final String typeName = schema.getProp(LogicalType.LOGICAL_TYPE_PROP);
+
+    if (typeName == null) {
+      return null;
+    }
 
-    LogicalType logicalType;
     try {
-      if (typeName == null) {
-        logicalType = null;
-      } else if (TIMESTAMP_MILLIS.equals(typeName)) {
+      switch (typeName) {
+      case TIMESTAMP_MILLIS:
         logicalType = TIMESTAMP_MILLIS_TYPE;
-      } else if (DECIMAL.equals(typeName)) {
+        break;
+      case DECIMAL:
         logicalType = new Decimal(schema);
-      } else if (UUID.equals(typeName)) {
+        break;
+      case UUID:
         logicalType = UUID_TYPE;
-      } else if (DATE.equals(typeName)) {
+        break;
+      case DATE:
         logicalType = DATE_TYPE;
-      } else if (TIMESTAMP_MICROS.equals(typeName)) {
+        break;
+      case TIMESTAMP_MICROS:
         logicalType = TIMESTAMP_MICROS_TYPE;
-      } else if (TIME_MILLIS.equals(typeName)) {
+        break;
+      case TIME_MILLIS:
         logicalType = TIME_MILLIS_TYPE;
-      } else if (TIME_MICROS.equals(typeName)) {
+        break;
+      case TIME_MICROS:
         logicalType = TIME_MICROS_TYPE;
-      } else if (REGISTERED_TYPES.containsKey(typeName)) {
-        logicalType = REGISTERED_TYPES.get(typeName).fromSchema(schema);
-      } else {
-        logicalType = null;
+        break;
+      default:
+        final LogicalTypeFactory typeFactory = REGISTERED_TYPES.get(typeName);
+        if (typeFactory != null) {
+          logicalType = REGISTERED_TYPES.get(typeName).fromSchema(schema);
+        } else {
+          logicalType = null;
+        }
+        break;
       }
 
       // make sure the type is valid before returning it
@@ -94,7 +109,7 @@ public class LogicalTypes {
       }
       LOG.warn("Ignoring invalid logical type for name: {}", typeName);
       // ignore invalid types
-      logicalType = null;
+      return null;
     }
 
     return logicalType;

Reply via email to