org.expasy.jpl.commons.collection
Class CollectionUtils

java.lang.Object
  extended by org.expasy.jpl.commons.collection.CollectionUtils

public class CollectionUtils
extends Object

Provides static utility method for Collections.

Version:
1.0
Author:
nikitin

Constructor Summary
CollectionUtils()
           
 
Method Summary
static
<T> HashSet<T>
asSet(T... elts)
          Create a new instance of HashSet from a list of elements.
static
<T> TreeSet<T>
asTreeSet(T... elts)
          Create a new instance of TreeSet from a list of elements.
static
<T> Set<T>
intersection(Set<T> s1, Set<T> s2)
          Compute the intersection between the 2 given sets.
static
<T> Set<T>
minus(Set<T> s1, Set<T> s2)
          Compute s1 - s2.
static List<Double> parseDoubleList(String str)
           
static List<Integer> parseIntList(String str)
           
static
<E> List<E>
parseList(String str, org.apache.commons.collections15.Transformer<String,E> transformer)
          Convert a string to a List.
static List<String> parseStringList(String str)
           
static Set<Integer> select(Set<Integer> s, Interval interval)
          Keep all integers that belong to the interval.
static Set<Integer> select(Set<Integer> s, int from, int to)
          Keep all integers that belong to the interval.
static
<T> Set<T>
union(Set<T>... sets)
          Compute the union of many sets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

asSet

public static final <T> HashSet<T> asSet(T... elts)
Create a new instance of HashSet from a list of elements.

Type Parameters:
T - the data type.
Parameters:
elts - the elements to fill the set.
Returns:
a new instance of HashSet.

asTreeSet

public static final <T> TreeSet<T> asTreeSet(T... elts)
Create a new instance of TreeSet from a list of elements.

Type Parameters:
T - the data type.
Parameters:
elts - the elements to fill the set.
Returns:
a new instance of TreeSet.

intersection

public static final <T> Set<T> intersection(Set<T> s1,
                                            Set<T> s2)
Compute the intersection between the 2 given sets.

Type Parameters:
T - the data type.
Parameters:
s1 - the first set.
s2 - the second set.
Returns:
an intersection of sets.

union

public static final <T> Set<T> union(Set<T>... sets)
Compute the union of many sets.

Type Parameters:
T - the data type.
Parameters:
sets - the sets to merge.
Returns:
a union of sets.

minus

public static final <T> Set<T> minus(Set<T> s1,
                                     Set<T> s2)
Compute s1 - s2.

Type Parameters:
T - the data type.
Parameters:
s1 - the first set.
s2 - the second set.
Returns:
a substraction of sets.

select

public static final Set<Integer> select(Set<Integer> s,
                                        int from,
                                        int to)
Keep all integers that belong to the interval.

Parameters:
s - the set to set element from.
from - the lower bound of the interval.
to - the upper bound.
Returns:
a set of integers.

select

public static final Set<Integer> select(Set<Integer> s,
                                        Interval interval)
Keep all integers that belong to the interval.

Parameters:
s - the set to set element from.
interval - the interval.
Returns:
a set of integers.

parseList

public static final <E> List<E> parseList(String str,
                                          org.apache.commons.collections15.Transformer<String,E> transformer)
Convert a string to a List.

Type Parameters:
E - the element type.
Parameters:
str - the string to parse list from (format="[?elt1,..,eltn]?").
transformer - the converter String to E.
Returns:
a list of E.
See Also:
StringConverters

parseIntList

public static final List<Integer> parseIntList(String str)

parseDoubleList

public static final List<Double> parseDoubleList(String str)

parseStringList

public static final List<String> parseStringList(String str)


Copyright (c) 2012 Swiss Institute of Bioinformatics. All rights reserved.