com.aliasi.util
Class Collections

java.lang.Object
  extended by com.aliasi.util.Collections

public class Collections
extends Object

Static utility methods for processing collections.

Since:
LingPipe1.0
Version:
3.0
Author:
Bob Carpenter

Method Summary
static
<E> void
addAll(Collection<? super E> c, E[] xs)
          Adds the elements from the specified array to the specified collection.
static void elementsToStringBuffer(StringBuffer sb, Collection<?> c)
          Appends a string-based representation of the specified colleciton to the specified string buffer.
static
<E> E
getFirst(List<? extends E> l)
          Returns the first member of the specified list.
static
<E> E
getFirst(Set<? extends E> s)
          Returns the first member of the specified set.
static
<E> Set<E>
immutableSet(Collection<? extends E> elts)
           
static
<E> Set<E>
immutableSet(E[] elts)
           
static boolean intersects(Set<?> set1, Set<?> set2)
          Returns true if the specified sets have at least one element in common.
static boolean isSingleton(Collection<?> c)
          Returns true if the specified collection contains exactly one member.
static String listToString(List<?> ls)
          Returns a string-based representation of the specified list.
static void listToStringBuffer(StringBuffer sb, List<?> ls)
          Appends a string-based representation of the specified list to the specified string buffer.
static String setToString(Set<?> s)
          Returns a string-based representation of the specified set.
static void setToStringBuffer(StringBuffer sb, Set<?> c)
          Appends a string-based representation of the specified set to the specified string buffer.
static int[] toIntArray(Collection cs)
          Returns an array of int consisting of the elements of the specified collection converted to int.
static String[] toStringArray(Collection c)
          Returns the elements in the specified collection as an array after converting each to a string.
static void toStringArray(Collection c, String[] members)
          Writes the elements in the specified collection into the specified array as strings, beginning with the first position of the array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isSingleton

public static boolean isSingleton(Collection<?> c)
Returns true if the specified collection contains exactly one member.

Parameters:
c - Collection to test.
Returns:
true if the specified collection contains exactly one member.

getFirst

public static <E> E getFirst(List<? extends E> l)
Returns the first member of the specified list.

Parameters:
l - List whose first member is returned.
Returns:
First member of the specified list.
Throws:
IndexOutOfBoundsException - If the list is empty.

getFirst

public static <E> E getFirst(Set<? extends E> s)
Returns the first member of the specified set.

Parameters:
s - Set whose first member is returned.
Returns:
First member of the specified set.
Throws:
NoSuchElementException - If the set is empty.

intersects

public static boolean intersects(Set<?> set1,
                                 Set<?> set2)
Returns true if the specified sets have at least one element in common.

Parameters:
set1 - First set.
set2 - Second set.
Returns:
true if the specified sets have at least one element in common.

addAll

public static <E> void addAll(Collection<? super E> c,
                              E[] xs)
Adds the elements from the specified array to the specified collection.

Parameters:
c - Collection to which objects are added.
xs - Objects to add to the collection.

toStringArray

public static String[] toStringArray(Collection c)
Returns the elements in the specified collection as an array after converting each to a string. The strings in the array will be ordered as by the collection's iterator.

Parameters:
c - Collection to convert to an array.
Returns:
Elements of specified collection as an array of strings.

toStringArray

public static void toStringArray(Collection c,
                                 String[] members)
Writes the elements in the specified collection into the specified array as strings, beginning with the first position of the array. The elements in the array will be ordered as by the collection's iterator. The array may be longer than the collection, in which case nothing is done to the remaining members of the array.

Parameters:
c - Collection to convert to an array.
members - String rray to write collection into.
Throws:
IndexOutOfBoundsException - If the size of the collection is greater than the length of the array.

toIntArray

public static int[] toIntArray(Collection cs)
Returns an array of int consisting of the elements of the specified collection converted to int. The collection must only consist of Integer values.

Parameters:
cs - Collection of integers to convert to ints.
Returns:
Array of ints derived from collection of integers.

setToString

public static String setToString(Set<?> s)
Returns a string-based representation of the specified set.

Parameters:
s - Set to convert to string.
Returns:
String-based representation of the specified set.

listToString

public static String listToString(List<?> ls)
Returns a string-based representation of the specified list.

Parameters:
ls - List to convert to string.
Returns:
String-based representation of the specified list.

listToStringBuffer

public static void listToStringBuffer(StringBuffer sb,
                                      List<?> ls)
Appends a string-based representation of the specified list to the specified string buffer.

Parameters:
sb - String buffer to which the representation is appended.
ls - List to append as a string.

setToStringBuffer

public static void setToStringBuffer(StringBuffer sb,
                                     Set<?> c)
Appends a string-based representation of the specified set to the specified string buffer.

Parameters:
sb - String buffer to which the representation is appended.
c - Set to append as a string.

elementsToStringBuffer

public static void elementsToStringBuffer(StringBuffer sb,
                                          Collection<?> c)
Appends a string-based representation of the specified colleciton to the specified string buffer.

Parameters:
sb - String buffer to which the representation is appended.
c - Collection to append as a string.

immutableSet

public static <E> Set<E> immutableSet(Collection<? extends E> elts)

immutableSet

public static <E> Set<E> immutableSet(E[] elts)