2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.datatypes.elements;
23 import java.util.HashMap;
26 import org.codehaus.jackson.annotate.JsonCreator;
27 import org.codehaus.jackson.annotate.JsonValue;
28 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
30 public class MapDataDefinition <T extends ToscaDataDefinition> extends ToscaDataDefinition {
32 protected Map<String, T > mapToscaDataDefinition;
34 public MapDataDefinition(MapDataDefinition<T> cdt) {
36 mapToscaDataDefinition = cdt.mapToscaDataDefinition;
40 public MapDataDefinition(Map<String, T > mapToscaDataDefinition) {
42 this.mapToscaDataDefinition = mapToscaDataDefinition;
45 public MapDataDefinition() {
49 public Map<String, T > getMapToscaDataDefinition() {
50 return mapToscaDataDefinition;
53 public void put(String key, T value){
54 if(mapToscaDataDefinition == null){
55 mapToscaDataDefinition = new HashMap<String, T>();
57 mapToscaDataDefinition.put(key, value);
60 public void delete(String key){
61 if(mapToscaDataDefinition != null && mapToscaDataDefinition.containsKey(key)){
62 mapToscaDataDefinition.remove(key);
66 public T findByKey(String key){
68 if(mapToscaDataDefinition != null && mapToscaDataDefinition.containsKey(key)){
69 value = mapToscaDataDefinition.get(key);
74 public void setOwnerIdIfEmpty(String ownerId) {
75 if ( mapToscaDataDefinition != null ){
76 mapToscaDataDefinition.entrySet().forEach(e -> e.getValue().setOwnerIdIfEmpty(ownerId));
81 public String findKeyByItemUidMatch(String uid){
82 if(null == mapToscaDataDefinition)
84 Map.Entry<String, T> entry = mapToscaDataDefinition.entrySet().stream().filter(e ->
85 e.getValue().findUidMatch(uid))
86 .findAny().orElse(null);
89 return entry.getKey();