YANG Model update for A1 Adapter
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / base / netconf / container / ValueNameList.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * 
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container;
19
20 import java.util.HashMap;
21 import java.util.List;
22
23 import javax.annotation.Nonnull;
24 import javax.annotation.Nullable;
25
26 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
27 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
28
29 /**
30  * ValueNameList is an access Wrapper to NETCONF Extension lists
31  * Class is a specialized HashMap.
32  */
33 public class ValueNameList extends HashMap<String, String> {
34
35         private static final long serialVersionUID = 1L;
36
37         /**
38          * Create ValueNameList for NETCONF extensions
39          * @param extensionList Parameters as received from device. Could be null.
40          */
41         public void put(@Nullable List<Extension> extensionList) {
42
43                 if (extensionList != null) {
44                         String name;
45                         String value;
46
47                         for (Extension e : extensionList) {
48                                 name = e.getValueName();
49                                 value = e.getValue();
50                                 if (name != null && value != null) {
51                                         put(name, value);
52                                 }
53                         }
54                 }
55         }
56
57         /**
58          * Return value or null
59          * @param name key for element
60          * @return value if key exists; if not nul
61          */
62         public String getOrNull(String name) {
63                 return containsKey(name) ? get(name) : null;
64         }
65
66         /**
67          * Get element as id list
68          * @param name key of element
69          * @param topLevelEqUuidList as input to add elements
70          * @return List<UniversalId>
71          */
72         public  @Nonnull List<UniversalId> getAsUniversalIdList(String name, List<UniversalId> topLevelEqUuidList) {
73                 if (containsKey(name)) {
74                         String[] result = get(name).split(",\\s*");
75                         if (result.length > 0) {
76                                 for (String e : result) {
77                                         topLevelEqUuidList.add(new UniversalId(e));
78                                 }
79                         }
80                 }
81                 return topLevelEqUuidList;
82         }
83
84 }