Merge "Reformat sdnr devicemanager-oran to ONAP code style"
[ccsdk/features.git] / sdnr / wt / devicemanager-onf / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf / ifpac / equipment / 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.onf.ifpac.equipment;
19
20 import java.util.HashMap;
21 import java.util.List;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
25 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
26
27 /**
28  * ValueNameList is an access Wrapper to NETCONF Extension lists
29  * Class is a specialized HashMap.
30  */
31 public class ValueNameList extends HashMap<String, String> {
32
33     private static final long serialVersionUID = 1L;
34
35     /**
36      * Create ValueNameList for NETCONF extensions
37      * @param extensionList Parameters as received from device. Could be null.
38      */
39     public void put(@Nullable List<Extension> extensionList) {
40
41         if (extensionList != null) {
42             String name;
43             String value;
44
45             for (Extension e : extensionList) {
46                 name = e.getValueName();
47                 value = e.getValue();
48                 if (name != null && value != null) {
49                     put(name, value);
50                 }
51             }
52         }
53     }
54
55     /**
56      * Return value or null
57      * @param name key for element
58      * @return value if key exists; if not nul
59      */
60     public String getOrNull(String name) {
61         return containsKey(name) ? get(name) : null;
62     }
63
64     /**
65      * Get element as id list
66      * @param name key of element
67      * @param topLevelEqUuidList as input to add elements
68      * @return List<UniversalId>
69      */
70     public  @NonNull List<UniversalId> getAsUniversalIdList(String name, List<UniversalId> topLevelEqUuidList) {
71         if (containsKey(name)) {
72             String[] result = get(name).split(",\\s*");
73             if (result.length > 0) {
74                 for (String e : result) {
75                     topLevelEqUuidList.add(new UniversalId(e));
76                 }
77             }
78         }
79         return topLevelEqUuidList;
80     }
81
82 }