@Override
  public ClassHierarchy merge(ClassHierarchy ch) {
    if (this == ch) {
      return this;
    }
    if (!(ch instanceof ProtocolBufferClassHierarchy)) {
      throw new UnsupportedOperationException(
          "Cannot merge with class hierarchies of type: " + ch.getClass().getName());
    }

    final ProtocolBufferClassHierarchy pch = (ProtocolBufferClassHierarchy) ch;
    for (final String key : pch.lookupTable.keySet()) {
      if (!this.lookupTable.containsKey(key)) {
        this.lookupTable.put(key, pch.lookupTable.get(key));
      }

      for (final Node n : ch.getNamespace().getChildren()) {
        if (!this.namespace.contains(n.getFullName())) {
          if (n instanceof NamedParameter) {
            final NamedParameterNode np = (NamedParameterNode) n;
            new NamedParameterNodeImpl<>(
                this.namespace,
                np.getName(),
                np.getFullName(),
                np.getFullArgName(),
                np.getSimpleArgName(),
                np.isSet(),
                np.isList(),
                np.getDocumentation(),
                np.getShortName(),
                np.getDefaultInstanceAsStrings());
          } else if (n instanceof ClassNode) {
            final ClassNode cn = (ClassNode) n;
            new ClassNodeImpl(
                namespace,
                cn.getName(),
                cn.getFullName(),
                cn.isUnit(),
                cn.isInjectionCandidate(),
                cn.isExternalConstructor(),
                cn.getInjectableConstructors(),
                cn.getAllConstructors(),
                cn.getDefaultImplementation());
          }
        }
      }
    }
    return this;
  }
 /**
  * serialize a class hierarchy into a file.
  *
  * @param file
  * @param classHierarchy
  * @throws IOException
  */
 public static void serialize(final File file, final ClassHierarchy classHierarchy)
     throws IOException {
   final ClassHierarchyProto.Node node = serializeNode(classHierarchy.getNamespace());
   try (final FileOutputStream output = new FileOutputStream(file)) {
     try (final DataOutputStream dos = new DataOutputStream(output)) {
       node.writeTo(dos);
     }
   }
 }
 /**
  * Serialize a class hierarchy into a protocol buffer object.
  *
  * @param classHierarchy
  * @return
  */
 public static ClassHierarchyProto.Node serialize(ClassHierarchy classHierarchy) {
   return serializeNode(classHierarchy.getNamespace());
 }