com.alee.utils
Class CollectionUtils

java.lang.Object
  extended by com.alee.utils.CollectionUtils

public final class CollectionUtils
extends java.lang.Object

This class provides a set of utilities to work with collections.

Author:
Mikle Garin

Constructor Summary
CollectionUtils()
           
 
Method Summary
static
<T> boolean
addAll(java.util.Collection<T> collection, T... objects)
          Adds all objects into specified list.
static boolean areEqual(java.util.List list1, java.util.List list2)
          Returns whether lists are equal or not.
static
<T extends java.lang.Cloneable>
java.util.List<T>
clone(java.util.Collection<T> collection)
          Returns clone of the specified list.
static
<T> java.util.List<T>
copy(java.util.Collection<T> collection)
          Returns copy of the specified list.
static
<T> java.util.List<T>
copy(T... data)
          Returns data converted into list.
static
<T> java.util.List<T>
filter(java.util.Collection<T> collection, Filter<T> filter)
          Returns list of elements filtered from collection.
static
<K,V> java.util.List<K>
keysList(java.util.Map<K,V> map)
          Returns map keys list.
static
<T> java.util.List<T>
removeNulls(java.util.List<T> list)
          Removes all null elements from list.
static int[] toArray(java.util.List<java.lang.Integer> list)
          Returns an int array created using Integer list.
static
<T> java.util.List<T>
toList(java.util.Deque<T> deque)
          Returns a list of objects converted from deque.
static
<T> java.util.List<T>
toList(T[] array)
          Returns a list of objects converted from array.
static
<T> java.util.List<java.lang.String>
toStringList(java.util.List<T> list, TextProvider<T> textProvider)
          Returns list of strings extracted from the specified elements list.
static
<K,V> java.util.List<V>
valuesList(java.util.Map<K,V> map)
          Returns map values list.
static
<K,V> java.util.List<V>
valuesSummaryList(java.util.Map<K,java.util.List<V>> map)
          Returns map values summary list with unique elements only.
 
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

addAll

public static <T> boolean addAll(java.util.Collection<T> collection,
                                 T... objects)
Adds all objects into specified list.

Type Parameters:
T - objects type
Parameters:
collection - list to fill
objects - objects
Returns:
true if list changed as the result of this operation, false otherwise

copy

public static <T> java.util.List<T> copy(java.util.Collection<T> collection)
Returns copy of the specified list. Note that this method will copy same list values into the new list.

Type Parameters:
T - list type
Parameters:
collection - list to copy
Returns:
copy of the specified list

clone

public static <T extends java.lang.Cloneable> java.util.List<T> clone(java.util.Collection<T> collection)
Returns clone of the specified list. Note that this method will clone all values into new list.

Type Parameters:
T - list type
Parameters:
collection - list to clone
Returns:
clone of the specified list

copy

public static <T> java.util.List<T> copy(T... data)
Returns data converted into list.

Type Parameters:
T - data type
Parameters:
data - data
Returns:
data list

removeNulls

public static <T> java.util.List<T> removeNulls(java.util.List<T> list)
Removes all null elements from list.

Type Parameters:
T - list type
Parameters:
list - list to refactor
Returns:
refactored list

areEqual

public static boolean areEqual(java.util.List list1,
                               java.util.List list2)
Returns whether lists are equal or not.

Parameters:
list1 - first list
list2 - second list
Returns:
true if lists are equal, false otherwise

toStringList

public static <T> java.util.List<java.lang.String> toStringList(java.util.List<T> list,
                                                                TextProvider<T> textProvider)
Returns list of strings extracted from the specified elements list.

Type Parameters:
T - elements type
Parameters:
list - elements list
textProvider - text provider
Returns:
list of strings extracted from the specified elements list

toArray

public static int[] toArray(java.util.List<java.lang.Integer> list)
Returns an int array created using Integer list.

Parameters:
list - Integer list
Returns:
int array

toList

public static <T> java.util.List<T> toList(T[] array)
Returns a list of objects converted from array.

Type Parameters:
T - data type
Parameters:
array - data array
Returns:
data list

toList

public static <T> java.util.List<T> toList(java.util.Deque<T> deque)
Returns a list of objects converted from deque.

Type Parameters:
T - data type
Parameters:
deque - data deque
Returns:
data list

filter

public static <T> java.util.List<T> filter(java.util.Collection<T> collection,
                                           Filter<T> filter)
Returns list of elements filtered from collection.

Type Parameters:
T - elements type
Parameters:
collection - collecton to filter
filter - filter to process
Returns:
list of elements filtered from collection

keysList

public static <K,V> java.util.List<K> keysList(java.util.Map<K,V> map)
Returns map keys list.

Type Parameters:
K - key object type
V - value object type
Parameters:
map - map to process
Returns:
map keys list

valuesList

public static <K,V> java.util.List<V> valuesList(java.util.Map<K,V> map)
Returns map values list.

Type Parameters:
K - key object type
V - value object type
Parameters:
map - map to process
Returns:
map values list

valuesSummaryList

public static <K,V> java.util.List<V> valuesSummaryList(java.util.Map<K,java.util.List<V>> map)
Returns map values summary list with unique elements only.

Type Parameters:
K - key object type
V - value object type
Parameters:
map - map to process
Returns:
map values summary list with unique elements only