private static LeafSetEntryNode<?> getReferencedLeafSetEntryNode(final LeafSetNode<?> referencedNode, final Object currentNodeValue) { for (final LeafSetEntryNode<?> entryNode : referencedNode.getValue()) { if (currentNodeValue.equals(entryNode.getValue())) { return entryNode; } } return null; }
private LeafSetNode<?> reusableSegment(final UnkeyedListEntryNode segment) { final Optional<NormalizedNode<?, ?>> maybeAsSequence = NormalizedNodes.findNode(segment, this.asPathSequence); if (maybeAsSequence.isPresent()) { final LeafSetNode<?> asList = (LeafSetNode<?>) maybeAsSequence.get(); if (asList.getValue().size() < Values.UNSIGNED_BYTE_MAX_VALUE) { return asList; } } return null; }
private static LeafSetEntryNode<?> getReferencedLeafSetEntryNode(final LeafSetNode<?> referencedNode, final Object currentNodeValue) { for (final LeafSetEntryNode<?> entryNode : referencedNode.getValue()) { if (currentNodeValue.equals(entryNode.getValue())) { return entryNode; } } return null; }
private static void addOtherClusterEntries(final Optional<NormalizedNode<?, ?>> maybeClusterList, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> clb) { final NormalizedNode<?, ?> clusterList = maybeClusterList.get(); if (clusterList instanceof LeafSetNode) { for (final LeafSetEntryNode<?> n : ((LeafSetNode<?>) clusterList).getValue()) { // There's no way we can safely avoid this cast @SuppressWarnings("unchecked") final LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>) n; clb.addChild(child); } } else { LOG.warn("Ignoring malformed CLUSTER_LIST {}", clusterList); } }
/** * Extracts all values of a leaf-list node as a set of strings */ private static Set<String> getAllChildNodeValues(final DataContainerNode<?> schemaNode, final QName childNodeQName) { final Set<String> extractedValues = Sets.newHashSet(); final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> child = schemaNode.getChild(toId(childNodeQName)); Preconditions.checkArgument(child.isPresent(), "Child nodes %s not present", childNodeQName); Preconditions.checkArgument(child.get() instanceof LeafSetNode<?>, "Child nodes %s not present", childNodeQName); for (final LeafSetEntryNode<?> childNode : ((LeafSetNode<?>) child.get()).getValue()) { extractedValues.add(getValueOfSimpleNode(childNode).get()); } return extractedValues; }
@Nullable Iterator<NormalizedNodeContext> iterateChildrenNamed(final DataContainerNode<?> data, final QName qname) { final NodeIdentifier arg = new NodeIdentifier(qname); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> maybeChild = data.getChild(arg); if (!maybeChild.isPresent()) { return null; } final NormalizedNode<?, ?> child = maybeChild.get(); final Collection<? extends NormalizedNode<?, ?>> collection; // The child may be a structural node if (child instanceof MapNode) { collection = ((MapNode)child).getValue(); } else if (child instanceof LeafSetNode) { collection = ((LeafSetNode<?>)child).getValue(); } else { return Iterators.singletonIterator(createChild(child)); } return Iterators.transform(collection.iterator(), this::createChild); }
@Override protected Object deserializeObject(final NormalizedNode<?, ?> normalizedNode) { if (normalizedNode instanceof LeafNode<?>) { return valueCodec.deserialize(normalizedNode.getValue()); } if (normalizedNode instanceof LeafSetNode<?>) { @SuppressWarnings("unchecked") final Collection<LeafSetEntryNode<Object>> domValues = ((LeafSetNode<Object>) normalizedNode).getValue(); final List<Object> result = new ArrayList<>(domValues.size()); for (final LeafSetEntryNode<Object> valueNode : domValues) { result.add(valueCodec.deserialize(valueNode.getValue())); } return result; } return null; }
@Override protected Object deserializeObject(final NormalizedNode<?, ?> normalizedNode) { if (normalizedNode instanceof LeafNode<?>) { return valueCodec.deserialize(normalizedNode.getValue()); } if (normalizedNode instanceof LeafSetNode<?>) { @SuppressWarnings("unchecked") final Collection<LeafSetEntryNode<Object>> domValues = ((LeafSetNode<Object>) normalizedNode).getValue(); final List<Object> result = new ArrayList<>(domValues.size()); for (final LeafSetEntryNode<Object> valueNode : domValues) { result.add(valueCodec.deserialize(valueNode.getValue())); } return result; } return null; }
@Nullable Iterator<NormalizedNodeContext> iterateChildrenNamed(final DataContainerNode<?> data, final QName qname) { final NodeIdentifier arg = new NodeIdentifier(qname); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> maybeChild = data.getChild(arg); if (!maybeChild.isPresent()) { return null; } final NormalizedNode<?, ?> child = maybeChild.get(); final Collection<? extends NormalizedNode<?, ?>> collection; // The child may be a structural node if (child instanceof MapNode) { collection = ((MapNode)child).getValue(); } else if (child instanceof LeafSetNode) { collection = ((LeafSetNode<?>)child).getValue(); } else { return Iterators.singletonIterator(createChild(child)); } return Iterators.transform(collection.iterator(), this::createChild); }
private void validateLeafSetNodeData(final LeafSetNode<?> node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { if (referencedByCtx != null || referencingCtx != null) { for (final NormalizedNode<?, ?> leafSetEntry : node.getValue()) { if (referencedByCtx != null && referencedByCtx.isReferenced()) { validateLeafRefTargetNodeData(leafSetEntry, referencedByCtx, modificationType); } if (referencingCtx != null && referencingCtx.isReferencing()) { validateLeafRefNodeData(leafSetEntry, referencingCtx, modificationType, current); } } } }
private void validateLeafSetNodeData(final LeafSetNode<?> node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { if (referencedByCtx != null || referencingCtx != null) { for (final NormalizedNode<?, ?> leafSetEntry : node.getValue()) { if (referencedByCtx != null && referencedByCtx.isReferenced()) { validateLeafRefTargetNodeData(leafSetEntry, referencedByCtx, modificationType); } if (referencingCtx != null && referencingCtx.isReferencing()) { validateLeafRefNodeData(leafSetEntry, referencingCtx, modificationType, current); } } } }
for (final LeafSetEntryNode<?> node : clusterList.getValue()) { if (this.clusterIdentifier.getValue().equals(node.getValue())) { LOG.info("Received a route with our CLUSTER_ID {} in CLUSTER_LIST {}, filtering it", this.clusterIdentifier.getValue(), clusterList);
private void addValues(final Set<Object> values, final NormalizedNode<?, ?> node, final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path, final YangInstanceIdentifier current) { if (node instanceof ValueNode) { values.add(node.getValue()); return; } if (node instanceof LeafSetNode<?>) { for (final NormalizedNode<?, ?> entry : ((LeafSetNode<?>) node).getValue()) { values.add(entry.getValue()); } return; } final QNameWithPredicate next = path.peek(); if (next == null) { return; } final PathArgument pathArgument = new NodeIdentifier(next.getQName()); if (node instanceof DataContainerNode) { processChildNode(values, (DataContainerNode<?>) node, pathArgument, next.getQNamePredicates(), path, current); } else if (node instanceof MapNode) { Stream<MapEntryNode> entries = ((MapNode) node).getValue().stream(); if (!nodePredicates.isEmpty() && current != null) { entries = entries.filter(createMapEntryPredicate(nodePredicates, current)); } entries.forEach(entry -> processChildNode(values, entry, pathArgument, next.getQNamePredicates(), path, current)); } }
private void addValues(final Set<Object> values, final NormalizedNode<?, ?> node, final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path, final YangInstanceIdentifier current) { if (node instanceof ValueNode) { values.add(node.getValue()); return; } if (node instanceof LeafSetNode<?>) { for (final NormalizedNode<?, ?> entry : ((LeafSetNode<?>) node).getValue()) { values.add(entry.getValue()); } return; } final QNameWithPredicate next = path.peek(); if (next == null) { return; } final PathArgument pathArgument = new NodeIdentifier(next.getQName()); if (node instanceof DataContainerNode) { processChildNode(values, (DataContainerNode<?>) node, pathArgument, next.getQNamePredicates(), path, current); } else if (node instanceof MapNode) { Stream<MapEntryNode> entries = ((MapNode) node).getValue().stream(); if (!nodePredicates.isEmpty() && current != null) { entries = entries.filter(createMapEntryPredicate(nodePredicates, current)); } entries.forEach(entry -> processChildNode(values, entry, pathArgument, next.getQNamePredicates(), path, current)); } }
for (final LeafSetEntryNode<?> child : reusableAsSeq.getValue()) { asSequenceBuilder.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.asNumberQname, child.getValue())).withValue(child.getValue()).build());