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

Method Detail

getFirst

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


getFirstElement

public static java.lang.Object getFirstElement(java.util.Collection 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 java.util.Collection getSingletonCollectionOrEmptyIfNull(java.lang.Object o)

getRandom

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


equalsUnorderedSet

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

Since:
1.4.1

nextBatch

public static java.util.List nextBatch(java.util.Iterator 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 int nextBatch(java.util.Iterator iter,
                            int length,
                            java.util.Collection 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 int nextBatch(java.util.Iterator iter,
                            java.lang.Object[] 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 int nextBatch(java.util.Iterator iter,
                            java.lang.Object[] 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 java.util.List castList(java.util.Collection c)
INTERNAL: Cast collection as list or make a new list.


addAll

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


overlaps

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


createConcurrentMap

public static java.util.Map createConcurrentMap()
INTERNAL: Creates new concurrent java.util.Map instance.


createConcurrentSet

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


filterSet

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


removeDuplicates

public static java.util.List removeDuplicates(java.util.List 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-2010 Ontopia.