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.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.Map.Entry;
28 import java.util.function.Predicate;
29 import java.util.stream.Collectors;
31 import org.codehaus.jackson.annotate.JsonCreator;
32 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
33 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
36 public class ListDataDefinition<T extends ToscaDataDefinition> extends ToscaDataDefinition {
38 protected List<T> listToscaDataDefinition;
40 public ListDataDefinition(ListDataDefinition<T> cdt) {
42 listToscaDataDefinition = cdt.listToscaDataDefinition;
47 public ListDataDefinition(List<T> listToscaDataDefinition) {
49 this.listToscaDataDefinition = listToscaDataDefinition;
52 public ListDataDefinition() {
56 public List<T> getListToscaDataDefinition() {
57 return listToscaDataDefinition;
60 public void add(T value) {
61 if (listToscaDataDefinition == null) {
62 listToscaDataDefinition = new ArrayList<T>();
64 listToscaDataDefinition.add(value);
67 public void delete(T value) {
68 if (listToscaDataDefinition != null) {
69 listToscaDataDefinition.remove(value);
74 public void setOwnerIdIfEmpty(String ownerId) {
75 if (listToscaDataDefinition != null) {
76 listToscaDataDefinition.forEach(e -> e.setOwnerIdIfEmpty(ownerId));
81 public <S extends ToscaDataDefinition> S mergeFunction(S other, boolean allowDefaultValueOverride){
82 Map<String, T> mapByName = listToMapByName(listToscaDataDefinition);
83 List<T> otherList = ((ListDataDefinition)other).getListToscaDataDefinition();
84 for(T item : otherList){
85 mapByName.merge((String)item.getToscaPresentationValue(JsonPresentationFields.NAME), item, (thisItem, otherItem) -> thisItem.mergeFunction(otherItem, allowDefaultValueOverride));
87 ((ListDataDefinition)other).listToscaDataDefinition = mapByName.values().stream().collect(Collectors.toList());
92 public boolean findUidMatch(String uid){
93 return listToscaDataDefinition.stream()
94 .anyMatch(p -> p.findUidMatch(uid));