b15135b096da0e9e73ed838f357888a41b6f84c3
[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 MapListRequirementDataDefinition extends MapDataDefinition<ListRequirementDataDefinition> {
30
31     public MapListRequirementDataDefinition(MapListRequirementDataDefinition cdt) {
32         super(cdt);
33     }
34
35     @JsonCreator
36     public MapListRequirementDataDefinition(Map<String, ListRequirementDataDefinition> mapToscaDataDefinition) {
37         super(mapToscaDataDefinition);
38     }
39
40     @JsonValue
41     @Override
42     public Map<String, ListRequirementDataDefinition> getMapToscaDataDefinition() {
43         return mapToscaDataDefinition;
44     }
45
46     public void add(String key, RequirementDataDefinition value) {
47         if (mapToscaDataDefinition == null) {
48             mapToscaDataDefinition = new HashMap<>();
49             ListRequirementDataDefinition newList = new ListRequirementDataDefinition();
50             newList.add(value);
51             put(key, newList);
52         } else {
53             ListRequirementDataDefinition existValue = mapToscaDataDefinition.get(key);
54             if (existValue == null) {
55                 ListRequirementDataDefinition newList = new ListRequirementDataDefinition();
56                 newList.add(value);
57                 put(key, newList);
58             } else {
59                 existValue.getListToscaDataDefinition().add(value);
60             }
61         }
62     }
63 }