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()); }
@SuppressWarnings("unchecked") private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException { LOG.trace("Reading children of leaf set"); lastLeafSetQName = nodeType; LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); while (child != null) { builder.withChild(child); child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); } return builder; }
@SuppressWarnings("unchecked") private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException { LOG.debug("Reading children of leaf set"); lastLeafSetQName = nodeType; LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); while(child != null) { builder.withChild(child); child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); } return builder; }
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(); }
.leafSetBuilder((LeafListSchemaNode) featureSchemaNode); for (final FeatureDefinition feature : module.getFeatures()) { featuresBuilder.withChild(Builders.leafSetEntryBuilder(((LeafListSchemaNode) featureSchemaNode)) .withValue(feature.getQName().getLocalName()).build());
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(); }
asSequenceBuilder.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.asNumberQname, child.getValue())).withValue(child.getValue()).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})) .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); }
new NodeIdentifier(SHOE_QNAME)).withChild(nike).withChild(puma).build(); .withNodeIdentifier( new NodeIdentifier(QName.create( TEST_QNAME, "capability"))).withChild(cap1).build(); .withNodeIdentifier( new NodeIdentifier(QName.create( TEST_QNAME, "number"))).withChild(five).withChild(fifteen) .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(); }
private static NormalizedNode<?, ?> createNormalizedNode() { final LeafSetNode<Object> leafSetNode = Builders.leafSetBuilder() .withNodeIdentifier(id("leafSetNode")) .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);