org.omnaest.utils.structure.collection
Class CollectionUtils

java.lang.Object
  extended by org.omnaest.utils.structure.collection.CollectionUtils

public class CollectionUtils
extends Object


Nested Class Summary
static interface CollectionUtils.ElementConverter<FROM,TO>
          Used to convert a collection element.
static class CollectionUtils.IdentityElementConverter<T>
          Does not change the type of the element and the value of the element being converted.
 
Constructor Summary
CollectionUtils()
           
 
Method Summary
static void addAll(Collection<Integer> integerCollection, int[] intArray)
          Adds an array of integer values to a collection of Integer
static void addAll(Collection<Long> longCollection, long[] intArray)
          Adds an array of long values to a collection of Long
static
<E> boolean
containsObjectIdentity(Collection<E> collection, Object object)
          Returns true if the given Collection contains the given object.
static boolean equals(Iterable<?> collection1, Iterable<?> collection2)
          Returns true if the elements of the two given Collections are equal and have the same order
static boolean equalsUnordered(Collection<?> collection1, Collection<?> collection2)
          Tests, if the two collection have the same elements.
static
<E> int
hashCode(Collection<E> collection)
          Calculates the hash code for a given collection including the order of elements
static
<E> int
hashCodeUnordered(Collection<E> collection)
          Calculates the hash code for a given collection not including the order of elements.
static
<E> int
indexOfObjectIdentity(Collection<E> collection, Object object)
          Returns the index position of the first occurring object within the Collection.
static
<E> int
lastIndexOfObjectIdentity(Collection<E> collection, Object object)
          Returns the index position of the last occurring object within the Collection.
static void printCollection(Collection<?> collection)
          Prints the collection values to the system out.
static double sumOfCollectionDouble(Collection<Double> collectionDouble)
          Returns the sum of the values within an Double Collection.
static int sumOfCollectionInteger(Collection<Integer> collectionInteger)
          Returns the sum of the values within an Integer Collection.
static
<E> E[]
toArray(Collection<E> collection, Class<? extends E> clazz)
          Converts a given Collection into a typed array
static int[] toArrayInt(Collection<Integer> integerList)
          Returns the values of a Integer collection as array.
static
<TO,FROM> Collection<TO>
transformCollection(Collection<FROM> collectionFrom, ListUtils.ElementTransformer<FROM,TO> elementTransformer)
          Converts a given Collection into another Collection with other element types using an ListUtils.ElementTransformer.
static
<TO,FROM> Collection<TO>
transformCollectionExcludingNullElements(Collection<FROM> collectionFrom, ListUtils.ElementTransformer<FROM,TO> elementTransformer)
          Converts a given Collection into another Collection with other element types, whereby all elements which convert to null will not be inserted into the target Collection.
 
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

sumOfCollectionInteger

public static int sumOfCollectionInteger(Collection<Integer> collectionInteger)
Returns the sum of the values within an Integer Collection.

Parameters:
collectionInteger -
Returns:

sumOfCollectionDouble

public static double sumOfCollectionDouble(Collection<Double> collectionDouble)
Returns the sum of the values within an Double Collection.

Parameters:
collectionDouble -
Returns:

printCollection

public static void printCollection(Collection<?> collection)
Prints the collection values to the system out.

Parameters:
collection -

addAll

public static void addAll(Collection<Integer> integerCollection,
                          int[] intArray)
Adds an array of integer values to a collection of Integer

Parameters:
integerCollection -
intArray -

addAll

public static void addAll(Collection<Long> longCollection,
                          long[] intArray)
Adds an array of long values to a collection of Long

Parameters:
longCollection -
intArray -

toArrayInt

public static int[] toArrayInt(Collection<Integer> integerList)
Returns the values of a Integer collection as array.

Parameters:
integerList -
Returns:

toArray

public static <E> E[] toArray(Collection<E> collection,
                              Class<? extends E> clazz)
Converts a given Collection into a typed array

Parameters:
collection -
clazz -
Returns:

equalsUnordered

public static boolean equalsUnordered(Collection<?> collection1,
                                      Collection<?> collection2)
Tests, if the two collection have the same elements.

Parameters:
collection1 -
collection2 -
Returns:

equals

public static boolean equals(Iterable<?> collection1,
                             Iterable<?> collection2)
Returns true if the elements of the two given Collections are equal and have the same order

Parameters:
collection1 -
collection2 -
Returns:

transformCollection

public static <TO,FROM> Collection<TO> transformCollection(Collection<FROM> collectionFrom,
                                                           ListUtils.ElementTransformer<FROM,TO> elementTransformer)
Converts a given Collection into another Collection with other element types using an ListUtils.ElementTransformer.

Parameters:
collectionFrom -
elementTransformer -
Returns:
See Also:
ListUtils.ElementTransformer

transformCollectionExcludingNullElements

public static <TO,FROM> Collection<TO> transformCollectionExcludingNullElements(Collection<FROM> collectionFrom,
                                                                                ListUtils.ElementTransformer<FROM,TO> elementTransformer)
Converts a given Collection into another Collection with other element types, whereby all elements which convert to null will not be inserted into the target Collection.

Parameters:
collectionFrom -
elementTransformer -
Returns:
See Also:
ListUtils.ElementTransformer

containsObjectIdentity

public static <E> boolean containsObjectIdentity(Collection<E> collection,
                                                 Object object)
Returns true if the given Collection contains the given object. Contains uses the "object == element" instead of the "equals" method to determine the object identity.

Parameters:
collection -
object -
Returns:

indexOfObjectIdentity

public static <E> int indexOfObjectIdentity(Collection<E> collection,
                                            Object object)
Returns the index position of the first occurring object within the Collection. Comparisons uses the "object == element" instead of the "equals" method to determine the object identity.

Parameters:
collection -
object -
Returns:
index position of the first matching element;-1 if no element is matching

lastIndexOfObjectIdentity

public static <E> int lastIndexOfObjectIdentity(Collection<E> collection,
                                                Object object)
Returns the index position of the last occurring object within the Collection. Comparisons uses the "object == element" instead of the "equals" method to determine the object identity.

Parameters:
collection -
object -
Returns:
index position of the first matching element;-1 if no element is matching

hashCode

public static <E> int hashCode(Collection<E> collection)
Calculates the hash code for a given collection including the order of elements

Parameters:
collection -
Returns:

hashCodeUnordered

public static <E> int hashCodeUnordered(Collection<E> collection)
Calculates the hash code for a given collection not including the order of elements. This can be used for Set implementations e.g.

Parameters:
collection -
Returns:


Copyright © 2011. All Rights Reserved.