com.twitter.common.collections
Class Multimaps

java.lang.Object
  extended by com.twitter.common.collections.Multimaps

public final class Multimaps
extends Object

Utility class for functions related to Multimaps in the java collections library.


Method Summary
static
<K> Set<K>
getLargeGroups(Multimap<K,?> map, int minSize)
          Returns the set of keys associated with groups of a size greater than or equal to a given size.
static
<K> Set<K>
getLargestGroups(Multimap<K,?> map, int topValues)
          Returns the set of keys associated with the largest values in the multimap.
static
<K,V> Multimap<K,V>
prune(Multimap<K,V> map, int minSize)
          Convenience method to prune key/values pairs where the size of the value collection is below a threshold.
static
<K,V> Multimap<K,V>
prune(Multimap<K,V> map, Predicate<Collection<V>> filterRule)
          Prunes a multimap based on a predicate, returning the pruned values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

prune

public static <K,V> Multimap<K,V> prune(Multimap<K,V> map,
                                        Predicate<Collection<V>> filterRule)
Prunes a multimap based on a predicate, returning the pruned values. The input map will be modified.

Type Parameters:
K - The key type in the multimap.
V - The value type in the multimap.
Parameters:
map - The multimap to prune.
filterRule - The pruning rule. When the predicate returns false for an entry, it will be pruned, otherwise it will be retained.
Returns:
A new multimap, containing the pruned keys/values.

prune

public static <K,V> Multimap<K,V> prune(Multimap<K,V> map,
                                        int minSize)
Convenience method to prune key/values pairs where the size of the value collection is below a threshold.

Type Parameters:
K - The key type in the multimap.
V - The value type in the multimap.
Parameters:
map - The multimap to prune.
minSize - The minimum size for retained value collections.
Returns:
A new multimap, containing the pruned keys/values.

getLargeGroups

public static <K> Set<K> getLargeGroups(Multimap<K,?> map,
                                        int minSize)
Returns the set of keys associated with groups of a size greater than or equal to a given size.

Type Parameters:
K - The key type for the multimap.
Parameters:
map - The multimap to search.
minSize - The minimum size to return associated keys for.
Returns:
The keys associated with groups of size greater than or equal to minSize.

getLargestGroups

public static <K> Set<K> getLargestGroups(Multimap<K,?> map,
                                          int topValues)
Returns the set of keys associated with the largest values in the multimap.

Parameters:
map - The multimap to search.
topValues - Number of groupings to find the keys for.
Returns:
The keys associated with the largest groups, of maximum size topValues.