Class MapUtils

java.lang.Object
org.aksw.commons.collections.MapUtils

public class MapUtils extends Object
Created by IntelliJ IDEA. User: raven Date: 4/22/11 Time: 2:36 PM To change this template use File | Settings | File Templates.
  • Constructor Details

    • MapUtils

      public MapUtils()
  • Method Details

    • addWithIntegerAutoIncrement

      public static <T> int addWithIntegerAutoIncrement(Map<T,Integer> map, T key)
    • addWithLongAutoIncrement

      public static <T> long addWithLongAutoIncrement(Map<T,Long> map, T key)
    • removeAll

      public static void removeAll(Map<?,?> map, Iterable<?> items)
    • putForAll

      public static <K, V> void putForAll(Map<K,V> map, Iterable<K> keys, V value)
      Set the same value for a given set of keys
      Parameters:
      map -
      keys -
      value -
    • isCompatible

      public static <K, V> boolean isCompatible(Map<? extends K,? extends V> a, Map<? extends K,? extends V> b)
      Compatible means that merging the two maps would not result in the same key being mapped to distinct values. Or put differently: The union of the two maps retains a functional mapping.
      Type Parameters:
      K -
      V -
      Parameters:
      a -
      b -
      Returns:
    • isCompatible

      public static <K, V> boolean isCompatible(Set<? extends K> keysToTest, Map<? extends K,? extends V> a, Map<? extends K,? extends V> b)
    • isPartiallyCompatible

      @Deprecated public static <K, V> boolean isPartiallyCompatible(Map<K,V> a, Map<K,V> b)
      Deprecated.
    • reverse

      public static <K, V> com.google.common.collect.Multimap<V,K> reverse(Map<K,V> map)
    • getOrElse

      public static <K, V> V getOrElse(Map<? extends K,? extends V> map, K key, V elze)
    • createChainMap

      public static <K, V> Map<K,V> createChainMap(Map<K,?> a, Map<?,V> b)
    • getOrCreate

      public static <K, V> V getOrCreate(Map<K,V> map, K key, Class<V> clazz, Object... ctorArgs)
    • mergeCompatible

      public static <K, V, R extends Map<K, V>> R mergeCompatible(Iterable<? extends Map<? extends K,? extends V>> maps, Supplier<R> resultSupplier)
      Find a mapping of variables from cand to query, such that the pattern of cand becomes a subset of that of query null if no mapping can be established
      Parameters:
      query -
      cand -
      Returns:
    • mergeCompatible

      public static <K, V, R extends Map<K, V>> R mergeCompatible(Map<? extends K,? extends V> a, Map<? extends K,? extends V> b, Supplier<R> resultSupplier)
    • union

      public static <K, V> Map<K,V> union(Map<K,? extends V> a, Map<K,? extends V> b)
      Returns a view of the union of two maps. For all keys k, if either map contains a value for k, the returned map contains that value. If both maps contain a value for the same key, this map contains the value in the second of the two provided maps.
    • union

      public static <K, V> Map<K,V> union(Map<K,? extends V> a, Map<K,? extends V> b, BinaryOperator<V> conflictHandler)
      Returns a view of the union of two maps. For all keys k, if either map contains a value for k, the returned map contains that value. If both maps contain a value for the same key, the conflict is resolved with the provided function.
    • difference

      public static <K, V> Map<K,V> difference(Map<K,? extends V> map, Set<? super K> deletions)
      Returns a view of the map where all keys present in 'deletions' are hidden
    • index

      public static <K, V> Map<K,V> index(Collection<? extends K> keys, Function<K,V> fn)
    • indexIdentity

      public static <K, V> Map<K,V> indexIdentity(Collection<? extends K> keys, Function<K,V> fn)
    • index

      public static <K, V> Map<K,V> index(Collection<? extends K> keys, Function<K,V> fn, Map<K,V> result)
    • transformKeys

      public static <K, V> Map<K,V> transformKeys(Map<K,V> original, Function<? super K,? extends K> map)
    • putWithRemoveOnNull

      public static <K, V> V putWithRemoveOnNull(Map<K,V> map, K key, V value)
      Put a key value pair. Removes the key if the value is null. Returns the prior value (null if there was none).