Update the comment and catch cluases

Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/848b5bb0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/848b5bb0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/848b5bb0

Branch: refs/heads/REEF-395
Commit: 848b5bb0130276c9f7aa5174b56358dc67473628
Parents: 7a095da
Author: Yunseong Lee <[email protected]>
Authored: Sun Jun 21 15:56:31 2015 +0900
Committer: Yunseong Lee <[email protected]>
Committed: Sun Jun 21 15:56:31 2015 +0900

----------------------------------------------------------------------
 .../implementation/java/AvroClassHierarchy.java | 61 ++++++++++++--------
 1 file changed, 36 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/848b5bb0/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/AvroClassHierarchy.java
----------------------------------------------------------------------
diff --git 
a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/AvroClassHierarchy.java
 
b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/AvroClassHierarchy.java
index 96ab16c..f4f22f0 100644
--- 
a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/AvroClassHierarchy.java
+++ 
b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/AvroClassHierarchy.java
@@ -14,7 +14,6 @@ import java.util.List;
 /**
  * Implementation of ClassHierarchy for Avro
  */
-// TODO Should it be a ClassHierarchy?
 public class AvroClassHierarchy implements ClassHierarchy {
   private final PackageNode namespace;
   private final HashMap<String, Node> lookupTable = new HashMap<>();
@@ -36,6 +35,9 @@ public class AvroClassHierarchy implements ClassHierarchy {
     }
   }
 
+  /**
+   * Build a table that matches the name and the corresponding Node 
recursively.
+   */
   private void buildLookupTable(final Node n) {
     for(final Node child : n.getChildren()) {
       lookupTable.put(child.getFullName(), child);
@@ -43,24 +45,27 @@ public class AvroClassHierarchy implements ClassHierarchy {
     }
   }
 
+  /**
+   * Parse the constructor definition.
+   */
   private static ConstructorDef<?> parseConstructorDef(final 
AvroConstructorDef def, final boolean isInjectable) {
     final List<ConstructorArg> args = new ArrayList<>();
     for (final AvroConstructorArg arg : def.getConstructorArg()) {
-      final String namedParameterName = arg.getNamedParameterName() == null ? 
null : arg.getNamedParameterName();
-      args.add(new ConstructorArgImpl(arg.getFullArgClassName(), 
namedParameterName,
-              arg.getIsInjectionFuture()));
+      args.add(new ConstructorArgImpl(arg.getFullArgClassName(), 
arg.getNamedParameterName(), arg.getIsInjectionFuture()));
     }
-    return new ConstructorDefImpl<>(def.getFullArgClassName(), 
args.toArray(new ConstructorArg[0]),
-            isInjectable);
+    return new ConstructorDefImpl<>(def.getFullArgClassName(), 
args.toArray(new ConstructorArg[0]), isInjectable);
   }
 
-  private static void parseSubHierarchy(Node parent, AvroNode n) {
+  /**
+   * Register the classes recursively.
+   */
+  private static void parseSubHierarchy(final Node parent, final AvroNode n) {
     final Node parsed;
     if (n.getPackageNode() != null) {
       parsed = new PackageNodeImpl(parent, n.getName(), n.getFullName());
     } else if (n.getNamedParameterNode() != null) {
       final AvroNamedParameterNode np = n.getNamedParameterNode();
-      parsed = new NamedParameterNodeImpl<Object>(parent, n.getName(), 
n.getFullName(),
+      parsed = new NamedParameterNodeImpl<>(parent, n.getName(), 
n.getFullName(),
               np.getFullArgClassName(), np.getSimpleArgClassName(), 
np.getIsSet(), np.getIsList(),
               np.getDocumentation(), np.getShortName(), 
np.getInstanceDefault().toArray(new String[0]));
     } else if (n.getClassNode() != null) {
@@ -84,14 +89,17 @@ public class AvroClassHierarchy implements ClassHierarchy {
               cn.getIsInjectionCandidate(), cn.getIsExternalConstructor(), 
injectableConstructors.toArray(dummy),
               allConstructors.toArray(dummy), defaultImpl);
     } else {
-      throw new IllegalStateException("Bad protocol buffer: got abstract node" 
+ n);
+      throw new IllegalStateException("Bad avro node: got abstract node" + n);
     }
-    for (AvroNode child : n.getChildren()) {
+
+    for (final AvroNode child : n.getChildren()) {
       parseSubHierarchy(parsed, child);
     }
   }
 
-
+  /**
+   * Register the implementation for the ClassNode recursively.
+   */
   @SuppressWarnings({"rawtypes", "unchecked"})
   private void wireUpInheritanceRelationships(final AvroNode n) {
     if (n.getClassNode() != null) {
@@ -100,25 +108,30 @@ public class AvroClassHierarchy implements ClassHierarchy 
{
       try {
         iface = (ClassNode) getNode(n.getFullName());
       } catch (NameResolutionException e) {
-        throw new IllegalStateException("When reading protocol buffer node "
-                + n.getFullName() + " does not exist.  Full record is " + n, 
e);
+        final String errorMessage = new StringBuilder()
+                .append("When reading avro node ").append(n.getFullName())
+                .append(" does not exist.  Full record is 
").append(n).toString();
+        throw new IllegalStateException(errorMessage, e);
       }
       for (final String impl : cn.getImplFullNames()) {
         try {
           iface.putImpl((ClassNode) getNode(impl));
         } catch (NameResolutionException e) {
-          throw new IllegalStateException("When reading protocol buffer node "
-                  + n + " refers to non-existent implementation:" + impl);
+          final String errorMessage = new StringBuilder()
+                  .append("When reading avro node ").append(n)
+                  .append(" refers to non-existent 
implementation:").append(impl).toString();
+          throw new IllegalStateException(errorMessage, e);
         } catch (ClassCastException e) {
           try {
-            throw new IllegalStateException(
-                    "When reading protocol buffer node " + n
-                            + " found implementation" + getNode(impl)
-                            + " which is not a ClassNode!");
+            final String errorMessage = new StringBuilder()
+                    .append("When reading avro node ").append(n).append(" 
found implementation").append(getNode(impl))
+                    .append(" which is not a ClassNode!").toString();
+            throw new IllegalStateException(errorMessage, e);
           } catch (NameResolutionException e2) {
-            throw new IllegalStateException(
-                    "Got 'cant happen' exception when producing error message 
for "
-                            + e);
+            final String errorMessage = new StringBuilder()
+                    .append("Got 'cant happen' exception when producing error 
message for ")
+                    .append(e).toString();
+            throw new IllegalStateException(errorMessage);
           }
         }
       }
@@ -145,7 +158,7 @@ public class AvroClassHierarchy implements ClassHierarchy {
   }
 
   @Override
-  public ClassHierarchy merge(ClassHierarchy ch) {
+  public ClassHierarchy merge(final ClassHierarchy ch) {
     if (this == ch) {
       return this;
     }
@@ -158,7 +171,6 @@ public class AvroClassHierarchy implements ClassHierarchy {
     for (final String key : ach.lookupTable.keySet()) {
       if (!this.lookupTable.containsKey(key)) {
         this.lookupTable.put(key, ach.lookupTable.get(key));
-        // TODO : Does the order not matter here?
       }
     }
 
@@ -175,7 +187,6 @@ public class AvroClassHierarchy implements ClassHierarchy {
                   cn.isExternalConstructor(), cn.getInjectableConstructors(), 
cn.getAllConstructors(),
                   cn.getDefaultImplementation());
         }
-        // TODO What if n is the package node?
       }
     }
     return this;

Reply via email to