public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent, final Iterable<PathArgument> relativePath) { requireNonNull(parent, "Parent must not be null"); requireNonNull(relativePath, "Relative path must not be null"); Optional<NormalizedNode<?, ?>> currentNode = parent; final Iterator<PathArgument> pathIterator = relativePath.iterator(); while (currentNode.isPresent() && pathIterator.hasNext()) { currentNode = getDirectChild(currentNode.get(), pathIterator.next()); } return currentNode; }
@Override public void enter(@Nonnull final PathArgument child) { final Optional<NormalizedNode<?, ?>> maybeChildNode = NormalizedNodes.getDirectChild(stack.peek(), child); checkArgument(maybeChildNode.isPresent(), "Child %s not found", child); final NormalizedNode<?, ?> childNode = maybeChildNode.get(); checkArgument(childNode instanceof NormalizedNodeContainer, "Child %s is not a container", child); stack.push((NormalizedNodeContainer<?, ?, ?>) childNode); }
@Override public void enter(@Nonnull final PathArgument child) { final Optional<NormalizedNode<?, ?>> maybeChildNode = NormalizedNodes.getDirectChild(stack.peek(), child); checkArgument(maybeChildNode.isPresent(), "Child %s not found", child); final NormalizedNode<?, ?> childNode = maybeChildNode.get(); checkArgument(childNode instanceof NormalizedNodeContainer, "Child %s is not a container", child); stack.push((NormalizedNodeContainer<?, ?, ?>) childNode); }
public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent, final Iterable<PathArgument> relativePath) { requireNonNull(parent, "Parent must not be null"); requireNonNull(relativePath, "Relative path must not be null"); Optional<NormalizedNode<?, ?>> currentNode = parent; final Iterator<PathArgument> pathIterator = relativePath.iterator(); while (currentNode.isPresent() && pathIterator.hasNext()) { currentNode = getDirectChild(currentNode.get(), pathIterator.next()); } return currentNode; }
private static Optional<NormalizedNode<?, ?>> findParentNode( final Optional<NormalizedNode<?, ?>> root, final YangInstanceIdentifier path) { Optional<NormalizedNode<?, ?>> currentNode = root; final Iterator<PathArgument> pathIterator = path.getPathArguments().iterator(); while (pathIterator.hasNext()) { final PathArgument childPathArgument = pathIterator.next(); if (pathIterator.hasNext() && currentNode.isPresent()) { currentNode = NormalizedNodes.getDirectChild(currentNode.get(), childPathArgument); } else { return currentNode; } } return Optional.empty(); }
private static Optional<NormalizedNode<?, ?>> findParentNode( final Optional<NormalizedNode<?, ?>> root, final YangInstanceIdentifier path) { Optional<NormalizedNode<?, ?>> currentNode = root; final Iterator<PathArgument> pathIterator = path.getPathArguments().iterator(); while (pathIterator.hasNext()) { final PathArgument childPathArgument = pathIterator.next(); if (pathIterator.hasNext() && currentNode.isPresent()) { currentNode = NormalizedNodes.getDirectChild(currentNode.get(), childPathArgument); } else { return currentNode; } } return Optional.empty(); }
NormalizedNodeContext createContext(final YangInstanceIdentifier path) { NormalizedNodeContext result = root; for (PathArgument arg : path.getPathArguments()) { final Optional<NormalizedNode<?, ?>> node = NormalizedNodes.getDirectChild(result.getNode(), arg); checkArgument(node.isPresent(), "Node %s has no child %s", result.getNode(), arg); result = result.createChild(node.get()); } return result; }
NormalizedNodeContext createContext(final YangInstanceIdentifier path) { NormalizedNodeContext result = root; for (PathArgument arg : path.getPathArguments()) { final Optional<NormalizedNode<?, ?>> node = NormalizedNodes.getDirectChild(result.getNode(), arg); checkArgument(node.isPresent(), "Node %s has no child %s", result.getNode(), arg); result = result.createChild(node.get()); } return result; }
private void enforceCases(final NormalizedNode<?, ?> normalizedNode) { Verify.verify(normalizedNode instanceof ChoiceNode); final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue(); if (!children.isEmpty()) { final DataContainerChild<?, ?> firstChild = children.iterator().next(); final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong " + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier()); // Make sure no leaves from other cases are present for (final CaseEnforcer other : exclusions.get(enforcer)) { for (final PathArgument id : other.getAllChildIdentifiers()) { final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id); Preconditions.checkArgument(!maybeChild.isPresent(), "Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s", firstChild.getIdentifier(), enforcer, id, other, maybeChild.orElse(null)); } } // Make sure all mandatory children are present enforcer.enforceOnTreeNode(normalizedNode); } }
private void enforceCases(final NormalizedNode<?, ?> normalizedNode) { Verify.verify(normalizedNode instanceof ChoiceNode); final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue(); if (!children.isEmpty()) { final DataContainerChild<?, ?> firstChild = children.iterator().next(); final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong " + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier()); // Make sure no leaves from other cases are present for (final CaseEnforcer other : exclusions.get(enforcer)) { for (final PathArgument id : other.getAllChildIdentifiers()) { final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id); Preconditions.checkArgument(!maybeChild.isPresent(), "Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s", firstChild.getIdentifier(), enforcer, id, other, maybeChild.orElse(null)); } } // Make sure all mandatory children are present enforcer.enforceOnTreeNode(normalizedNode); } }