@Override
  @SuppressWarnings("unchecked")
  public final NormalizedNode<?, ?> create(
      final YangInstanceIdentifier instanceId,
      final Optional<NormalizedNode<?, ?>> lastChild,
      final Optional<Map.Entry<QName, ModifyAction>> operation) {
    checkNotNull(instanceId);
    final Iterator<PathArgument> iterator = instanceId.getPathArguments().iterator();
    final PathArgument legacyData = iterator.next();

    if (!isMixin() && getIdentifier().getNodeType() != null) {
      checkArgument(
          getIdentifier().getNodeType().equals(legacyData.getNodeType()),
          "Node QName must be %s was %s",
          getIdentifier().getNodeType(),
          legacyData.getNodeType());
    }
    final NormalizedNodeContainerBuilder builder = createBuilder(legacyData);

    if (iterator.hasNext()) {
      final PathArgument childPath = iterator.next();
      final InstanceIdToNodes<?> childOp = getChildOperation(childPath);

      final YangInstanceIdentifier childId =
          YangInstanceIdentifier.create(Iterables.skip(instanceId.getPathArguments(), 1));
      builder.addChild(childOp.create(childId, lastChild, operation));
    } else {
      if (lastChild.isPresent()) {
        builder.withValue(Lists.newArrayList((Collection<?>) lastChild.get().getValue()));
      }
      if (operation.isPresent()) {
        Preconditions.checkArgument(builder instanceof AttributesBuilder<?>);
        addModifyOpIfPresent(operation, ((AttributesBuilder<?>) builder));
      }
    }

    return builder.build();
  }
  private void findDuplicates(final YangInstanceIdentifier path, final NormalizedNode<?, ?> node) {
    final DuplicateEntry i = identities.get(node);
    if (i == null) {
      final DuplicateEntry d = duplicates.get(node);
      if (d == null) {
        final DuplicateEntry n = new DuplicateEntry(path);
        identities.put(node, n);
        duplicates.put(node, n);
      } else {
        d.addDuplicate(path);
      }

      if (node instanceof NormalizedNodeContainer<?, ?, ?>) {
        final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node;

        for (NormalizedNode<?, ?> c : container.getValue()) {
          findDuplicates(path.node(c.getIdentifier()), c);
        }
      }
    } else {
      i.addHardLink(path);
    }
  }