com.silverpeas.util
Class CollectionUtil

java.lang.Object
  extended by com.silverpeas.util.CollectionUtil

public class CollectionUtil
extends Object

Author:
Yohann Chastagnier

Constructor Summary
CollectionUtil()
           
 
Method Summary
static
<T> boolean
addAllIgnoreNull(Collection<? super T> c, T... elements)
          Null elements are not taking into account.
static
<T> List<T>
asList(T... values)
           
static
<T> Set<T>
asSet(T... values)
           
static
<T> Collection<T>
extractFrom(Class<T> aClass, Collection<?> collection, String propertyName)
          Extracting a property.
static
<T> Collection<T>
extractFrom(Class<T> aClass, Collection<?> collection, String propertyNameToExtract, String propertyNameToCompare, Object givenValueToCompare, boolean nullValueExtracted)
          Extracting a property from elements that each has an other property with a given value
static
<T> Collection<T>
extractFrom(Collection<?> collection, String propertyName)
          Extracting a property.
static
<T> Collection<T>
extractFrom(Collection<?> collection, String propertyName, boolean isListOfArray, int numberColumn)
          Extracting a property.
static
<T> List<T>
intersection(List<T> list1, List<T> list2)
          Makes an intersection betwwen both of the given lists.
static
<T> boolean
isEmpty(Collection<T> collection)
          Checks if the given collection is not instancied or empty
static
<T> boolean
isNotEmpty(Collection<T> collection)
          Checks if the given collection is instancied and not empty
static
<T,K,V> HashMap<K,V>
listToMap(Collection<T> collection, ExtractionList<T,K,V> extractor)
          Transforming a collection into a map
static
<T> List<T>
reverse(List<T> list)
          Reverse the given list and returns it.
static
<T> Collection<Collection<T>>
split(Collection<T> collection)
          Splits a collection into several collections.
static
<T> Collection<Collection<T>>
split(Collection<T> collection, int collectionSizeMax)
          Splits a collection into several collections.
static
<T> List<T>
union(List<T> list1, List<T> list2)
          Makes an union between both of the given lists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtil

public CollectionUtil()
Method Detail

reverse

public static <T> List<T> reverse(List<T> list)
Reverse the given list and returns it.

Type Parameters:
T -
Parameters:
list -
Returns:

isEmpty

public static <T> boolean isEmpty(Collection<T> collection)
Checks if the given collection is not instancied or empty

Type Parameters:
T -
Parameters:
collection -
Returns:

isNotEmpty

public static <T> boolean isNotEmpty(Collection<T> collection)
Checks if the given collection is instancied and not empty

Type Parameters:
T -
Parameters:
collection -
Returns:

split

public static <T> Collection<Collection<T>> split(Collection<T> collection)
Splits a collection into several collections. (Particularly useful for limitations of database around the "in" clause)

Parameters:
collection -
Returns:

split

public static <T> Collection<Collection<T>> split(Collection<T> collection,
                                                  int collectionSizeMax)
Splits a collection into several collections. (Particularly useful for limitations of database around the "in" clause)

Parameters:
collection -
collectionSizeMax -
Returns:

listToMap

public static <T,K,V> HashMap<K,V> listToMap(Collection<T> collection,
                                             ExtractionList<T,K,V> extractor)
Transforming a collection into a map

Type Parameters:
T - collection type elements
K - map type key
V - map type value
Parameters:
collection -
extractor - extractor interface
Returns:
a map initialized from a list by an extractor

extractFrom

public static <T> Collection<T> extractFrom(Class<T> aClass,
                                            Collection<?> collection,
                                            String propertyName)
Extracting a property.

Parameters:
aClass - property class to extract
collection - collection from that to extract
propertyName - name of the property
Returns:
a collection with requested elements

extractFrom

public static <T> Collection<T> extractFrom(Collection<?> collection,
                                            String propertyName)
Extracting a property.

Parameters:
collection - collection from that to extract
propertyName - name of the property
Returns:
a collection with requested elements

extractFrom

public static <T> Collection<T> extractFrom(Collection<?> collection,
                                            String propertyName,
                                            boolean isListOfArray,
                                            int numberColumn)
Extracting a property.

Parameters:
collection - collection from that to extract
propertyName - name of the property
isListOfArray - indicates if the list is an array list
numberColumn - column index to extract from the array
Returns:
a collection with requested elements

extractFrom

public static <T> Collection<T> extractFrom(Class<T> aClass,
                                            Collection<?> collection,
                                            String propertyNameToExtract,
                                            String propertyNameToCompare,
                                            Object givenValueToCompare,
                                            boolean nullValueExtracted)
Extracting a property from elements that each has an other property with a given value

Parameters:
class - property class to extract
collection - element collection
propertyNameToExtract - name property to extract
propertyNameToCompare - name value to compare
givenValueToCompare - value to compare
nullValueExtracted - null value extracted
Returns:
a bean property collection

asList

public static <T> List<T> asList(T... values)

asSet

public static <T> Set<T> asSet(T... values)

addAllIgnoreNull

public static <T> boolean addAllIgnoreNull(Collection<? super T> c,
                                           T... elements)
Null elements are not taking into account.

See Also:
Collections.addAll(java.util.Collection, Object[])

union

public static <T> List<T> union(List<T> list1,
                                List<T> list2)
Makes an union between both of the given lists.
The result contains unique values.

Type Parameters:
T -
Parameters:
list1 - the first list.
list2 - the second list.
Returns:
the union between the two lists.

intersection

public static <T> List<T> intersection(List<T> list1,
                                       List<T> list2)
Makes an intersection betwwen both of the given lists.
The result contains unique values.

Type Parameters:
T -
Parameters:
list1 - the first list.
list2 - the second list.
Returns:
the intersection between the two lists.


Copyright © 2016 Silverpeas. All Rights Reserved.