aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/model
diff options
context:
space:
mode:
authorAmichai Hemli <amichai.hemli@intl.att.com>2019-12-09 18:11:45 +0000
committerGerrit Code Review <gerrit@onap.org>2019-12-09 18:11:45 +0000
commit299190fbe78defb71a717e446c0f394ea7404dfe (patch)
tree2d88704ec31c2fc1a522911b62b247f88cac99dd /vid-app-common/src/main/java/org/onap/vid/model
parentcbcca6ed1783b41eb10fbcaa456f3a1cfb8c9a39 (diff)
parent8878a06f6023c4fc2fc03656c9e2012bde80bb70 (diff)
Merge "Extract getExistingCounterMap from AAITreeConverter to ModelUtil"
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/model')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java53
1 files changed, 20 insertions, 33 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java b/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java
index 45e100fb1..6c56a464b 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java
+++ b/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java
@@ -20,39 +20,26 @@
package org.onap.vid.model;
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.counting;
+import static java.util.stream.Collectors.groupingBy;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.vid.mso.model.ModelInfo;
+import org.springframework.stereotype.Component;
+
+@Component
public class ModelUtil {
- /**
- * Gets the tags for the given element according to the configured namespace
- * @param namespaces the namespace list from the configuration
- * @param constantValue the constant portion of the tag name, i.e. resource.vf...
- * @return the tags
- */
- public static String[] getTags ( String[] namespaces, String constantValue ) {
- String[] tags;
- if ( namespaces == null || namespaces.length == 0 ) {
- return null;
- }
- int le = namespaces.length;
- tags = new String[le];
- for ( int i = 0; i < le; i++ ) {
- tags[i] = namespaces[i] + constantValue;
- }
- return (tags);
- }
- /**
- * Determine if a note template type matches a set of configurable tags
- * @param type the node template type
- * @param tags the model configurable namespaces
- * @return true if type starts with a tag in the array, false otherwise
- */
- public static boolean isType ( String type, String[] tags ) {
- if ( (tags != null) && (tags.length > 0) ) {
- for ( int i = 0; i < tags.length; i++ ) {
- if ( type.startsWith (tags[i]) ) {
- return (true);
- }
- }
- }
- return (false);
+ public <T> Map<String, Long> getExistingCounterMap(Map<String, T> nodeList, Function<T, ModelInfo> modelInfoExtractor) {
+ return nodeList.values().stream()
+ .map(it -> {
+ ModelInfo modelInfo = modelInfoExtractor.apply(it);
+ return StringUtils.defaultIfEmpty(modelInfo.getModelCustomizationId(), modelInfo.getModelVersionId());
+ })
+ .filter(Objects::nonNull)
+ .collect(groupingBy(identity(), counting()));
}
}