|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ge.research.utils.CollectionUtils
A utility class with common, useful methods for dealing with Collections.
| Constructor Summary | |
CollectionUtils()
|
|
| Method Summary | |
static boolean |
allElementsOfType(java.util.Collection c,
java.lang.Class type)
Checks each entry in the Collection to see if the entry is assignable to the argument class type. |
static void |
moveItem(java.util.Collection c,
int moveFrom,
int moveTo)
Moves the element in the collection c from the position moveFrom to
the position moveTo, and preserves the order of the collection. |
static void |
moveItem(java.util.Collection c,
java.lang.Object element,
int moveTo)
Moves the element in the collection c from its current position to
the position moveTo, and preserves the order of the collection. |
static void |
moveItemAfter(java.util.Collection c,
java.lang.Object elementToMove,
java.lang.Object referenceElement)
Moves the elementToMove and places it directly after the
referenceElement in the collection c, and preserves the order of the collection. |
static void |
moveItemBefore(java.util.Collection c,
java.lang.Object elementToMove,
java.lang.Object referenceElement)
Moves the elementToMove and places it directly before the
referenceElement in the collection c, and preserves the order of the collection. |
static void |
moveItemToEnd(java.util.Collection c,
int moveFrom)
Moves the element in the collection c currently at position moveFrom
to the end of the collection, and preserves the order of the collection. |
static void |
moveItemToEnd(java.util.Collection c,
java.lang.Object element)
Moves the element |
static void |
moveItemToStart(java.util.Collection c,
int moveFrom)
Moves the element in the collection c currently at position moveFrom
to the beginning of the collection, and preserves the order of the collection. |
static void |
moveItemToStart(java.util.Collection c,
java.lang.Object element)
Moves the element in the collection c
to the beginning of the collection, and preserves the order of the collection. |
static void |
orderItems(java.util.Collection c,
boolean orderAscending)
Orders the elements of the collection based upon the collection elements object types. |
static void |
removeDuplicates(java.util.Collection c)
Eliminates duplicate elements from the colection, and only retains a single instance of each unique element. |
static void |
reverseOrder(java.util.Collection c)
Reverses the order of the elements of the Collection. |
static void |
swapItems(java.util.Collection c,
java.lang.Object elementOne,
java.lang.Object elementTwo)
Moves two elements of the collection such that each element occupies the others original position. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public CollectionUtils()
| Method Detail |
public static boolean allElementsOfType(java.util.Collection c,
java.lang.Class type)
Collection to see if the entry is assignable to the argument class type.
c - the datastructure that extends Collection and contains the elements of interesttype - the Class type to check each entry in the Collection against, to see if the entries are an instance of that class or one of its subclasses.
true if all entries are of the type specified, or if the Collection is null or empty;
false otherwise
public static void moveItem(java.util.Collection c,
int moveFrom,
int moveTo)
c from the position moveFrom to
the position moveTo, and preserves the order of the collection.
c - the datastructure that extends Collection and contains the elements of interestmoveFrom - the index within the collection the element to move currently resides atmoveTo - the index within the collection the element is to be moved to
public static void moveItem(java.util.Collection c,
java.lang.Object element,
int moveTo)
element in the collection c from its current position to
the position moveTo, and preserves the order of the collection.
c - the datastructure that extends Collection and contains the elements of interestelement - the collection element to movemoveTo - the index within the collection the element is to be moved to
public static void moveItemAfter(java.util.Collection c,
java.lang.Object elementToMove,
java.lang.Object referenceElement)
elementToMove and places it directly after the
referenceElement in the collection c, and preserves the order of the collection.
c - the datastructure that extends Collection and contains the elements of interestelementToMove - the element to movereferenceElement - the element that marks the position within the collection that the moving element should immediately follow
public static void moveItemToStart(java.util.Collection c,
int moveFrom)
c currently at position moveFrom
to the beginning of the collection, and preserves the order of the collection.
c - the datastructure that extends Collection and contains the elements of interestmoveFrom - the index within the collection the element to move currently resides atmoveItem(java.util.Collection, int, int)
public static void moveItemBefore(java.util.Collection c,
java.lang.Object elementToMove,
java.lang.Object referenceElement)
elementToMove and places it directly before the
referenceElement in the collection c, and preserves the order of the collection.
c - the datastructure that extends Collection and contains the elements of interestelementToMove - the element to movereferenceElement - the element that marks the position within the collection that the moving element should immediately precede
public static void moveItemToEnd(java.util.Collection c,
int moveFrom)
c currently at position moveFrom
to the end of the collection, and preserves the order of the collection.
c - the datastructure that extends Collection and contains the elements of interestmoveFrom - the index within the collection the element to move currently resides atmoveItem(java.util.Collection, int, int)
public static void moveItemToEnd(java.util.Collection c,
java.lang.Object element)
element in the collection c
to the end of the collection, and preserves the order of the collection.
- Parameters:
c - the datastructure that extends Collection and contains the elements of interestelement - the element to move to the end of the collection- See Also:
moveItem(java.util.Collection, java.lang.Object, int)
public static void moveItemToStart(java.util.Collection c,
java.lang.Object element)
element in the collection c
to the beginning of the collection, and preserves the order of the collection.
c - the datastructure that extends Collection and contains the elements of interestelement - the element to move to the beginning of the collectionmoveItem(java.util.Collection, java.lang.Object, int)
public static void orderItems(java.util.Collection c,
boolean orderAscending)
orderAscending parameter. Each element of the collection
must be of the same type and must implement the Comparable interface.
If the collection type is determined to be String, then an attempt is made
to see if the Strings represent numbers, and if so the collection is sorted by the
numerical values, otherwise by the lexigraphical values.
c - the datastructure that extends Collection and contains the elements of interestorderAscending - true if the collection should be sorting in ASCending fashion;
false if the collection should be sorted in DESCending fasionpublic static void removeDuplicates(java.util.Collection c)
Object.equals(java.lang.Object) method as the comparison operator.
c - the datastructure that extends Collection and contains the elements of interestpublic static void reverseOrder(java.util.Collection c)
Collection.
c - the datastructure that extends Collection and contains the elements of interest
public static void swapItems(java.util.Collection c,
java.lang.Object elementOne,
java.lang.Object elementTwo)
c - the datastructure that extends Collection and contains the elements of interestelementOne - the first element to move.
Its current position will be occupied by elementTwo after the swap is performedelementTwo - the second element to move
Its current position will be occupied by elementOne after the swap is performed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||