Holger's
Java API

com.antelmann.util
Class Sets

java.lang.Object
  extended by com.antelmann.util.Sets

public class Sets
extends Object

utility class for calculations on sets, lists and other collections.

Author:
Holger Antelmann

Method Summary
static
<T> List<T>
asList(Collection<T> col)
          convenience method to display a collection in a JList for example
static
<T> Set<? extends T>
difference(Set<? extends T> set1, Set<? extends T> set2)
          returns a set that contains all elements from set1 that are not in set2
static
<T> ArrayList<T>
extract(Collection<T> col, Filter<T> filter)
          returns a new Collection that will only contain those elements that passed the filter.
static
<T> ArrayList<T>
filter(Collection<T> col, Filter<T> filter)
          filters all objects out of the given col that are not accepted by the filter; the dropout is returned as a separate Collection.
static
<T,P> HashMap<P,ArrayList<T>>
groupBy(Collection<T> col, PatternExtractor<T,P> extractor)
          splits the given collection into many, where the extractor is the discriminator
static
<K,V> K
keyForValue(Map<K,V> map, V value)
           
static
<K,V> Set<K>
keysForValue(Map<K,V> map, V value)
           
static
<T> HashSet<T>
makeSet(T[] array)
           
static
<T> HashSet<T>
makeSet(T[] array, boolean ignoreDuplicates)
           
static
<K,V> Map<V,K>
reverseMap(Map<K,V> map)
          generates a reversed map, mapping values to keys
static boolean same(Map m1, Map m2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asList

public static <T> List<T> asList(Collection<T> col)
convenience method to display a collection in a JList for example


filter

public static <T> ArrayList<T> filter(Collection<T> col,
                                      Filter<T> filter)
filters all objects out of the given col that are not accepted by the filter; the dropout is returned as a separate Collection. The given col Object will contain only elements that passed the filter.


extract

public static <T> ArrayList<T> extract(Collection<T> col,
                                       Filter<T> filter)
returns a new Collection that will only contain those elements that passed the filter. The filter may be null, in which case the returned list contains all elements.


groupBy

public static <T,P> HashMap<P,ArrayList<T>> groupBy(Collection<T> col,
                                                    PatternExtractor<T,P> extractor)
splits the given collection into many, where the extractor is the discriminator


makeSet

public static <T> HashSet<T> makeSet(T[] array)
                          throws IllegalArgumentException
Throws:
IllegalArgumentException - if the array contains duplicates

reverseMap

public static <K,V> Map<V,K> reverseMap(Map<K,V> map)
generates a reversed map, mapping values to keys


keyForValue

public static <K,V> K keyForValue(Map<K,V> map,
                                  V value)

keysForValue

public static <K,V> Set<K> keysForValue(Map<K,V> map,
                                        V value)

makeSet

public static <T> HashSet<T> makeSet(T[] array,
                                     boolean ignoreDuplicates)
                          throws IllegalArgumentException
Throws:
IllegalArgumentException - if the array contains duplicates and ignoreduplicates is false

difference

public static <T> Set<? extends T> difference(Set<? extends T> set1,
                                              Set<? extends T> set2)
returns a set that contains all elements from set1 that are not in set2


same

public static boolean same(Map m1,
                           Map m2)


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads