From 53fe02c107eae2f45abfee02e5b56a8ab3c09523 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 23 Aug 2021 17:10:00 -0400 Subject: More lombok for apex-pdp Added lombok to auth thru context-management, excluding basic-model and context-model. Issue-ID: POLICY-3391 Change-Id: I1c3a69d52d3bc65a99126ad44126e5a97424c66f Signed-off-by: Jim Hahn --- .../policy/apex/model/utilities/TreeMapUtils.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'model/utilities/src/main/java/org') diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java index 6daa6864a..3f369c0e0 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java @@ -23,7 +23,9 @@ package org.onap.policy.apex.model.utilities; import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.NavigableMap; import lombok.AccessLevel; @@ -75,4 +77,50 @@ public final class TreeMapUtils { } return foundNodes; } + + /** + * Compares two maps. + * @param Key type + * @param Value type + * @param leftMap left map + * @param rightMap right map + * @return an integer indicating how different the maps are + */ + @SuppressWarnings("unchecked") + public static int compareMaps(Map, ? extends Comparable> leftMap, + Map, ? extends Comparable> rightMap) { + if (leftMap == rightMap) { + return 0; + } + + Iterator leftIt = leftMap.entrySet().iterator(); + Iterator rightIt = rightMap.entrySet().iterator(); + + while (leftIt.hasNext() && rightIt.hasNext()) { + Map.Entry leftEntry = (Entry) leftIt.next(); + Map.Entry rightEntry = (Entry) rightIt.next(); + + K leftKey = (K) leftEntry.getKey(); + K rightKey = (K) rightEntry.getKey(); + int result = ((Comparable) leftKey).compareTo(rightKey); + if (result != 0) { + return result; + } + + V leftValue = (V) leftEntry.getValue(); + V rightValue = (V) rightEntry.getValue(); + result = ((Comparable) leftValue).compareTo(rightValue); + if (result != 0) { + return result; + } + } + + if (leftIt.hasNext()) { + return 1; + } else if (rightIt.hasNext()) { + return -1; + } else { + return 0; + } + } } -- cgit 1.2.3-korg