net.ontopia.utils
Class CollectionUtils

java.lang.Object
  extended by net.ontopia.utils.CollectionUtils

public class CollectionUtils
extends java.lang.Object

INTERNAL: Class that contains useful collection methods.


Method Summary
static
<T> void
addAll(java.util.Collection<T> c, T[] a)
          INTERNAL: Adds all elements in the array to the collection.
static
<T> java.util.List<T>
castList(java.util.Collection<T> c)
          INTERNAL: Cast collection as list or make a new list.
static
<K,V> java.util.Map<K,V>
createConcurrentMap()
          INTERNAL: Creates new concurrent java.util.Map instance.
static
<T> java.util.Set<T>
createConcurrentSet()
          INTERNAL: Creates new concurrent java.util.Set instance.
static
<T> boolean
equalsUnorderedSet(java.util.Collection<T> coll1, java.util.Collection<T> coll2)
          INTERNAL: Compares two collections to see if they contain the same elements.
static
<T> java.util.Set<T>
filterSet(java.util.Collection<T> coll, DeciderIF decider)
          INTERNAL: Creates new Set that contains the elements from the input collection that the decider deems ok.
static
<T> T
getFirst(java.util.Collection<T> coll)
          INTERNAL: Gets the first object in the collection.
static
<T> T
getFirstElement(java.util.Collection<T> coll)
          INTERNAL: Gets the first object in the collection.
static
<T> T
getRandom(java.util.Collection<T> coll)
          INTERNAL: Gets a random object from the collection.
static
<T> java.util.Collection<T>
getSingletonCollectionOrEmptyIfNull(T o)
           
static
<T> java.util.List<T>
nextBatch(java.util.Iterator<T> iter, int length)
          EXPERIMENTAL: Iterates over up to length number of elements in the iterator and returns those elements as a Collection.
static
<T> int
nextBatch(java.util.Iterator<T> iter, int length, java.util.Collection<T> batch)
          EXPERIMENTAL: Iterates over up to length number of elements in the iterator and adds those elements to the given collection.
static
<T> int
nextBatch(java.util.Iterator<T> iter, T[] values)
          EXPERIMENTAL: Iterates over up to values.length number of elements in the iterator and inserts those elements in the values> array.
static
<T> int
nextBatch(java.util.Iterator<T> iter, T[] values, int offset, int length)
          EXPERIMENTAL: Iterates over up to length number of elements in the iterator and inserts those elements in the values> array.
static
<T> boolean
overlaps(java.util.Collection<T> c1, java.util.Collection<T> c2)
          INTERNAL: Returns true if the two collections overlap with one or more elements.
static
<T> java.util.List<T>
removeDuplicates(java.util.List<T> list)
          INTERNAL: Removes all except the first occurrence of each element in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFirst

public static <T> T getFirst(java.util.Collection<T> coll)
INTERNAL: Gets the first object in the collection. If the collection is empty, null is returned.


getFirstElement

public static <T> T getFirstElement(java.util.Collection<T> coll)
                         throws java.util.NoSuchElementException
INTERNAL: Gets the first object in the collection. If the collection does not contain any elements NoSuchElementException is thrown.

Throws:
java.util.NoSuchElementException
Since:
1.3.4

getSingletonCollectionOrEmptyIfNull

public static <T> java.util.Collection<T> getSingletonCollectionOrEmptyIfNull(T o)

getRandom

public static <T> T getRandom(java.util.Collection<T> coll)
INTERNAL: Gets a random object from the collection. If the collection is empty, null is returned.


equalsUnorderedSet

public static <T> boolean equalsUnorderedSet(java.util.Collection<T> coll1,
                                             java.util.Collection<T> coll2)
INTERNAL: Compares two collections to see if they contain the same elements.

Since:
1.4.1

nextBatch

public static <T> java.util.List<T> nextBatch(java.util.Iterator<T> iter,
                                              int length)
EXPERIMENTAL: Iterates over up to length number of elements in the iterator and returns those elements as a Collection. If the iterator is exhausted only the iterated elements are returned.


nextBatch

public static <T> int nextBatch(java.util.Iterator<T> iter,
                                int length,
                                java.util.Collection<T> batch)
EXPERIMENTAL: Iterates over up to length number of elements in the iterator and adds those elements to the given collection. If the iterator is exhausted only the iterated elements are added.

Returns:
the number of elements inserted into the array

nextBatch

public static <T> int nextBatch(java.util.Iterator<T> iter,
                                T[] values)
EXPERIMENTAL: Iterates over up to values.length number of elements in the iterator and inserts those elements in the values> array. If the iterator is exhausted only the iterated elements are included.

Returns:
the number of elements inserted into the array

nextBatch

public static <T> int nextBatch(java.util.Iterator<T> iter,
                                T[] values,
                                int offset,
                                int length)
EXPERIMENTAL: Iterates over up to length number of elements in the iterator and inserts those elements in the values> array. The first element is inserted at the specified offset. If the iterator is exhausted only the iterated elements are included.

Returns:
the number of elements inserted into the array

castList

public static <T> java.util.List<T> castList(java.util.Collection<T> c)
INTERNAL: Cast collection as list or make a new list.


addAll

public static <T> void addAll(java.util.Collection<T> c,
                              T[] a)
INTERNAL: Adds all elements in the array to the collection.


overlaps

public static <T> boolean overlaps(java.util.Collection<T> c1,
                                   java.util.Collection<T> c2)
INTERNAL: Returns true if the two collections overlap with one or more elements.


createConcurrentMap

public static <K,V> java.util.Map<K,V> createConcurrentMap()
INTERNAL: Creates new concurrent java.util.Map instance.


createConcurrentSet

public static <T> java.util.Set<T> createConcurrentSet()
INTERNAL: Creates new concurrent java.util.Set instance.


filterSet

public static <T> java.util.Set<T> filterSet(java.util.Collection<T> coll,
                                             DeciderIF decider)
INTERNAL: Creates new Set that contains the elements from the input collection that the decider deems ok.


removeDuplicates

public static <T> java.util.List<T> removeDuplicates(java.util.List<T> list)
INTERNAL: Removes all except the first occurrence of each element in the list. Use only with fairly small RandomAccess collections. Method trades speed for memory.



Copyright © 2000-2012 Ontopia.