X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-base%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Fbase%2FPfUtils.java;h=57d23450a2c98fc51cc1eca88b96fe6fb313c07f;hb=4c4946e339942863e73e20726dd95aaacfcfb5a6;hp=d5b70d78ad75a057f407dcd63a01c2e4d07f6d9d;hpb=ab145590ffdf99b9f4e132e5f20241099d6c5cbe;p=policy%2Fmodels.git diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java index d5b70d78a..57d23450a 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java @@ -22,6 +22,7 @@ package org.onap.policy.models.base; import java.lang.reflect.InvocationTargetException; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -29,6 +30,8 @@ import java.util.Map.Entry; import java.util.function.Function; import java.util.stream.Collectors; import javax.ws.rs.core.Response; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; /** * Utility class for Policy Framework concept utilities. @@ -67,6 +70,37 @@ public final class PfUtils { return 0; } + /** + * Compare two collections of the same type, nulls are allowed. + * + * @param leftCollection the first collection + * @param rightCollection the second collection + * @return a measure of the comparison + */ + public static int compareCollections(final Collection leftCollection, final Collection rightCollection) { + if (CollectionUtils.isEmpty(leftCollection) && CollectionUtils.isEmpty(rightCollection)) { + return 0; + } + + return compareObjects(leftCollection, rightCollection); + } + + + /** + * Compare two maps of the same type, nulls are allowed. + * + * @param leftMap the first map + * @param rightMap the second map + * @return a measure of the comparison + */ + public static int compareMaps(final Map leftMap, final Map rightMap) { + if (MapUtils.isEmpty(leftMap) && MapUtils.isEmpty(rightMap)) { + return 0; + } + + return compareObjects(leftMap, rightMap); + } + /** * Convenience method to apply a mapping function to all of the elements of a list, generating a new list. *