avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject [08/36] avro git commit: [fix] remove @author from javadoc, add some useful comment instead, reformat file to 2 space indentation
Date Fri, 19 May 2017 17:12:22 GMT
[fix] remove @author from javadoc, add some useful comment instead, reformat file to 2 space
indentation

Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/1158152d
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/1158152d
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/1158152d

Branch: refs/heads/master
Commit: 1158152de6debcf8e5a532585a68a39ab64d78ed
Parents: ce16a3f
Author: Zoltan Farkas <zolyfarkas@yahoo.com>
Authored: Mon Apr 4 11:33:13 2016 -0400
Committer: Zoltan Farkas <zolyfarkas@yahoo.com>
Committed: Mon Apr 4 11:33:13 2016 -0400

----------------------------------------------------------------------
 .../avro/compiler/idl/SchemaResolver.java       | 357 +++++++++----------
 1 file changed, 176 insertions(+), 181 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/1158152d/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java
----------------------------------------------------------------------
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java
b/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java
index df0c7ac..9dabdd4 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/SchemaResolver.java
@@ -28,202 +28,197 @@ import org.apache.avro.Schema;
 import org.codehaus.jackson.JsonNode;
 
 /**
- *
- * @author zoly
+ * Utility class to resolve schemas that are unavailable at the time they are referenced
in the IDL.
  */
+
 final class SchemaResolver {
 
-    private SchemaResolver() { }
+  private SchemaResolver() {
+  }
 
-    private static final String UR_SCHEMA_ATTR = "org.apache.avro.compiler.idl.unresolved.name";
+  private static final String UR_SCHEMA_ATTR = "org.apache.avro.compiler.idl.unresolved.name";
 
-    static Schema unresolvedSchema(final String name) {
-        Schema schema = Schema.createRecord("UnresolvedSchema", "unresolved schema",
-                "org.apache.avro.compiler", false, Collections.EMPTY_LIST);
-        schema.addProp(UR_SCHEMA_ATTR, name);
-        return schema;
-    }
+  static Schema unresolvedSchema(final String name) {
+    Schema schema = Schema.createRecord("UnresolvedSchema", "unresolved schema",
+            "org.apache.avro.compiler", false, Collections.EMPTY_LIST);
+    schema.addProp(UR_SCHEMA_ATTR, name);
+    return schema;
+  }
 
-    static boolean isUnresolvedSchema(final Schema schema) {
-        return (schema.getType() == Schema.Type.RECORD && schema.getProp(UR_SCHEMA_ATTR)
!= null);
-    }
+  static boolean isUnresolvedSchema(final Schema schema) {
+    return (schema.getType() == Schema.Type.RECORD && schema.getProp(UR_SCHEMA_ATTR)
!= null);
+  }
 
-    static String getUnresolvedSchemaName(final Schema schema) {
-        String name = schema.getProp(UR_SCHEMA_ATTR);
-        if (name == null) {
-            throw new IllegalArgumentException("Schema " + schema + " is not a unresolved
schema");
-        } else {
-            return name;
-        }
+  static String getUnresolvedSchemaName(final Schema schema) {
+    String name = schema.getProp(UR_SCHEMA_ATTR);
+    if (name == null) {
+      throw new IllegalArgumentException("Schema " + schema + " is not a unresolved schema");
+    } else {
+      return name;
     }
-
-
-
-    static Protocol resolve(final Protocol protocol) {
-        Protocol result = new Protocol(protocol.getName(), protocol.getDoc(), protocol.getNamespace());
-        final Collection<Schema> types = protocol.getTypes();
-        List<Schema> newSchemas = new ArrayList(types.size());
-        Map<String, Schema> processed =  new HashMap<String, Schema>();
-        for (Schema schema : types) {
-            newSchemas.add(resolve(schema, protocol, processed));
-        }
-        result.setTypes(newSchemas);
-
-        for (Map.Entry<String, Protocol.Message> entry : protocol.getMessages().entrySet())
{
-            Protocol.Message value = entry.getValue();
-            Protocol.Message nvalue;
-            if (value.isOneWay()) {
-                Schema request = value.getRequest();
-                nvalue = result.createMessage(value.getName(), value.getDoc(),
-                        value.getObjectProps(), intern(request, processed));
-            } else {
-                Schema request = value.getRequest();
-                Schema response = value.getResponse();
-                Schema errors = value.getErrors();
-                nvalue = result.createMessage(value.getName(), value.getDoc(),
-                        value.getObjectProps(), intern(request, processed),
-                        intern(response, processed), intern(errors, processed));
-            }
-            result.getMessages().put(entry.getKey(), nvalue);
-        }
-        copyProps(protocol, result);
-        return result;
+  }
+
+  static Protocol resolve(final Protocol protocol) {
+    Protocol result = new Protocol(protocol.getName(), protocol.getDoc(), protocol.getNamespace());
+    final Collection<Schema> types = protocol.getTypes();
+    List<Schema> newSchemas = new ArrayList(types.size());
+    Map<String, Schema> processed = new HashMap<String, Schema>();
+    for (Schema schema : types) {
+      newSchemas.add(resolve(schema, protocol, processed));
     }
-
-    private static void copyProps(final JsonProperties from, final JsonProperties to) {
-        for (Map.Entry<String, JsonNode> entry : from.getJsonProps().entrySet()) {
-            to.addProp(entry.getKey(), entry.getValue());
-        }
+    result.setTypes(newSchemas);
+
+    for (Map.Entry<String, Protocol.Message> entry : protocol.getMessages().entrySet())
{
+      Protocol.Message value = entry.getValue();
+      Protocol.Message nvalue;
+      if (value.isOneWay()) {
+        Schema request = value.getRequest();
+        nvalue = result.createMessage(value.getName(), value.getDoc(),
+                value.getObjectProps(), intern(request, processed));
+      } else {
+        Schema request = value.getRequest();
+        Schema response = value.getResponse();
+        Schema errors = value.getErrors();
+        nvalue = result.createMessage(value.getName(), value.getDoc(),
+                value.getObjectProps(), intern(request, processed),
+                intern(response, processed), intern(errors, processed));
+      }
+      result.getMessages().put(entry.getKey(), nvalue);
     }
+    copyProps(protocol, result);
+    return result;
+  }
 
-
-    static Schema resolve(final Schema schema, final Protocol protocol, final Map<String,
Schema> processed) {
-        final String fullName = schema.getFullName();
-        if (fullName != null && processed.containsKey(fullName)) {
-            return processed.get(schema.getFullName());
-        } else if (isUnresolvedSchema(schema)) {
-            final String unresolvedSchemaName = getUnresolvedSchemaName(schema);
-            Schema type = protocol.getType(unresolvedSchemaName);
-            if (type == null) {
-                throw new IllegalArgumentException("Cannot resolve " + unresolvedSchemaName);
-            }
-            return resolve(type, protocol, processed);
-        } else {
-            switch (schema.getType()) {
-                case RECORD:
-                    Schema createRecord = Schema.createRecord(schema.getName(), schema.getDoc(),
schema.getNamespace(),
-                    schema.isError());
-                    processed.put(schema.getFullName(), createRecord);
-                    final List<Schema.Field> currFields = schema.getFields();
-                    List<Schema.Field> newFields = new ArrayList<Schema.Field>(currFields.size());
-                    for (Schema.Field field : currFields) {
-                        Schema.Field nf = new Schema.Field(field.name(), resolve(field.schema(),
protocol, processed),
-                                field.doc(), field.defaultVal(), field.order());
-                        for (String alias : field.aliases()) {
-                            nf.addAlias(alias);
-                        }
-                        newFields.add(nf);
-                    }
-                    createRecord.setFields(newFields);
-                    final LogicalType lt = schema.getLogicalType();
-                    if (lt != null) {
-                        lt.addToSchema(createRecord);
-                    }
-                    copyProps(schema, createRecord);
-                    return createRecord;
-                case MAP:
-                    Schema result = Schema.createMap(resolve(schema.getValueType(), protocol,
processed));
-                    copyProps(schema, result);
-                    return result;
-                case ARRAY:
-                    Schema aresult = Schema.createArray(resolve(schema.getElementType(),
protocol, processed));
-                    copyProps(schema, aresult);
-                    return aresult;
-                case UNION:
-                    final List<Schema> uTypes = schema.getTypes();
-                    List<Schema> newTypes = new ArrayList<Schema>(uTypes.size());
-                    for (Schema s : uTypes) {
-                        newTypes.add(resolve(s, protocol, processed));
-                    }
-                    Schema bresult =  Schema.createUnion(newTypes);
-                    copyProps(schema, bresult);
-                    return bresult;
-                case ENUM:
-                case FIXED:
-                case STRING:
-                case BYTES:
-                case INT:
-                case LONG:
-                case FLOAT:
-                case DOUBLE:
-                case BOOLEAN:
-                case NULL:
-                    return schema;
-                default:
-                    throw new RuntimeException("Unknown type: " + schema);
+  private static void copyProps(final JsonProperties from, final JsonProperties to) {
+    for (Map.Entry<String, JsonNode> entry : from.getJsonProps().entrySet()) {
+      to.addProp(entry.getKey(), entry.getValue());
+    }
+  }
+
+  static Schema resolve(final Schema schema, final Protocol protocol, final Map<String,
Schema> processed) {
+    final String fullName = schema.getFullName();
+    if (fullName != null && processed.containsKey(fullName)) {
+      return processed.get(schema.getFullName());
+    } else if (isUnresolvedSchema(schema)) {
+      final String unresolvedSchemaName = getUnresolvedSchemaName(schema);
+      Schema type = protocol.getType(unresolvedSchemaName);
+      if (type == null) {
+        throw new IllegalArgumentException("Cannot resolve " + unresolvedSchemaName);
+      }
+      return resolve(type, protocol, processed);
+    } else {
+      switch (schema.getType()) {
+        case RECORD:
+          Schema createRecord = Schema.createRecord(schema.getName(), schema.getDoc(), schema.getNamespace(),
+                  schema.isError());
+          processed.put(schema.getFullName(), createRecord);
+          final List<Schema.Field> currFields = schema.getFields();
+          List<Schema.Field> newFields = new ArrayList<Schema.Field>(currFields.size());
+          for (Schema.Field field : currFields) {
+            Schema.Field nf = new Schema.Field(field.name(), resolve(field.schema(), protocol,
processed),
+                    field.doc(), field.defaultVal(), field.order());
+            for (String alias : field.aliases()) {
+              nf.addAlias(alias);
             }
-        }
+            newFields.add(nf);
+          }
+          createRecord.setFields(newFields);
+          final LogicalType lt = schema.getLogicalType();
+          if (lt != null) {
+            lt.addToSchema(createRecord);
+          }
+          copyProps(schema, createRecord);
+          return createRecord;
+        case MAP:
+          Schema result = Schema.createMap(resolve(schema.getValueType(), protocol, processed));
+          copyProps(schema, result);
+          return result;
+        case ARRAY:
+          Schema aresult = Schema.createArray(resolve(schema.getElementType(), protocol,
processed));
+          copyProps(schema, aresult);
+          return aresult;
+        case UNION:
+          final List<Schema> uTypes = schema.getTypes();
+          List<Schema> newTypes = new ArrayList<Schema>(uTypes.size());
+          for (Schema s : uTypes) {
+            newTypes.add(resolve(s, protocol, processed));
+          }
+          Schema bresult = Schema.createUnion(newTypes);
+          copyProps(schema, bresult);
+          return bresult;
+        case ENUM:
+        case FIXED:
+        case STRING:
+        case BYTES:
+        case INT:
+        case LONG:
+        case FLOAT:
+        case DOUBLE:
+        case BOOLEAN:
+        case NULL:
+          return schema;
+        default:
+          throw new RuntimeException("Unknown type: " + schema);
+      }
     }
+  }
 
-    public static Schema intern(final Schema schema, final Map<String, Schema> processed)
{
-        if (schema == null) {
-            return null;
-        }
-        final String fullName = schema.getFullName();
-        if (fullName != null && processed.containsKey(fullName)) {
-            return processed.get(schema.getFullName());
-        } else {
-            switch (schema.getType()) {
-                case RECORD:
-                    Schema createRecord = Schema.createRecord(schema.getName(), schema.getDoc(),
schema.getNamespace(),
-                    schema.isError());
-                    processed.put(schema.getFullName(), createRecord);
-                    final List<Schema.Field> currFields = schema.getFields();
-                    List<Schema.Field> newFields = new ArrayList<Schema.Field>(currFields.size());
-                    for (Schema.Field field : currFields) {
-                        Schema.Field nf = new Schema.Field(field.name(), intern(field.schema(),
processed),
-                                field.doc(), field.defaultVal(), field.order());
-                        for (String alias : field.aliases()) {
-                            nf.addAlias(alias);
-                        }
-                        newFields.add(nf);
-                    }
-                    createRecord.setFields(newFields);
-                    final LogicalType lt = schema.getLogicalType();
-                    if (lt != null) {
-                        lt.addToSchema(createRecord);
-                    }
-                    copyProps(schema, createRecord);
-                    return createRecord;
-                case MAP:
-                    return Schema.createMap(intern(schema.getValueType(), processed));
-                case ARRAY:
-                    return Schema.createArray(intern(schema.getElementType(), processed));
-                case UNION:
-                    final List<Schema> uTypes = schema.getTypes();
-                    List<Schema> newTypes = new ArrayList<Schema>(uTypes.size());
-                    for (Schema s : uTypes) {
-                        newTypes.add(intern(s, processed));
-                    }
-                    return Schema.createUnion(newTypes);
-                case ENUM:
-                case FIXED:
-                case STRING:
-                case BYTES:
-                case INT:
-                case LONG:
-                case FLOAT:
-                case DOUBLE:
-                case BOOLEAN:
-                case NULL:
-                    return schema;
-                default:
-                    throw new RuntimeException("Unknown type: " + schema);
+  public static Schema intern(final Schema schema, final Map<String, Schema> processed)
{
+    if (schema == null) {
+      return null;
+    }
+    final String fullName = schema.getFullName();
+    if (fullName != null && processed.containsKey(fullName)) {
+      return processed.get(schema.getFullName());
+    } else {
+      switch (schema.getType()) {
+        case RECORD:
+          Schema createRecord = Schema.createRecord(schema.getName(), schema.getDoc(), schema.getNamespace(),
+                  schema.isError());
+          processed.put(schema.getFullName(), createRecord);
+          final List<Schema.Field> currFields = schema.getFields();
+          List<Schema.Field> newFields = new ArrayList<Schema.Field>(currFields.size());
+          for (Schema.Field field : currFields) {
+            Schema.Field nf = new Schema.Field(field.name(), intern(field.schema(), processed),
+                    field.doc(), field.defaultVal(), field.order());
+            for (String alias : field.aliases()) {
+              nf.addAlias(alias);
             }
-        }
+            newFields.add(nf);
+          }
+          createRecord.setFields(newFields);
+          final LogicalType lt = schema.getLogicalType();
+          if (lt != null) {
+            lt.addToSchema(createRecord);
+          }
+          copyProps(schema, createRecord);
+          return createRecord;
+        case MAP:
+          return Schema.createMap(intern(schema.getValueType(), processed));
+        case ARRAY:
+          return Schema.createArray(intern(schema.getElementType(), processed));
+        case UNION:
+          final List<Schema> uTypes = schema.getTypes();
+          List<Schema> newTypes = new ArrayList<Schema>(uTypes.size());
+          for (Schema s : uTypes) {
+            newTypes.add(intern(s, processed));
+          }
+          return Schema.createUnion(newTypes);
+        case ENUM:
+        case FIXED:
+        case STRING:
+        case BYTES:
+        case INT:
+        case LONG:
+        case FLOAT:
+        case DOUBLE:
+        case BOOLEAN:
+        case NULL:
+          return schema;
+        default:
+          throw new RuntimeException("Unknown type: " + schema);
+      }
     }
-
-
-
+  }
 
 }


Mime
View raw message