ActivitySpec - Correcting logger messages
[sdc.git] / common / openecomp-tosca-datatype / src / main / java / org / openecomp / sdc / tosca / services / DataModelCloneUtil.java
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
21 package org.openecomp.sdc.tosca.services;
22
23
24 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
25 import org.openecomp.sdc.tosca.datatypes.model.Constraint;
26 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
27
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.stream.Collectors;
32
33 public class DataModelCloneUtil {
34
35   /**
36    * Clone constraints list.
37    *
38    * @param constraints the constraints
39    * @return the list
40    */
41   public static List<Constraint> cloneConstraints(List<Constraint> constraints) {
42
43     if (constraints == null) {
44       return null;
45     }
46     return constraints.stream().map(Constraint::clone).collect(Collectors.toList());
47   }
48
49   /**
50    * Clone property definitions map.
51    *
52    * @param propertyDefinitions the property definitions
53    * @return the map
54    */
55   public static Map<String, PropertyDefinition> clonePropertyDefinitions(
56       Map<String, PropertyDefinition> propertyDefinitions) {
57
58     if (propertyDefinitions == null) {
59       return null;
60     }
61     Map<String, PropertyDefinition> clonedProperties = new HashMap<>();
62     for (String propertyKey : propertyDefinitions.keySet()) {
63       clonedProperties.put(propertyKey, propertyDefinitions.get(propertyKey).clone());
64     }
65
66     return clonedProperties;
67   }
68
69   /**
70    * Clone attribute definitions map.
71    *
72    * @param attributeDefinitions the attribute definitions
73    * @return the map
74    */
75   public static Map<String, AttributeDefinition> cloneAttributeDefinitions(
76       Map<String, AttributeDefinition> attributeDefinitions) {
77
78     if (attributeDefinitions == null) {
79       return null;
80     }
81     Map<String, AttributeDefinition> clonedAttributeDefinitions = new HashMap<>();
82     for (String attributeKey : attributeDefinitions.keySet()) {
83       clonedAttributeDefinitions.put(attributeKey, attributeDefinitions.get(attributeKey).clone());
84     }
85
86     return clonedAttributeDefinitions;
87   }
88
89   /**
90    * Clone valid source types list.
91    *
92    * @param validSourceTypes the valid source types
93    * @return the list
94    */
95   public static List<String> cloneValidSourceTypes(List<String> validSourceTypes) {
96
97     if (validSourceTypes == null) {
98       return null;
99     }
100
101     return validSourceTypes.stream().collect(Collectors.toList());
102   }
103 }