Improve segmented journal actor metrics
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / DomListBuilder.java
1 /*
2  * Copyright (c) 2015 Cisco Systems and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.dsbenchmark;
10
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.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
18 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
20 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
21
22 public final class DomListBuilder {
23     // Inner List Qname identifiers for yang model's 'name' and 'value'
24     private static final org.opendaylight.yangtools.yang.common.QName IL_NAME = QName.create(InnerList.QNAME, "name");
25     private static final org.opendaylight.yangtools.yang.common.QName IL_VALUE = QName.create(InnerList.QNAME, "value");
26
27     // Outer List Qname identifier for yang model's 'id'
28     private static final org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id");
29
30     private DomListBuilder() {
31
32     }
33
34     public static List<MapEntryNode> buildOuterList(final int outerElements, final int innerElements) {
35         final var outerList = new ArrayList<MapEntryNode>(outerElements);
36         for (int j = 0; j < outerElements; j++) {
37             outerList.add(ImmutableNodes.newMapEntryBuilder()
38                 .withNodeIdentifier(NodeIdentifierWithPredicates.of(OuterList.QNAME, OL_ID, j))
39                 .withChild(ImmutableNodes.leafNode(OL_ID, j))
40                 .withChild(buildInnerList(j, innerElements))
41                 .build());
42         }
43         return outerList;
44     }
45
46     private static MapNode buildInnerList(final int index, final int elements) {
47         final var innerList = ImmutableNodes.newSystemMapBuilder()
48             .withNodeIdentifier(new NodeIdentifier(InnerList.QNAME));
49
50         final String itemStr = "Item-" + index + "-";
51         for (int i = 0; i < elements; i++) {
52             innerList.addChild(ImmutableNodes.newMapEntryBuilder()
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)))
56                 .build());
57         }
58         return innerList.build();
59     }
60 }