1bb394d118daa7220ae5393d5ac277a9d0698a93
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.be.datatypes.elements;
21
22 import com.fasterxml.jackson.annotation.JsonCreator;
23 import com.fasterxml.jackson.annotation.JsonValue;
24 import java.util.HashMap;
25 import java.util.Map;
26 import lombok.NoArgsConstructor;
27
28 @NoArgsConstructor
29 public class MapListCapabilityDataDefinition extends MapDataDefinition<ListCapabilityDataDefinition> {
30
31     public MapListCapabilityDataDefinition(MapListCapabilityDataDefinition cdt) {
32         super(cdt);
33     }
34
35     @JsonCreator
36     public MapListCapabilityDataDefinition(Map<String, ListCapabilityDataDefinition> mapToscaDataDefinition) {
37         super(mapToscaDataDefinition);
38     }
39
40     @JsonValue
41     @Override
42     public Map<String, ListCapabilityDataDefinition> getMapToscaDataDefinition() {
43         return mapToscaDataDefinition;
44     }
45
46     public void add(String key, CapabilityDataDefinition value) {
47         if (mapToscaDataDefinition == null) {
48             mapToscaDataDefinition = new HashMap<>();
49             ListCapabilityDataDefinition newList = new ListCapabilityDataDefinition();
50             newList.add(value);
51             put(key, newList);
52         } else {
53             ListCapabilityDataDefinition existValue = mapToscaDataDefinition.get(key);
54             if (existValue == null) {
55                 ListCapabilityDataDefinition newList = new ListCapabilityDataDefinition();
56                 newList.add(value);
57                 put(key, newList);
58             } else {
59                 existValue.getListToscaDataDefinition().add(value);
60             }
61         }
62     }
63 }