Class CollectionCmp<B,W>
- java.lang.Object
-
- io.github.nejckorasa.CollectionCmp<B,W>
-
public final class CollectionCmp<B,W> extends Object
Class to compare collections of objects
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CmpResult<B,W>
compare(Function<B,Serializable> baseKeyExtractor, Function<W,Serializable> workingKeyExtractor, BiFunction<B,W,Boolean> equalsFunction)
Compares collections.static <B> CollectionCmpSameBuilder<B>
of(Collection<B> baseList, Collection<B> workingList, Function<B,Serializable> keyExtractor)
Initializes builderCollectionCmpBuilder
to compare collections of same object types (baseList and workingList).static <B,W>
CollectionCmpBuilder<B,W>of(Collection<B> baseList, Collection<W> workingList, Function<B,Serializable> baseKeyExtractor, Function<W,Serializable> workingKeyExtractor)
Initializes builderCollectionCmpBuilder
to compare collections of different object types (baseList and workingList).
-
-
-
Method Detail
-
of
public static <B,W> CollectionCmpBuilder<B,W> of(Collection<B> baseList, Collection<W> workingList, Function<B,Serializable> baseKeyExtractor, Function<W,Serializable> workingKeyExtractor)
Initializes builderCollectionCmpBuilder
to compare collections of different object types (baseList and workingList).See
of(Collection, Collection, Function)
to compare collections of objects of the same type.- Parameters:
baseList
- base list to compareworkingList
- working list to compare base list with- Returns:
- builder to configure
-
of
public static <B> CollectionCmpSameBuilder<B> of(Collection<B> baseList, Collection<B> workingList, Function<B,Serializable> keyExtractor)
Initializes builderCollectionCmpBuilder
to compare collections of same object types (baseList and workingList).See
of(Collection, Collection, Function, Function)
to compare collections of objects of different type.- Parameters:
baseList
- base list to compareworkingList
- working list to compare base list with- Returns:
- builder to configure
-
compare
public CmpResult<B,W> compare(Function<B,Serializable> baseKeyExtractor, Function<W,Serializable> workingKeyExtractor, BiFunction<B,W,Boolean> equalsFunction)
Compares collections.Items from
baseList
andworkingList
are compared and merged into pairs based on keys configured by baseKeyExtractor and workingKeyExtractor. Items matched together by the same key are later compared using equalsFunction.Make sure that collections
baseList
andworkingList
can be partitioned usingCollectionPartitioner.canPartition(Collection, Function)
. If keys collide and partitioning is not successful, compare result will not always be correct.The end result contains all changes found between collections - added, updated, removed, same and different items. See
Diff
andCmpResult
.- Parameters:
baseKeyExtractor
- key extractor used to extract keys from items insidebaseList
workingKeyExtractor
- key extractor used to extract keys from items insideworkingList
equalsFunction
- equals function to compare items matched by key- Returns:
- compare result, containing all changes - information of added, updated, removed, different objects...
-
-