@Nonnull @Override public final Collection<DataTreeCandidateNode> getChildNodes() { return Collections2.transform(getData().getValue(), this::createChild); }
@Nonnull @Override public Collection<DataTreeCandidateNode> getChildNodes() { if (data instanceof NormalizedNodeContainer) { return Collections2.transform(((NormalizedNodeContainer<?, ?, ?>) data).getValue(), input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input)); } return ImmutableList.of(); }
private static int numOfChildrenFromValue(final NormalizedNode<?, ?> value) { if (value instanceof NormalizedNodeContainer) { return ((NormalizedNodeContainer<?, ?, ?>) value).getValue().size(); } else if (value instanceof UnkeyedListNode) { return ((UnkeyedListNode) value).getSize(); } throw new IllegalArgumentException(String.format( "Unexpected type '%s', expected types are NormalizedNodeContainer and UnkeyedListNode", value.getClass())); } }
@Nonnull @Override public Collection<DataTreeCandidateNode> getChildNodes() { if (data instanceof NormalizedNodeContainer) { return Collections2.transform(((NormalizedNodeContainer<?, ?, ?>) data).getValue(), input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input)); } return ImmutableList.of(); }
@Nonnull @Override public final Collection<DataTreeCandidateNode> getChildNodes() { return Collections2.transform(getData().getValue(), this::createChild); }
private static int numOfChildrenFromValue(final NormalizedNode<?, ?> value) { if (value instanceof NormalizedNodeContainer) { return ((NormalizedNodeContainer<?, ?, ?>) value).getValue().size(); } else if (value instanceof UnkeyedListNode) { return ((UnkeyedListNode) value).getSize(); } throw new IllegalArgumentException(String.format( "Unexpected type '%s', expected types are NormalizedNodeContainer and UnkeyedListNode", value.getClass())); } }
private static boolean isEmpty(final TreeNode treeNode) { final NormalizedNode<?, ?> data = treeNode.getData(); if (data instanceof NormalizedNodeContainer) { return ((NormalizedNodeContainer<?, ?, ?>) data).getValue().isEmpty(); } if (data instanceof OrderedNodeContainer) { return ((OrderedNodeContainer<?>) data).getSize() == 0; } throw new IllegalStateException("Unhandled data " + data); } }
@SuppressWarnings("unchecked") @Nonnull @Override public D deserialize(@Nonnull final NormalizedNode<?, ?> data) { Preconditions.checkArgument(data instanceof ChoiceNode); final NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>> casted = (NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>>) data; final NormalizedNode<?, ?> first = Iterables.getFirst(casted.getValue(), null); if (first == null) { return null; } final DataContainerCodecPrototype<?> caze = byYangCaseChild.get(first.getIdentifier()); return (D) caze.get().deserialize(data); }
private static void toStringTree(final StringBuilder builder, final NormalizedNode<?, ?> node, final int offset) { final String prefix = Strings.repeat(" ", offset); builder.append(prefix).append(toStringTree(node.getIdentifier())); if (node instanceof NormalizedNodeContainer<?, ?, ?>) { final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node; builder.append(" {\n"); for (NormalizedNode<?, ?> child : container.getValue()) { toStringTree(builder, child, offset + STRINGTREE_INDENT); } builder.append(prefix).append('}'); } else { builder.append(' ').append(node.getValue()); } builder.append('\n'); }
private static void toStringTree(final StringBuilder builder, final NormalizedNode<?, ?> node, final int offset) { final String prefix = Strings.repeat(" ", offset); builder.append(prefix).append(toStringTree(node.getIdentifier())); if (node instanceof NormalizedNodeContainer<?, ?, ?>) { final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node; builder.append(" {\n"); for (NormalizedNode<?, ?> child : container.getValue()) { toStringTree(builder, child, offset + STRINGTREE_INDENT); } builder.append(prefix).append('}'); } else { builder.append(' ').append(node.getValue()); } builder.append('\n'); }
@Override public final void mergeToCurrent(final NormalizedNodeContainer<?, ?, ?> data) { for (NormalizedNode<?, ?> child : data.getValue()) { PathArgument childId = child.getIdentifier(); WriteableModificationNode shardChild = node.getChild(childId); if (shardChild != null) { // FIXME: Decompose somehow throw new UnsupportedOperationException("Not implemented yet"); } cursor.merge(childId, child); } }
@Override public MutableTreeNode mutable() { final Map<PathArgument, TreeNode> snapshot = snapshotChildren(); if (snapshot.size() == castData().getValue().size()) { return new MaterializedMutableContainerNode(this, snapshot); } return new LazyMutableContainerNode(this, snapshot); }
@Override public MutableTreeNode mutable() { final Map<PathArgument, TreeNode> snapshot = snapshotChildren(); if (snapshot.size() == castData().getValue().size()) { return new MaterializedMutableContainerNode(this, snapshot); } return new LazyMutableContainerNode(this, snapshot); }
@Override protected ToStringHelper addToStringAttributes(final ToStringHelper helper) { // Modified children add added by superclass. Here we filter the other children. return super.addToStringAttributes(helper).add("untouched", Collections2.filter(castData().getValue(), input -> getModifiedChild(input.getIdentifier()) == null)); } }
@Override protected ToStringHelper addToStringAttributes(final ToStringHelper helper) { // Modified children add added by superclass. Here we filter the other children. return super.addToStringAttributes(helper).add("untouched", Collections2.filter(castData().getValue(), input -> getModifiedChild(input.getIdentifier()) == null)); } }
@Override public void mergeToCurrent(final NormalizedNodeContainer<?, ?, ?> data) { for (NormalizedNode<?, ?> child : data.getValue()) { delegate().merge(child.getIdentifier(), child); } }
private void navigateNormalizedNodeContainerMixin(int level, final String parentPath, NormalizedNodeContainer<?, ?, ?> node) { visitor.visitNode(level, parentPath, node); String newParentPath = parentPath + "/" + node.getIdentifier().toString(); final Iterable<? extends NormalizedNode<?, ?>> value = node.getValue(); for(NormalizedNode<?, ?> normalizedNode : value){ if(normalizedNode instanceof MixinNode && normalizedNode instanceof NormalizedNodeContainer){ navigateNormalizedNodeContainerMixin(level + 1, newParentPath, (NormalizedNodeContainer) normalizedNode); } else { navigateNormalizedNode(level, newParentPath, normalizedNode); } } }
@Override public void writeToCurrent(final NormalizedNodeContainer<?, ?, ?> data) { for (NormalizedNode<?, ?> child : data.getValue()) { delegate().write(child.getIdentifier(), child); } }
@Override protected void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) { final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) value; for (final Object child : container.getValue()) { checkArgument(child instanceof NormalizedNode); final NormalizedNode<?, ?> castedChild = (NormalizedNode<?, ?>) child; final Optional<ModificationApplyOperation> childOp = getChild(castedChild.getIdentifier()); if (childOp.isPresent()) { childOp.get().recursivelyVerifyStructure(castedChild); } else { throw new SchemaValidationFailedException( String.format("Node %s is not a valid child of %s according to the schema.", castedChild.getIdentifier(), container.getIdentifier())); } } }
private void navigateNormalizedNodeContainerMixin(int level, final String parentPath, NormalizedNodeContainer<?, ?, ?> node) { visitor.visitNode(level, parentPath, node); String newParentPath = parentPath + "/" + node.getIdentifier().toString(); final Iterable<? extends NormalizedNode<?, ?>> value = node.getValue(); for (NormalizedNode<?, ?> normalizedNode : value) { if (normalizedNode instanceof MixinNode && normalizedNode instanceof NormalizedNodeContainer) { navigateNormalizedNodeContainerMixin(level + 1, newParentPath, (NormalizedNodeContainer<?, ?, ?>) normalizedNode); } else { navigateNormalizedNode(level, newParentPath, normalizedNode); } } }