private Optional<LeafSetNode<?>> build(LeafListSchemaNode schemaNode, List<LeafSetEntryNode<?>> resultNodes) { if(resultNodes.isEmpty()) { return Optional.absent(); } ListNodeBuilder<Object, LeafSetEntryNode<Object>> b = Builders.leafSetBuilder(schemaNode); for (LeafSetEntryNode<?> resultNode : resultNodes) { // FIXME: can we do something about this SuppressWarnings? @SuppressWarnings("unchecked") final LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>) resultNode; b.withChild(child); } return Optional.<LeafSetNode<?>>of(b.build()); }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof LeafSetNode<?>); return ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(((LeafSetNode<?>) original).getIdentifier()) .build(); } }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof OrderedLeafSetNode<?>); return ImmutableOrderedLeafSetNodeBuilder.create() .withNodeIdentifier(((OrderedLeafSetNode<?>) original).getIdentifier()).build(); }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof OrderedLeafSetNode<?>); return ImmutableOrderedLeafSetNodeBuilder.create() .withNodeIdentifier(((OrderedLeafSetNode<?>) original).getIdentifier()).build(); } }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof LeafSetNode<?>); return ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(((LeafSetNode<?>) original).getIdentifier()) .build(); }
@Override public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) { return Builders.leafSetBuilder().withNodeIdentifier(getIdentifier()).build(); }
@Override public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) { return Builders.orderedLeafSetBuilder().withNodeIdentifier(getIdentifier()).build(); } }
private NormalizedNode<?, ?> buildListNode( final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder, final NormalizedNodeMessages.Node node) { builder.withNodeIdentifier(toNodeIdentifier(node.getPathArgument())); for(NormalizedNodeMessages.Node child : node.getChildList()){ builder.withChild((LeafSetEntryNode<Object>) deSerialize(child)); } return builder.build(); }
.withValue(feature.getQName().getLocalName()).build()); moduleNodeValues.withChild(featuresBuilder.build());
/** * Attributes when reflecting a route from Internal iBGP (Application Peer) * @param attributes * @return */ ContainerNode reflectedAttributes(final ContainerNode attributes) { final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> attributesContainer = Builders.containerBuilder(attributes); // if there was a CLUSTER_LIST attribute, add it final Optional<NormalizedNode<?, ?>> maybeClusterList = NormalizedNodes.findNode(attributes, this.clusterListPath); if (maybeClusterList.isPresent()) { // Create a new CLUSTER_LIST builder final ListNodeBuilder<Object, LeafSetEntryNode<Object>> clusterBuilder = Builders.orderedLeafSetBuilder(); clusterBuilder.withNodeIdentifier(this.clusterListLeaf); AttributeOperations.addOtherClusterEntries(maybeClusterList, clusterBuilder); // Now wrap it in a container and add it to attributes final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> clusterListCont= Builders.containerBuilder(); clusterListCont.withNodeIdentifier(this.clusterListContainer); clusterListCont.withChild(clusterBuilder.build()); attributesContainer.withChild(clusterListCont.build()); } return attributesContainer.build(); }
LOG.debug("Read leaf set node {}", identifier); return addLeafSetChildren(identifier.getNodeType(), Builders.leafSetBuilder().withNodeIdentifier(identifier)).build(); Builders.orderedLeafSetBuilder().withNodeIdentifier(identifier); orderedLeafSetBuilder = addLeafSetChildren(identifier.getNodeType(), orderedLeafSetBuilder); return orderedLeafSetBuilder.build();
private MapEntryNode toMapEntryNode(TestResult testResult) { YangInstanceIdentifier testResultId = YangInstanceIdentifier.builder().node(TEST_RESULTS_QNAME).node(TEST_RESULT_QNAME).build(); // Construct results list LinkedList<LeafSetEntryNode<Object>> entryList = new LinkedList<>(); for (String result : testResult.getResults()) { LeafSetEntryNode<Object> leafSetEntryNode = ImmutableLeafSetEntryNodeBuilder.create() .withNodeIdentifier(new NodeWithValue(RESULTS_QNAME, result)) .withValue(result) .build(); entryList.add(leafSetEntryNode); } // Construct results LeafSetNode LeafSetNode<?> resultsNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(RESULTS_QNAME)).withValue(entryList).build(); // Construct test result ContainerNode with 2 children - test-identifier leaf and results leaf-set MapEntryNode testResultNode = ImmutableNodes.mapEntryBuilder() .withNodeIdentifier(new NodeIdentifierWithPredicates(TEST_RESULT_QNAME, TEST_ID_QNAME, testResult.getTestIdentifier())) .withChild(ImmutableNodes.leafNode(TEST_ID_QNAME, testResult.getTestIdentifier())) .withChild(resultsNode) .build(); return(testResultNode); }
ContainerNode reflectedAttributes(final ContainerNode attributes, final Ipv4Address originatorId, final ClusterIdentifier clusterId) { final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> attributesContainer = Builders.containerBuilder(attributes); // Create a new CLUSTER_LIST builder final ListNodeBuilder<Object, LeafSetEntryNode<Object>> clusterBuilder = Builders.orderedLeafSetBuilder(); clusterBuilder.withNodeIdentifier(this.clusterListLeaf); // prepend local CLUSTER_ID clusterBuilder.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.clusterQname, clusterId.getValue())). withValue(clusterId.getValue()).build()); // if there was a CLUSTER_LIST attribute, add all other entries final Optional<NormalizedNode<?, ?>> maybeClusterList = NormalizedNodes.findNode(attributes, this.clusterListPath); if (maybeClusterList.isPresent()) { AttributeOperations.addOtherClusterEntries(maybeClusterList, clusterBuilder); } else { LOG.debug("Creating fresh CLUSTER_LIST attribute"); } // Now wrap it in a container and add it to attributes final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> clusterListCont = Builders.containerBuilder(); clusterListCont.withNodeIdentifier(this.clusterListContainer); clusterListCont.withChild(clusterBuilder.build()); attributesContainer.withChild(clusterListCont.build()); // add ORIGINATOR_ID if not present final Optional<NormalizedNode<?, ?>> maybeOriginatorId = NormalizedNodes.findNode(attributes, this.originatorIdPath); if (!maybeOriginatorId.isPresent()) { final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> originatorIDBuilder = Builders.containerBuilder(); originatorIDBuilder.withNodeIdentifier(this.originatorIdContainer); originatorIDBuilder.withChild(ImmutableNodes.leafNode(this.originatorIdLeaf, originatorId.getValue())); attributesContainer.withChild(originatorIDBuilder.build()); } return attributesContainer.build(); }
segmentsBuilder.withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(this.asPathSegments).withChild(asSequenceBuilder.build()).build());
@Test public void testLeafSetEntryNodeNotPrunedWhenHasParent() throws IOException { NormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.SHOE_QNAME)); LeafSetEntryNode<Object> child = Builders.leafSetEntryBuilder().withValue("puma").withNodeIdentifier( new NodeWithValue<>(TestModel.SHOE_QNAME, "puma")).build(); NormalizedNode<?, ?> input = Builders.leafSetBuilder().withNodeIdentifier( new NodeIdentifier(TestModel.SHOE_QNAME)).withChild(child).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", input, actual); }
@Test public void testLeafSetEntryNodePrunedWhenHasParentAndSchemaMissing() throws IOException { NormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.INVALID_QNAME)); LeafSetEntryNode<Object> child = Builders.leafSetEntryBuilder().withValue("test").withNodeIdentifier( new NodeWithValue<>(TestModel.INVALID_QNAME, "test")).build(); NormalizedNode<?, ?> input = Builders.leafSetBuilder().withNodeIdentifier( new NodeIdentifier(TestModel.INVALID_QNAME)).withChild(child).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertNull(actual); }
private static NormalizedNode<?, ?> createTestContainer() { byte[] bytes1 = {1, 2, 3}; LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build(); byte[] bytes2 = {}; LeafSetEntryNode<Object> entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).withValue(bytes2).build(); return TestModel.createBaseTestContainerBuilder() .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier( new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)) .withChild(entry1).withChild(entry2).build()) .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1, 2, 3, 4})) .build(); } }
private static NormalizedNode<?, ?> createTestContainer() { byte[] bytes1 = {1, 2, 3}; LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build(); byte[] bytes2 = {}; LeafSetEntryNode<Object> entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).withValue(bytes2).build(); return TestModel.createBaseTestContainerBuilder() .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier( new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)) .withChild(entry1).withChild(entry2).build()) .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1, 2, 3, 4})) .withChild(ImmutableNodes.leafNode(TestModel.EMPTY_QNAME, Empty.getInstance())) .withChild(Builders.orderedMapBuilder() .withNodeIdentifier(new NodeIdentifier(TestModel.ORDERED_LIST_QNAME)) .withChild(ImmutableNodes.mapEntry(TestModel.ORDERED_LIST_ENTRY_QNAME, TestModel.ID_QNAME, 11)).build()).build(); }
.withChild(createLeafSetEntry("leafSetNode", "leafSetValue1")) .withChild(createLeafSetEntry("leafSetNode", "leafSetValue2")) .build(); final LeafSetNode<Object> orderedLeafSetNode = Builders.orderedLeafSetBuilder() .withNodeIdentifier(id("orderedLeafSetNode")) .withChild(createLeafSetEntry("orderedLeafSetNode", "value1")) .withChild(createLeafSetEntry("orderedLeafSetNode", "value2")) .build(); final LeafNode<Boolean> booleanLeaf = createLeaf("booleanLeaf", true); final LeafNode<Byte> byteLeaf = createLeaf("byteLeaf", (byte) 0);