avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [avro] branch master updated: AVRO-2349: Review Usage of Arrays.asList
Date Tue, 12 Mar 2019 16:50:55 GMT
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 0e6977d  AVRO-2349: Review Usage of Arrays.asList
0e6977d is described below

commit 0e6977d1b89c9a103cec0be5bd4bbeceb740d50f
Author: Beluga Behr <dam6923@gmail.com>
AuthorDate: Mon Mar 11 17:22:58 2019 -0400

    AVRO-2349: Review Usage of Arrays.asList
---
 lang/java/avro/src/main/java/org/apache/avro/Schema.java   | 14 ++++++--------
 .../main/java/org/apache/avro/specific/SpecificData.java   |  4 ++--
 .../main/java/org/apache/avro/compiler/schema/Schemas.java |  6 +++---
 .../apache/avro/compiler/specific/SpecificCompiler.java    |  6 ++----
 .../main/java/org/apache/avro/protobuf/ProtobufData.java   |  2 +-
 .../src/main/java/org/apache/avro/thrift/ThriftData.java   |  2 +-
 6 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index a55b265..b058c2a 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -26,6 +26,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.IdentityHashMap;
@@ -124,16 +125,13 @@ public abstract class Schema extends JsonProperties {
     }
   }
 
-  private static final Set<String> SCHEMA_RESERVED = new HashSet<>();
-  static {
-    Collections.addAll(SCHEMA_RESERVED,
-                       "doc", "fields", "items", "name", "namespace",
-                       "size", "symbols", "values", "type", "aliases");
-  }
-  private static final Set<String> ENUM_RESERVED = new HashSet<>();
+  private static final Set<String> SCHEMA_RESERVED =
+      new HashSet<>(Arrays.asList("doc", "fields", "items", "name", "namespace",
+          "size", "symbols", "values", "type", "aliases"));
+
+  private static final Set<String> ENUM_RESERVED = new HashSet<>(SCHEMA_RESERVED);
   static {
     ENUM_RESERVED.add("default");
-    ENUM_RESERVED.addAll(SCHEMA_RESERVED);
   }
 
   int hashCode = NO_HASHCODE;
diff --git a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
index 3b83fe4..ddee2d9 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
@@ -80,7 +80,7 @@ public class SpecificData extends GenericData {
    * combined with the classnames used internally in the generated avro code.
    */
   public static final Set<String> RESERVED_WORDS = new HashSet<>
-    (Arrays.asList(new String[] {
+    (Arrays.asList(
         "abstract", "assert", "boolean", "break", "byte", "case", "catch",
         "char", "class", "const", "continue", "default", "do", "double",
         "else", "enum", "extends", "false", "final", "finally", "float",
@@ -91,7 +91,7 @@ public class SpecificData extends GenericData {
         "transient", "true", "try", "void", "volatile", "while",
         /* classnames use internally by the avro code generator */
         "Builder"
-      }));
+      ));
 
   /** Read/write some common builtin classes as strings.  Representing these as
    * strings isn't always best, as they aren't always ordered ideally, but at
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java
b/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java
index 29b9924..ae69c29 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java
@@ -18,7 +18,7 @@
 package org.apache.avro.compiler.schema;
 
 import java.util.ArrayDeque;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.Deque;
 import java.util.IdentityHashMap;
 import java.util.Iterator;
@@ -136,7 +136,7 @@ public final class Schemas {
           Schema.Type type = schema.getType();
           switch (type) {
             case ARRAY:
-              terminate = visitNonTerminal(visitor, schema, dq, Arrays.asList(schema.getElementType()));
+              terminate = visitNonTerminal(visitor, schema, dq, Collections.singleton(schema.getElementType()));
               visited.put(schema, schema);
               break;
             case RECORD:
@@ -151,7 +151,7 @@ public final class Schemas {
               visited.put(schema, schema);
               break;
             case MAP:
-              terminate = visitNonTerminal(visitor, schema, dq, Arrays.asList(schema.getValueType()));
+              terminate = visitNonTerminal(visitor, schema, dq, Collections.singleton(schema.getValueType()));
               visited.put(schema, schema);
               break;
             case NULL:
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index 236dba3..a6e8ae6 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -138,9 +138,7 @@ public class SpecificCompiler {
 
   /* Reserved words for accessor/mutator methods */
   private static final Set<String> ACCESSOR_MUTATOR_RESERVED_WORDS =
-      new HashSet<>(Arrays.asList(new String[]{
-            "class", "schema", "classSchema"
-          }));
+      new HashSet<>(Arrays.asList("class", "schema", "classSchema"));
   static {
     // Add reserved words to accessor/mutator reserved words
     ACCESSOR_MUTATOR_RESERVED_WORDS.addAll(RESERVED_WORDS);
@@ -148,7 +146,7 @@ public class SpecificCompiler {
 
   /* Reserved words for error types */
   private static final Set<String> ERROR_RESERVED_WORDS = new HashSet<>(
-      Arrays.asList(new String[]{"message", "cause"}));
+      Arrays.asList("message", "cause"));
   static {
     // Add accessor/mutator reserved words to error reserved words
     ERROR_RESERVED_WORDS.addAll(ACCESSOR_MUTATOR_RESERVED_WORDS);
diff --git a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
index 0bf84be..92a6d2a 100644
--- a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
+++ b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
@@ -291,7 +291,7 @@ public class ProtobufData extends GenericData {
       result = getSchema(f.getMessageType());
       if (f.isOptional())
         // wrap optional record fields in a union with null
-        result = Schema.createUnion(Arrays.asList(new Schema[] {NULL, result}));
+        result = Schema.createUnion(Arrays.asList(NULL, result));
       return result;
     case GROUP:                                   // groups are deprecated
     default:
diff --git a/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java b/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
index 654cd0f..383552f 100644
--- a/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
+++ b/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
@@ -264,7 +264,7 @@ public class ThriftData extends GenericData {
   }
 
   private Schema nullable(Schema schema) {
-    return Schema.createUnion(Arrays.asList(new Schema[] {NULL, schema}));
+    return Schema.createUnion(Arrays.asList(NULL, schema));
   }
 
 }


Mime
View raw message