Class DefaultCollectionHelper
- java.lang.Object
-
- de.hybris.platform.cms2.common.service.impl.DefaultCollectionHelper
-
- All Implemented Interfaces:
CollectionHelper
public class DefaultCollectionHelper extends java.lang.Object implements CollectionHelper
Default implementation ofCollectionHelper.
-
-
Constructor Summary
Constructors Constructor Description 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 twoMapvalues that have the same key.protected booleanisCollection(java.lang.Object obj)Method to test whether theObjectis aCollectionor not.protected booleanisMap(java.lang.Object obj)Method to test whether theObjectis aMapor 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.
-
-
-
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:CollectionHelperMerges 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:
mergeMapsin interfaceCollectionHelper- Parameters:
firstMap- theMapto mergesecondMap- theMapto mergemergeFunction- 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 usesCollectionHelper.defaultDeepMergeFunction()
if a value already exists for a given key in a resulting map.- Specified by:
mergeMapsin interfaceCollectionHelper- Parameters:
maps- theListofMap.- 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:CollectionHelperMerges 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:
mergeMapsin interfaceCollectionHelper- Parameters:
maps- theListofMap.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 twoMapvalues 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 usingCollectionHelper.mergeMaps(List, BinaryOperator)- Otherwise the value from the secondMapis returned- Specified by:
defaultDeepMergeFunctionin interfaceCollectionHelper- Returns:
- the
BinaryOperatorto merge two values with the same key.
-
isCollection
protected boolean isCollection(java.lang.Object obj)
Method to test whether theObjectis aCollectionor not.- Parameters:
obj- theObjectto test- Returns:
- true if the
Objectis aCollection, false otherwise.
-
isMap
protected boolean isMap(java.lang.Object obj)
Method to test whether theObjectis aMapor not.- Parameters:
obj- theObjectto test- Returns:
- true if the
Objectis aMap, 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 firstCollectionsecond- the secondCollection- Returns:
- the concatenation of two collections
-
-