org.aksw.commons.collections
Class MultiMaps

java.lang.Object
  extended by org.aksw.commons.collections.MultiMaps

public class MultiMaps
extends Object

Created by Claus Stadler Date: Oct 9, 2010 Time: 5:42:34 PM A set of static methods for treating a Map> as a multimap (or rather graphs, as keys may be mapped to an empty set of values)


Constructor Summary
MultiMaps()
           
 
Method Summary
static
<K,V> void
addAllKeys(Map<K,Set<V>> map, Iterable<K> keys)
           
static
<K,V> Set<V>
addKey(Map<K,Set<V>> map, K key)
           
static
<K,V> boolean
containsEntry(Map<K,Set<V>> map, K key, V value)
           
static
<K,V> Map<K,Set<V>>
copy(Map<K,Set<V>> source)
           
static
<T> Set<T>
getCommonParent(Map<T,? extends Collection<T>> map, T a, T b)
          Find the nearest set of nodes that are parents of both given nodes.
static
<K,V> void
put(Map<K,Set<V>> map, K key, V value)
           
static
<K,V> void
putAll(Map<K,Set<V>> map, K key, Collection<? extends V> vs)
           
static
<K,V> void
putAll(Map<K,Set<V>> target, Map<? extends K,? extends Set<? extends V>> source)
           
static
<K,V> Map<V,Set<K>>
reverse(Map<K,Set<V>> source)
          Creates a new map that is the reverse of the source
static
<K,V> Set<V>
safeGet(Map<K,? extends Collection<V>> map, Object key)
          This method returns an empty set (Collections.emptySet) for keys that are not in the map.
static
<K,V> Set<V>
safeGetAll(Map<K,? extends Collection<V>> map, Collection<?> keys)
          Returns the set of successors for a given set of keys
static
<K,V> Collection<V>
safeGetC(Map<K,? extends Collection<V>> map, Object key)
          TODO Add to collection utils
static
<T> Map<T,Set<T>>
transitiveClosure(Map<T,Set<T>> map)
           
static
<T> Map<T,Set<T>>
transitiveClosure(Map<T,Set<T>> map, boolean inPlace)
           
static
<T> Map<T,Set<T>>
transitiveClosureInPlace(Map<T,Set<T>> map)
           
static
<T> Set<T>
transitiveGet(Map<T,? extends Collection<T>> map, Object key)
           
static
<K,V> Collection<V>
values(Map<K,Set<V>> map)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiMaps

public MultiMaps()
Method Detail

putAll

public static <K,V> void putAll(Map<K,Set<V>> target,
                                Map<? extends K,? extends Set<? extends V>> source)

putAll

public static <K,V> void putAll(Map<K,Set<V>> map,
                                K key,
                                Collection<? extends V> vs)

put

public static <K,V> void put(Map<K,Set<V>> map,
                             K key,
                             V value)

containsEntry

public static <K,V> boolean containsEntry(Map<K,Set<V>> map,
                                          K key,
                                          V value)

values

public static <K,V> Collection<V> values(Map<K,Set<V>> map)

addKey

public static <K,V> Set<V> addKey(Map<K,Set<V>> map,
                                  K key)

addAllKeys

public static <K,V> void addAllKeys(Map<K,Set<V>> map,
                                    Iterable<K> keys)

copy

public static <K,V> Map<K,Set<V>> copy(Map<K,Set<V>> source)

reverse

public static <K,V> Map<V,Set<K>> reverse(Map<K,Set<V>> source)
Creates a new map that is the reverse of the source

Type Parameters:
K -
V -
Parameters:
source -
Returns:

safeGet

public static <K,V> Set<V> safeGet(Map<K,? extends Collection<V>> map,
                                   Object key)
This method returns an empty set (Collections.emptySet) for keys that are not in the map.

Type Parameters:
K -
V -
Parameters:
map -
key -
Returns:

safeGetAll

public static <K,V> Set<V> safeGetAll(Map<K,? extends Collection<V>> map,
                                      Collection<?> keys)
Returns the set of successors for a given set of keys

Type Parameters:
K -
V -
Parameters:
map -
keys -
Returns:

safeGetC

public static <K,V> Collection<V> safeGetC(Map<K,? extends Collection<V>> map,
                                           Object key)
TODO Add to collection utils

Type Parameters:
K -
V -
Parameters:
map -
key -
Returns:

transitiveGet

public static <T> Set<T> transitiveGet(Map<T,? extends Collection<T>> map,
                                       Object key)

transitiveClosure

public static <T> Map<T,Set<T>> transitiveClosure(Map<T,Set<T>> map)

transitiveClosure

public static <T> Map<T,Set<T>> transitiveClosure(Map<T,Set<T>> map,
                                                  boolean inPlace)

transitiveClosureInPlace

public static <T> Map<T,Set<T>> transitiveClosureInPlace(Map<T,Set<T>> map)

getCommonParent

public static <T> Set<T> getCommonParent(Map<T,? extends Collection<T>> map,
                                         T a,
                                         T b)
Find the nearest set of nodes that are parents of both given nodes.

Parameters:
map - A mapping from children to parents
a -
b -


Copyright © 2011. All Rights Reserved.