Class PersistentSortedMaps


  • public final class PersistentSortedMaps
    extends Object
    Utility class for PersistentSortedMaps.

    Currently this class provides a merge operation. The result of merging two maps is defined as a map whose keyset is the union of the keyset of both input maps. The values of the resulting map are the corresponding values of the input maps as long as they are not differing. Differing values for one key are resolved by passing them to a callback function.

    • Method Detail

      • merge

        public static <K extends Comparable<? super K>,​V> PersistentSortedMap<K,​V> merge​(PersistentSortedMap<K,​V> map1,
                                                                                                     PersistentSortedMap<K,​V> map2,
                                                                                                     PersistentSortedMaps.MergeConflictHandler<K,​V> conflictHandler)
        Merge two PersistentSortedMaps. The result has all key-value pairs where the key is only in one of the map, those which are identical in both map, and for those keys that have a different value in both maps a handler is called, and the result is put in the resulting map.
        Parameters:
        map1 - The first map.
        map2 - The second map.
        conflictHandler - The handler that is called for a key with two different values.
        Returns:
        The merged map.
      • merge

        public static <K extends Comparable<? super K>,​V> PersistentSortedMap<K,​V> merge​(PersistentSortedMap<K,​V> map1,
                                                                                                     PersistentSortedMap<K,​V> map2,
                                                                                                     Equivalence<? super V> valueEquals,
                                                                                                     PersistentSortedMaps.MergeConflictHandler<? super K,​V> conflictHandler,
                                                                                                     MapsDifference.Visitor<? super K,​? super V> collectDifferences)
        Merge two PersistentSortedMaps. The result has all key-value pairs where the key is only in one of the map, those which are identical in both map, and for those keys that have a different value in both maps a handler is called, and the result is put in the resulting map.

        Optionally you can pass a list that will receive all encountered differences, i.e., keys which are present in only one map, or have different values. The list will contain triples with key and both values, where missing values are replaced by null.

        Implementation note: It may be faster to call this method with the bigger of the input maps as the first parameter.

        Parameters:
        map1 - The first map.
        map2 - The second map.
        valueEquals - The Equivalence that will determine whether two values are considered equal.
        conflictHandler - The handler that is called for a key with two different values.
        collectDifferences - A visitor which receives keys with two different values or keys that are present only in one of the maps.
        Returns:
        The merged map.