diff options
author | Jim Hahn <jrh3@att.com> | 2021-08-23 17:10:00 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-08-24 09:22:38 -0400 |
commit | 53fe02c107eae2f45abfee02e5b56a8ab3c09523 (patch) | |
tree | 35c9646b7c629485f6241ed1b48b853305e585ac /model/utilities/src/main/java/org | |
parent | c3d0b33c9facf49e37e9ab58412227ff44c66363 (diff) |
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 <jrh3@att.com>
Diffstat (limited to 'model/utilities/src/main/java/org')
-rw-r--r-- | model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TreeMapUtils.java | 48 |
1 files changed, 48 insertions, 0 deletions
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 <K> Key type + * @param <V> Value type + * @param leftMap left map + * @param rightMap right map + * @return an integer indicating how different the maps are + */ + @SuppressWarnings("unchecked") + public static <K, V> int compareMaps(Map<? extends Comparable<K>, ? extends Comparable<V>> leftMap, + Map<? extends Comparable<K>, ? extends Comparable<V>> 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<K>) leftKey).compareTo(rightKey); + if (result != 0) { + return result; + } + + V leftValue = (V) leftEntry.getValue(); + V rightValue = (V) rightEntry.getValue(); + result = ((Comparable<V>) leftValue).compareTo(rightValue); + if (result != 0) { + return result; + } + } + + if (leftIt.hasNext()) { + return 1; + } else if (rightIt.hasNext()) { + return -1; + } else { + return 0; + } + } } |