Package org.sosy_lab.common.collect
Class PersistentSortedMaps
- java.lang.Object
-
- org.sosy_lab.common.collect.PersistentSortedMaps
-
public final class PersistentSortedMaps extends Object
Utility class forPersistentSortedMap
s.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
PersistentSortedMaps.MergeConflictHandler<K,V>
A callback that is used when a key with two different values is encountered during the merge of two maps.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
PersistentSortedMaps.MergeConflictHandler<K,V>getExceptionMergeConflictHandler()
Returns aPersistentSortedMaps.MergeConflictHandler
that will always throw anIllegalArgumentException
.static <K,V extends Comparable<? super V>>
PersistentSortedMaps.MergeConflictHandler<K,V>getMaximumMergeConflictHandler()
Returns aPersistentSortedMaps.MergeConflictHandler
that will always return the maximum (according to the natural order).static <K,V extends Comparable<? super V>>
PersistentSortedMaps.MergeConflictHandler<K,V>getMinimumMergeConflictHandler()
Returns aPersistentSortedMaps.MergeConflictHandler
that will always return the minimum (according to the natural order).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.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.
-
-
-
Method Detail
-
getExceptionMergeConflictHandler
public static <K,V> PersistentSortedMaps.MergeConflictHandler<K,V> getExceptionMergeConflictHandler()
Returns aPersistentSortedMaps.MergeConflictHandler
that will always throw anIllegalArgumentException
. Use this in cases where you never expect differing values for one key.
-
getMaximumMergeConflictHandler
public static <K,V extends Comparable<? super V>> PersistentSortedMaps.MergeConflictHandler<K,V> getMaximumMergeConflictHandler()
Returns aPersistentSortedMaps.MergeConflictHandler
that will always return the maximum (according to the natural order). This may not be used if the map containsnull
as value.
-
getMinimumMergeConflictHandler
public static <K,V extends Comparable<? super V>> PersistentSortedMaps.MergeConflictHandler<K,V> getMinimumMergeConflictHandler()
Returns aPersistentSortedMaps.MergeConflictHandler
that will always return the minimum (according to the natural order). This may not be used if the map containsnull
as value.
-
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
- TheEquivalence
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.
-
-