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 various collections and arrays.

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 int indexOf(char character, char[] array)
          Returns index of specified character in array.
static int indexOf(int number, int[] array)
          Returns index of specified integer in array.
static int indexOf(java.lang.Object object, java.lang.Object[] array)
          Returns index of specified object in array.
static int indexOf(java.lang.String text, java.lang.String[] array)
          Returns index of specified text in array.
static int indexOf(java.lang.String text, java.lang.String[] array, boolean ignoreCase)
          Returns index of specified text in array.
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.
 
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

indexOf

public static int indexOf(java.lang.Object object,
                          java.lang.Object[] array)
Returns index of specified object in array.

Parameters:
object - object to find
array - array to process
Returns:
index of specified object in array

indexOf

public static int indexOf(java.lang.String text,
                          java.lang.String[] array)
Returns index of specified text in array.

Parameters:
text - text to find
array - array to process
Returns:
index of specified text in array

indexOf

public static int indexOf(java.lang.String text,
                          java.lang.String[] array,
                          boolean ignoreCase)
Returns index of specified text in array.

Parameters:
text - text to find
array - array to process
ignoreCase - whether ignore text case or not
Returns:
index of specified text in array

indexOf

public static int indexOf(int number,
                          int[] array)
Returns index of specified integer in array.

Parameters:
number - integer to find
array - array to process
Returns:
index of specified integer in array

indexOf

public static int indexOf(char character,
                          char[] array)
Returns index of specified character in array.

Parameters:
character - character to find
array - array to process
Returns:
index of specified character in array

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