2 * Copyright (c) 2015 Cisco Systems and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.dsbenchmark;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
17 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
23 public final class DomListBuilder {
24 // Inner List Qname identifiers for yang model's 'name' and 'value'
25 private static final org.opendaylight.yangtools.yang.common.QName IL_NAME = QName.create(InnerList.QNAME, "name");
26 private static final org.opendaylight.yangtools.yang.common.QName IL_VALUE = QName.create(InnerList.QNAME, "value");
28 // Outer List Qname identifier for yang model's 'id'
29 private static final org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id");
31 private DomListBuilder() {
35 public static List<MapEntryNode> buildOuterList(final int outerElements, final int innerElements) {
36 List<MapEntryNode> outerList = new ArrayList<>(outerElements);
37 for (int j = 0; j < outerElements; j++) {
38 outerList.add(ImmutableNodes.mapEntryBuilder()
39 .withNodeIdentifier(NodeIdentifierWithPredicates.of(OuterList.QNAME, OL_ID, j))
40 .withChild(ImmutableNodes.leafNode(OL_ID, j))
41 .withChild(buildInnerList(j, innerElements))
47 private static MapNode buildInnerList(final int index, final int elements) {
48 CollectionNodeBuilder<MapEntryNode, SystemMapNode> innerList = ImmutableNodes.mapNodeBuilder(InnerList.QNAME);
50 final String itemStr = "Item-" + String.valueOf(index) + "-";
51 for (int i = 0; i < elements; i++) {
52 innerList.addChild(ImmutableNodes.mapEntryBuilder()
53 .withNodeIdentifier(NodeIdentifierWithPredicates.of(InnerList.QNAME, IL_NAME, i))
54 .withChild(ImmutableNodes.leafNode(IL_NAME, i))
55 .withChild(ImmutableNodes.leafNode(IL_VALUE, itemStr + String.valueOf(i)))
58 return innerList.build();