1f379fd262c2b295204b4088f6a76f90c3facc94
[controller.git] / opendaylight / md-sal / sal-test-model / src / main / java / org / opendaylight / controller / md / sal / test / model / util / ListsBindingUtils.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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 package org.opendaylight.controller.md.sal.test.model.util;
9
10 import com.google.common.collect.ImmutableMap;
11 import com.google.common.collect.ImmutableMap.Builder;
12 import com.google.common.collect.Maps;
13 import java.util.Arrays;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugmentBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.top.level.list.NestedList;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.top.level.list.NestedListKey;
28 import org.opendaylight.yangtools.yang.binding.Augmentation;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31
32 public final class ListsBindingUtils {
33     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
34
35     public static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
36     public static final TopLevelListKey TOP_BAR_KEY = new TopLevelListKey("bar");
37     public static final ListViaUsesKey USES_ONE_KEY = new ListViaUsesKey("one");
38     public static final ListViaUsesKey USES_TWO_KEY = new ListViaUsesKey("two");
39
40     private ListsBindingUtils() {
41
42     }
43
44     public static InstanceIdentifier<TopLevelList> path(final TopLevelListKey key) {
45         return TOP_PATH.child(TopLevelList.class, key);
46     }
47
48     public static InstanceIdentifier<NestedList> path(final TopLevelListKey top,final NestedListKey nested) {
49         return path(top).child(NestedList.class, nested);
50     }
51
52     public static InstanceIdentifier<ListViaUses> path(final TopLevelListKey top,final ListViaUsesKey uses) {
53         return path(top).augmentation(TreeComplexUsesAugment.class).child(ListViaUses.class, uses);
54     }
55
56     public static <T extends DataObject & Augmentation<TopLevelList>> InstanceIdentifier<T> path(
57             final TopLevelListKey key, final Class<T> augmentation) {
58         return path(key).augmentation(augmentation);
59     }
60
61     public static Top top(final TopLevelList... listItems) {
62         return new TopBuilder().setTopLevelList(Maps.uniqueIndex(Arrays.asList(listItems), TopLevelList::key)).build();
63     }
64
65     public static TopLevelList topLevelList(final TopLevelListKey key) {
66         return new TopLevelListBuilder().withKey(key).build();
67     }
68
69     public static TopLevelList topLevelList(final TopLevelListKey key, final TreeComplexUsesAugment augment) {
70         TopLevelListBuilder builder = new TopLevelListBuilder().withKey(key);
71         builder.addAugmentation(TreeComplexUsesAugment.class, augment);
72         return builder.build();
73     }
74
75     public static TreeComplexUsesAugment complexUsesAugment(final ListViaUsesKey... keys) {
76         Builder<ListViaUsesKey, ListViaUses> listViaUses = ImmutableMap.builderWithExpectedSize(keys.length);
77         for (ListViaUsesKey key : keys) {
78             listViaUses.put(key, new ListViaUsesBuilder().withKey(key).build());
79         }
80         return new TreeComplexUsesAugmentBuilder().setListViaUses(listViaUses.build()).build();
81     }
82
83     public static TreeLeafOnlyUsesAugment leafOnlyUsesAugment(final String leafFromGroupingValue) {
84
85         return new TreeLeafOnlyUsesAugmentBuilder().setLeafFromGrouping(leafFromGroupingValue).build();
86     }
87 }