org.jocl.cloth.utils
Class CollectionUtils

java.lang.Object
  extended by org.jocl.cloth.utils.CollectionUtils

public class CollectionUtils
extends java.lang.Object

Utility methods for collections.


Method Summary
static
<T> java.util.List<java.util.List<T>>
asListList(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
          Returns the given collections as a list of lists
static
<T> java.util.List<java.util.List<java.util.List<T>>>
asListListList(java.lang.Iterable<? extends java.lang.Iterable<? extends java.util.Collection<? extends T>>> collections)
          Returns the given collections as a list of lists of lists
static
<T> java.util.List<java.util.Set<T>>
asSetList(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
          Returns the given collections as a list of sets
static
<T extends java.util.Collection<?>>
java.util.Comparator<T>
collectionBySizeComparator()
          Returns a comparator that compares collections by their size, in ascending order
static
<T> int
computeTotalSize(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
          Returns the total size of the given collections
static
<T> boolean
containsAny(java.util.Collection<? extends T> containing, java.lang.Iterable<? extends T> anyOfThese)
          Returns whether the first collection contains any of the elements of the second sequence of elements
static
<T> java.util.List<T>
flatten(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
          Flatten the contents of the given sequence of collections.
static
<T extends java.util.Collection<?>>
T
largest(java.lang.Iterable<T> collections)
          Returns the largest of the given collections
static
<T extends java.util.Collection<?>>
int
maxSize(java.lang.Iterable<T> collections)
          Returns the size of the largest collection
static
<T extends java.util.Collection<?>>
int
minSize(java.lang.Iterable<T> collections)
          Returns the size of the smallest collection
static
<T extends java.util.Collection<?>>
T
smallest(java.lang.Iterable<T> collections)
          Returns the smallest of the given collections
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

collectionBySizeComparator

public static <T extends java.util.Collection<?>> java.util.Comparator<T> collectionBySizeComparator()
Returns a comparator that compares collections by their size, in ascending order

Type Parameters:
T - The type of the collection
Returns:
The comparator

largest

public static <T extends java.util.Collection<?>> T largest(java.lang.Iterable<T> collections)
Returns the largest of the given collections

Type Parameters:
T - The type of the collections
Parameters:
collections - The collections
Returns:
The largest collection

smallest

public static <T extends java.util.Collection<?>> T smallest(java.lang.Iterable<T> collections)
Returns the smallest of the given collections

Type Parameters:
T - The type of the collections
Parameters:
collections - The collections
Returns:
The smallest collection

maxSize

public static <T extends java.util.Collection<?>> int maxSize(java.lang.Iterable<T> collections)
Returns the size of the largest collection

Type Parameters:
T - The type of the collections
Parameters:
collections - The collections
Returns:
The size of the largest collection

minSize

public static <T extends java.util.Collection<?>> int minSize(java.lang.Iterable<T> collections)
Returns the size of the smallest collection

Type Parameters:
T - The type of the collections
Parameters:
collections - The collections
Returns:
The size of the smallest collection

flatten

public static <T> java.util.List<T> flatten(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
Flatten the contents of the given sequence of collections. That is, return the contents of all collections as a single list.

Type Parameters:
T - The content type
Parameters:
collections - The collections
Returns:
The flattened collection

asListList

public static <T> java.util.List<java.util.List<T>> asListList(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
Returns the given collections as a list of lists

Type Parameters:
T - The content type of the lists
Parameters:
collections - The collections
Returns:
The collections as a list of lists

asListListList

public static <T> java.util.List<java.util.List<java.util.List<T>>> asListListList(java.lang.Iterable<? extends java.lang.Iterable<? extends java.util.Collection<? extends T>>> collections)
Returns the given collections as a list of lists of lists

Type Parameters:
T - The content type of the lists
Parameters:
collections - The collections
Returns:
The collections as a list of lists of lists

asSetList

public static <T> java.util.List<java.util.Set<T>> asSetList(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
Returns the given collections as a list of sets

Type Parameters:
T - The content type of the sets
Parameters:
collections - The collections
Returns:
The collections as a list of sets

containsAny

public static <T> boolean containsAny(java.util.Collection<? extends T> containing,
                                      java.lang.Iterable<? extends T> anyOfThese)
Returns whether the first collection contains any of the elements of the second sequence of elements

Type Parameters:
T - The content type
Parameters:
containing - The collection potentially containing the elements
anyOfThese - The elements that may be contained in the collection
Returns:
Whether any of the elements is contained in the collection

computeTotalSize

public static <T> int computeTotalSize(java.lang.Iterable<? extends java.util.Collection<? extends T>> collections)
Returns the total size of the given collections

Type Parameters:
T - The content type of the collections
Parameters:
collections - The collections
Returns:
The total size