From 541c25e33adf734dec724809f76cbcec3a86c0ce Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Wed, 27 Nov 2024 17:31:23 +0000 Subject: Minor refactor of CPS rest controller Use streams to simplify logic Issue-ID: CPS-2416 Signed-off-by: danielhanrahan Change-Id: I1c37ac9c2fa7543e94f8cd60447f4a879a7376f7 --- .../org/onap/cps/rest/controller/QueryRestController.java | 15 +++------------ 1 file 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> groupDataNodesPerAnchor(final Collection dataNodes) { - final Map> dataNodesMapForAnchor = new HashMap<>(); - for (final DataNode dataNode : dataNodes) { - List dataNodesInAnchor = dataNodesMapForAnchor.get(dataNode.getAnchorName()); - if (dataNodesInAnchor == null) { - dataNodesInAnchor = new ArrayList<>(); - dataNodesMapForAnchor.put(dataNode.getAnchorName(), dataNodesInAnchor); - } - dataNodesInAnchor.add(dataNode); - } - return dataNodesMapForAnchor; + private static Map> groupDataNodesPerAnchor(final Collection dataNodes) { + return dataNodes.stream().collect(Collectors.groupingBy(DataNode::getAnchorName)); } private ResponseEntity executeNodesByDataspaceQueryAndCreateResponse(final String dataspaceName, -- cgit 1.2.3-korg