diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2024-11-27 17:31:23 +0000 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-11-27 19:17:42 +0000 |
commit | 541c25e33adf734dec724809f76cbcec3a86c0ce (patch) | |
tree | 4d26f25520297c4064d732f6161c3597fdd9fa94 | |
parent | 10506e09338ecd48cdb38602a67e530f41e75081 (diff) |
Minor refactor of CPS rest controller
Use streams to simplify logic
Issue-ID: CPS-2416
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I1c37ac9c2fa7543e94f8cd60447f4a879a7376f7
-rw-r--r-- | cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java index b425333f9e..55a1886ce7 100644 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java @@ -25,9 +25,9 @@ package org.onap.cps.rest.controller; import io.micrometer.core.annotation.Timed; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.CpsQueryService; @@ -126,17 +126,8 @@ public class QueryRestController implements CpsQueryApi { : (int) Math.ceil((double) totalAnchors / paginationOption.getPageSize()); } - private Map<String, List<DataNode>> groupDataNodesPerAnchor(final Collection<DataNode> dataNodes) { - final Map<String, List<DataNode>> dataNodesMapForAnchor = new HashMap<>(); - for (final DataNode dataNode : dataNodes) { - List<DataNode> dataNodesInAnchor = dataNodesMapForAnchor.get(dataNode.getAnchorName()); - if (dataNodesInAnchor == null) { - dataNodesInAnchor = new ArrayList<>(); - dataNodesMapForAnchor.put(dataNode.getAnchorName(), dataNodesInAnchor); - } - dataNodesInAnchor.add(dataNode); - } - return dataNodesMapForAnchor; + private static Map<String, List<DataNode>> groupDataNodesPerAnchor(final Collection<DataNode> dataNodes) { + return dataNodes.stream().collect(Collectors.groupingBy(DataNode::getAnchorName)); } private ResponseEntity<Object> executeNodesByDataspaceQueryAndCreateResponse(final String dataspaceName, |