aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java79
1 files changed, 35 insertions, 44 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
index a77c150a91..ffb953c89e 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
@@ -13,65 +13,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.impl;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.converter.errors.CreateToscaObjectErrorBuilder;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.utils.CommonUtil;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
public class ToscaConverterUtil {
- private static final String DEFAULT = "default";
- private static final String DEFAULT_CAPITAL = "Default";
- private static final Set<String> DEFAULT_VALUE_KEYS;
+ private static final String DEFAULT = "default";
+ private static final String DEFAULT_CAPITAL = "Default";
+ private static final Set<String> DEFAULT_VALUE_KEYS;
- static {
- DEFAULT_VALUE_KEYS =
- Stream.of(DEFAULT, DEFAULT_CAPITAL).collect(Collectors.toSet());
- }
-
- private ToscaConverterUtil() {
- // static utility methods only, prevent instantiation
- }
-
- static <T> Optional<T> createObjectFromClass(String objectId,
- Object objectCandidate,
- Class<T> classToCreate) {
- try {
- return CommonUtil.createObjectUsingSetters(objectCandidate, classToCreate);
- } catch (Exception ex) {
- throw new CoreException(
- new CreateToscaObjectErrorBuilder(classToCreate.getSimpleName(), objectId)
- .build(), ex);
+ static {
+ DEFAULT_VALUE_KEYS = Stream.of(DEFAULT, DEFAULT_CAPITAL).collect(Collectors.toSet());
}
- }
-
- static Optional<Object> getDefaultValue(Object entryValue,
- Object objectToAssignDefaultValue) {
- if (!(entryValue instanceof Map)
- || Objects.isNull(objectToAssignDefaultValue)) {
- return Optional.empty();
+ private ToscaConverterUtil() {
+ // static utility methods only, prevent instantiation
}
- return Optional.ofNullable(getDefaultParameterValue((Map<String, Object>) entryValue));
- }
-
- private static Object getDefaultParameterValue(Map<String, Object> entryValue) {
- Object defaultValue = null;
- Set<String> keys = new HashSet<>(entryValue.keySet());
- keys.retainAll(DEFAULT_VALUE_KEYS);
+ static <T> Optional<T> createObjectFromClass(String objectId, Object objectCandidate, Class<T> classToCreate) {
+ try {
+ return CommonUtil.createObjectUsingSetters(objectCandidate, classToCreate);
+ } catch (Exception ex) {
+ throw new CoreException(new CreateToscaObjectErrorBuilder(classToCreate.getSimpleName(), objectId).build(), ex);
+ }
+ }
- if (CollectionUtils.isNotEmpty(keys)) {
- defaultValue = entryValue.get(keys.iterator().next());
+ static Optional<Object> getDefaultValue(Object entryValue, Object objectToAssignDefaultValue) {
+ if (!(entryValue instanceof Map) || Objects.isNull(objectToAssignDefaultValue)) {
+ return Optional.empty();
+ }
+ return Optional.ofNullable(getDefaultParameterValue((Map<String, Object>) entryValue));
}
- return defaultValue;
- }
+ private static Object getDefaultParameterValue(Map<String, Object> entryValue) {
+ Object defaultValue = null;
+ Set<String> keys = new HashSet<>(entryValue.keySet());
+ keys.retainAll(DEFAULT_VALUE_KEYS);
+ if (CollectionUtils.isNotEmpty(keys)) {
+ defaultValue = entryValue.get(keys.iterator().next());
+ }
+ return defaultValue;
+ }
}