com.ge.research.utils
Class ListUtils

java.lang.Object
  extended bycom.ge.research.utils.CollectionUtils
      extended bycom.ge.research.utils.ListUtils

public class ListUtils
extends CollectionUtils

A utility class with common, useful methods for dealing with Lists.

Version:
$Revision: 1.1 $ $Date: 2006/08/11 00:17:38 $
Author:
garbiras
Created on:
Aug 20, 2002

Constructor Summary
ListUtils()
           
 
Method Summary
static boolean allElementsOfType(java.util.List list, java.lang.Class type)
          Checks each entry in the List to see if the entry is assignable to the argument class type.
static boolean isInRange(java.util.List list, int index)
          Checks the argument index against the List to see if it is a valid index reference for the List.
static void moveItem(java.util.List list, int moveFrom, int moveTo)
          Moves the element in the list list from the position moveFrom to the position moveTo, and preserves the order of the list.
static void moveItem(java.util.List list, java.lang.Object element, int moveTo)
          Moves the element in the list from its current position to the position moveTo, and preserves the order of the list.
static void moveItemAfter(java.util.List list, java.lang.Object elementToMove, java.lang.Object referenceElement)
          Moves the elementToMove and places it directly after the referenceElement in the list, and preserves the order of the list.
static void moveItemBefore(java.util.List list, java.lang.Object elementToMove, java.lang.Object referenceElement)
          Moves the elementToMove and places it directly before the referenceElement in the list, and preserves the order of the list.
static void moveItemToEnd(java.util.List list, int moveFrom)
          Moves the element in the list currently at position moveFrom to the end of the list, and preserves the order of the list.
static void moveItemToEnd(java.util.List list, java.lang.Object element)
          Moves the element in the list to the end of the list, and preserves the order of the list.
static void moveItemToStart(java.util.List list, int moveFrom)
          Moves the element in the list currently at position moveFrom to the beginning of the list, and preserves the order of the list.
static void moveItemToStart(java.util.List list, java.lang.Object element)
          Moves the element in the list to the beginning of the list, and preserves the order of the list.
static void swapItems(java.util.List list, java.lang.Object elementOne, java.lang.Object elementTwo)
          Moves two elements of the list such that each element occupies the others original position.
 
Methods inherited from class com.ge.research.utils.CollectionUtils
allElementsOfType, moveItem, moveItem, moveItemAfter, moveItemBefore, moveItemToEnd, moveItemToEnd, moveItemToStart, moveItemToStart, orderItems, removeDuplicates, reverseOrder, swapItems
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListUtils

public ListUtils()
Method Detail

allElementsOfType

public static boolean allElementsOfType(java.util.List list,
                                        java.lang.Class type)
Checks each entry in the List to see if the entry is assignable to the argument class type.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
type - the Class type to check each entry in the List against, to see if the entries are an instance of that class or one of its subclasses.
Returns:
true if all entries are of the type specified, or if the List is null or empty; false otherwise

isInRange

public static boolean isInRange(java.util.List list,
                                int index)
Checks the argument index against the List to see if it is a valid index reference for the List.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
index - the index value to check against the size of the List to see if it is a valid index reference
Returns:
false if the List is null, or if the List is empty, or if index is negative, or if index is greater than or equal to the size of the List; true otherwise

moveItem

public static void moveItem(java.util.List list,
                            int moveFrom,
                            int moveTo)
Moves the element in the list list from the position moveFrom to the position moveTo, and preserves the order of the list.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
moveFrom - the index within the list the element to move currently resides at
moveTo - the index within the list the element is to be moved to

moveItem

public static void moveItem(java.util.List list,
                            java.lang.Object element,
                            int moveTo)
Moves the element in the list from its current position to the position moveTo, and preserves the order of the list.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
element - the list element to move
moveTo - the index within the list the element is to be moved to
See Also:
moveItem(java.util.List, int, int)

moveItemAfter

public static void moveItemAfter(java.util.List list,
                                 java.lang.Object elementToMove,
                                 java.lang.Object referenceElement)
Moves the elementToMove and places it directly after the referenceElement in the list, and preserves the order of the list.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
elementToMove - the element to move
referenceElement - the element that marks the position within the list that the moving element should immediately follow
See Also:
moveItem(java.util.List, int, int)

moveItemBefore

public static void moveItemBefore(java.util.List list,
                                  java.lang.Object elementToMove,
                                  java.lang.Object referenceElement)
Moves the elementToMove and places it directly before the referenceElement in the list, and preserves the order of the list.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
elementToMove - the element to move
referenceElement - the element that marks the position within the list that the moving element should immediately precede
See Also:
moveItem(java.util.List, int, int)

moveItemToEnd

public static void moveItemToEnd(java.util.List list,
                                 int moveFrom)
Moves the element in the list currently at position moveFrom to the end of the list, and preserves the order of the list.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
moveFrom - the index within the list the element to move currently resides at
See Also:
moveItem(java.util.List, int, int)

moveItemToEnd

public static void moveItemToEnd(java.util.List list,
                                 java.lang.Object element)
Moves the element in the list to the end of the list, and preserves the order of the list.

Parameters:
list - The datastructure that implements the List interface and contains the elements of interest
element - The element to move to the end of the list
See Also:
moveItem(java.util.List, java.lang.Object, int)

moveItemToStart

public static void moveItemToStart(java.util.List list,
                                   int moveFrom)
Moves the element in the list currently at position moveFrom to the beginning of the list, and preserves the order of the list.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
moveFrom - the index within the list the element to move currently resides at
See Also:
moveItem(java.util.List, int, int)

moveItemToStart

public static void moveItemToStart(java.util.List list,
                                   java.lang.Object element)
Moves the element in the list to the beginning of the list, and preserves the order of the list.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
element - the element to move to the beginning of the list
See Also:
moveItem(java.util.List, java.lang.Object, int)

swapItems

public static void swapItems(java.util.List list,
                             java.lang.Object elementOne,
                             java.lang.Object elementTwo)
Moves two elements of the list such that each element occupies the others original position.

Parameters:
list - the datastructure that implements the List interface and contains the elements of interest
elementOne - the first element to move. Its current position will be occupied by elementTwo after the swap is performed
elementTwo - the second element to move Its current position will be occupied by elementOne after the swap is performed
See Also:
moveItem(java.util.List, java.lang.Object, int)