Class DefaultCollectionHelper

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.List<java.lang.Object> concatCollections​(java.util.Collection<java.lang.Object> first, java.util.Collection<java.lang.Object> second)
      Concatenates two collections.
      java.util.function.BinaryOperator<java.lang.Object> defaultDeepMergeFunction()
      Resolver for two Map values that have the same key.
      protected boolean isCollection​(java.lang.Object obj)
      Method to test whether the Object is a Collection or not.
      protected boolean isMap​(java.lang.Object obj)
      Method to test whether the Object is a Map or not.
      java.util.Map<java.lang.String,​java.lang.Object> mergeMaps​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> maps)
      Merges the list of maps.
      java.util.Map<java.lang.String,​java.lang.Object> mergeMaps​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> maps, java.util.function.BinaryOperator<java.lang.Object> mergeFunction)
      Merges the list of maps.
      java.util.Map<java.lang.String,​java.lang.Object> mergeMaps​(java.util.Map<java.lang.String,​java.lang.Object> firstMap, java.util.Map<java.lang.String,​java.lang.Object> secondMap, java.util.function.BinaryOperator<java.lang.Object> mergeFunction)
      Merges two maps.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultCollectionHelper

        public DefaultCollectionHelper()
    • Method Detail

      • mergeMaps

        public java.util.Map<java.lang.String,​java.lang.Object> mergeMaps​(java.util.Map<java.lang.String,​java.lang.Object> firstMap,
                                                                                java.util.Map<java.lang.String,​java.lang.Object> secondMap,
                                                                                java.util.function.BinaryOperator<java.lang.Object> mergeFunction)
        Description copied from interface: CollectionHelper
        Merges two maps. If a value already exists for a given key in a resulting map
        then the mergeFunction is used to resolve the issue.
        Specified by:
        mergeMaps in interface CollectionHelper
        Parameters:
        firstMap - the Map to merge
        secondMap - the Map to merge
        mergeFunction - the function used to resolve conflict for the same key
        Returns:
        the Map
      • mergeMaps

        public java.util.Map<java.lang.String,​java.lang.Object> mergeMaps​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> maps)
        Merges the list of maps.
        The default implementation uses CollectionHelper.defaultDeepMergeFunction()
        if a value already exists for a given key in a resulting map.
        Specified by:
        mergeMaps in interface CollectionHelper
        Parameters:
        maps - the List of Map.
        Returns:
        the Map
      • mergeMaps

        public java.util.Map<java.lang.String,​java.lang.Object> mergeMaps​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> maps,
                                                                                java.util.function.BinaryOperator<java.lang.Object> mergeFunction)
        Description copied from interface: CollectionHelper
        Merges the list of maps. If a value already exists for a given key in a resulting map
        then the mergeFunction is used to resolve the issue.
        Specified by:
        mergeMaps in interface CollectionHelper
        Parameters:
        maps - the List of Map.
        mergeFunction - the function used to resolve conflict for the same key
        Returns:
        the Map
      • defaultDeepMergeFunction

        public java.util.function.BinaryOperator<java.lang.Object> defaultDeepMergeFunction()
        Resolver for two Map values that have the same key. The default implementation has the following logic: - If two values are collections they will be concatenated - If two values are maps they will be merged using CollectionHelper.mergeMaps(List, BinaryOperator) - Otherwise the value from the second Map is returned
        Specified by:
        defaultDeepMergeFunction in interface CollectionHelper
        Returns:
        the BinaryOperator to merge two values with the same key.
      • isCollection

        protected boolean isCollection​(java.lang.Object obj)
        Method to test whether the Object is a Collection or not.
        Parameters:
        obj - the Object to test
        Returns:
        true if the Object is a Collection, false otherwise.
      • isMap

        protected boolean isMap​(java.lang.Object obj)
        Method to test whether the Object is a Map or not.
        Parameters:
        obj - the Object to test
        Returns:
        true if the Object is a Map, false otherwise.
      • concatCollections

        protected java.util.List<java.lang.Object> concatCollections​(java.util.Collection<java.lang.Object> first,
                                                                     java.util.Collection<java.lang.Object> second)
        Concatenates two collections.
        Parameters:
        first - the first Collection
        second - the second Collection
        Returns:
        the concatenation of two collections