ariba.util.core
Class ListUtil

java.lang.Object
  extended by ariba.util.core.ListUtil

public abstract class ListUtil
extends java.lang.Object

List Utilities. These are helper functions for dealing with lists.


Nested Class Summary
static class ListUtil.Comparator<T extends java.util.List<?>>
          Is a java.util.Comparator for Lists based on a supplied elementComparator that delegates to compare(java.util.List, java.util.List, java.util.Comparator) when doing the comparison.
 
Field Summary
static java.util.List ImmutableEmptyList
          Deprecated. use Collections.emptyList() instead
static java.lang.Class ImmutableListClass
           
 
Constructor Summary
ListUtil()
           
 
Method Summary
static
<T> void
addAll(java.util.Collection<? super T> collection, java.lang.Iterable<T> toAdd)
          Simple convenience method that adds the array elements in toAdd to the collection.
static
<T> void
addElementIfAbsent(java.util.List<T> l, T element)
          Adds element as the last element of the List, if not already present within the List.
static
<T> void
addElementsIfAbsent(java.util.List<T> destList, java.util.Collection<? extends T> aColl)
          Adds the elements contained in aList that are not already present in the List to the end of the List.
static
<T> void
addToCollection(java.util.Collection<? super T> collection, T[] toAdd)
          Simple convenience method that adds the array elements in toAdd to the collection.
static void appendAndRemoveIfPresent(java.util.List destList, java.util.Collection aColl)
          Adds the elements contained in aList; delete the old element if existed
static void appendAndRemoveIfPresent(java.util.List l, java.lang.Object element)
          Adds element as the last element of the List; delete the old element if existed .
static
<T> java.util.List<T>
arrayToList(T[] array)
          Creates a List from the objects in the given array.
static
<T> java.util.List<T>
arrayToList(T[] array, boolean copy)
          Creates a List from the objects in the given array.
static
<T> java.util.List<T>
cloneList(java.util.List<? extends T> l)
          Helper method to clone a List.
static
<T> java.util.List<T>
collectionToList(java.util.Collection<T> source)
          Creates a new List with the same contents as the given Collection.
static int compare(java.util.List first, java.util.List second, java.util.Comparator elementComparator)
          Compares the elements of first and second and returns a negative, zero or positive integer as first is less than, equal to or greater than second, respectively.
static
<T> java.util.List<T>
concatenate(java.util.List<T>... lists)
           
static
<T> boolean
containsIdentical(java.util.List<T> l, T element)
          Checks if the list contains the element element using the == operator.
static java.util.List copyAndSortMapInList(java.util.List list)
          This method will do 2 things: 1) Copy objects which are not of type Map into a new List object.
static int copyInto(java.util.List from, java.util.List to, int fromIndex, int length)
          Copies length elements of the list from to the list to starting at the specified fromIndex.
static void copyInto(java.util.List l, java.lang.Object[] anArray, int startingAt)
          Copies the List's elements into anArray at a specified offset.
static java.util.List copyList(java.util.List source)
          Copy a Collection.
static ListUtil.Comparator createComparator(java.util.Comparator elementComparator)
          Returns a new instance of ListUtil.Comparator with the specified elementComparator.
static java.util.List<java.lang.String> delimitedStringToList(java.lang.String str, char delimiter)
          Tokenize a String with a specified separator character and return a list with the tokenized elements.
static java.util.List diff(java.util.List change, java.util.List baseline)
           
static java.util.List equalElements(java.util.List l1, java.util.List l2)
          Determine all elements common between two Lists.
static
<T> T
firstElement(java.util.List<T> l)
          Returns the List's first element without modification of the List.
static void fromSerializedString(java.util.List l, java.lang.String serialized)
          Populates the list with serialized data from the string.
static java.util.List[] getChunkedLists(java.util.List list, int maxChunkSize)
           
static int getListSize(java.util.List<?> list)
          Null safe method to check the length of a List.
static
<T> boolean
hasSameElements(java.util.List<T> l1, java.util.List<T> l2)
          Returns true if the 2 input lists has the same size and contain the same elements, even though the elements may be stored at possibly a different order in the 2 lists.
static
<T> java.util.List<T>
immutableList(java.util.List<? extends T> l)
          Returns a version of the list that is not modifiable If l is null, null will be returned.
static
<T> int
indexOfIdentical(java.util.List<T> l, T element)
          Finds the location of an element in the List using the == operator for comparison.
static
<T> boolean
insertElementAfter(java.util.List<T> l, T element, T existingElement)
          Inserts element after existingElement in the List.
static
<T> boolean
insertElementBefore(java.util.List<T> l, T element, T existingElement)
          Inserts element before existingElement in the List.
static
<T> boolean
isSubList(java.util.List<T> subList, java.util.List<T> l)
          Returns true if list subList is the subList of list l.
static
<T> T
lastElement(java.util.List<T> l)
          Returns the List's last element without modification of the List.
static
<T> int
lastIndexOfIdentical(java.util.List<T> l, T element)
          Finds the last location of an element in the List using the == operator for comparison.
static
<T> int
lastIndexOfIdentical(java.util.List<T> l, T element, int startingAt)
          Finds the last location of an element in the List using the == operator for comparison.
static
<T> java.util.List<T>
list()
          Constructs a new type-safe List with a small initial capacity.
static
<T> java.util.List<T>
list(int initialCapacity)
          Primitive constructor.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c)
          Helper function to create a new List containing three Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d)
          Helper function to create a new List containing four Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e)
          Helper function to create a new List containing five Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e, java.lang.Object f)
          Helper function to create a new List containing six Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e, java.lang.Object f, java.lang.Object g)
          Helper function to create a new List containing seven Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e, java.lang.Object f, java.lang.Object g, java.lang.Object h)
          Helper function to create a new List containing eight Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e, java.lang.Object f, java.lang.Object g, java.lang.Object h, java.lang.Object i)
          Helper function to create a new List containing nine Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e, java.lang.Object f, java.lang.Object g, java.lang.Object h, java.lang.Object i, java.lang.Object j)
          Helper function to create a new List containing ten Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e, java.lang.Object f, java.lang.Object g, java.lang.Object h, java.lang.Object i, java.lang.Object j, java.lang.Object k)
          Helper function to create a new List containing eleven Objects.
static java.util.List list(java.lang.Object a, java.lang.Object b, java.lang.Object c, java.lang.Object d, java.lang.Object e, java.lang.Object f, java.lang.Object g, java.lang.Object h, java.lang.Object i, java.lang.Object j, java.lang.Object k, java.lang.Object l)
          Helper function to create a new List containing twelve Objects.
static
<T> java.util.List<T>
list(T object)
          Helper function to create a new List containing one Object.
static
<T> java.util.List<T>
list(T a, T b)
          Helper function to create a new List containing two Objects.
static
<T> java.util.List<T>
listAddAll(java.util.Collection<T> source)
          Returns new List with all the items in source Collection added to it.
static boolean listEquals(java.util.List v1, java.util.List v2)
          Determine if the two lists are equal.
static java.lang.String listToCSVString(java.util.List l)
          Generate a comma separated list of strings from a List.
static
<T> java.util.Enumeration<T>
listToEnumeration(java.util.List<T> list)
          A simple wrapper to convert a List to an Enumeration.
static java.lang.String listToString(java.util.List l, java.lang.String separator)
          Generate a string from a list, separating the elements with the specified string.
static
<T> java.util.List<T>
minus(java.util.List<T> l1, java.util.List<T> l2)
          Returns values in one list which are not present in the other
static boolean nullOrEmptyList(java.util.List<?> list)
          Determine if a List is null or empty.
static void readExternal(java.util.List l, java.io.ObjectInput input)
          Reads object data from the given input and restores the contents of the given List.
static
<T> void
removeAll(java.util.List<T> l, T o)
          Removes all occurrences of element from the Vector.
static
<T> boolean
removeElementIdentical(java.util.List<T> l, T element)
          Finds the location of an element in the List using the == operator for comparison.
static void removeEqualElements(java.util.List v1, java.util.List v2)
          Removes all elements from the two lists v1 and v2 which are contained in both.
static
<T> T
removeFirstElement(java.util.List<T> l)
          Removes and returns the element at index 0, or null if the List is empty.
static
<T> T
removeLastElement(java.util.List<T> l)
          Removes and returns the element at the end (size-1), or null if the List is empty.
static java.lang.Object replace(java.util.List list, java.lang.Object o, java.lang.Object n)
          Replaces the element o with n.
static
<T> java.util.List<T>
reverse(java.util.List<T> list)
          Return a new list with the keys reversed.
static int size(java.util.Collection list)
           
static void sortStrings(java.util.List<java.lang.String> l, boolean ascending)
          Sorts the List's contents.
static void sortStrings(java.util.List<java.lang.String> l, boolean ascending, boolean ignoreCase)
          Sorts the List's contents, presuming all elements are of type String.
static
<V> java.util.List<V>
subList(java.util.Collection<V> values, int fromIndex, int toIndex)
           
static
<V> java.util.List<V>
subList(java.lang.Iterable<V> values, int fromIndex, int toIndex, boolean createNewList)
          Returns a list which is a sub-collection of values from index fromIndex (inclusive) to toIndex (exclusive).
static void writeExternal(java.util.List l, java.io.ObjectOutput output)
          Writes the List's data out to the given stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ImmutableEmptyList

public static java.util.List ImmutableEmptyList
Deprecated. use Collections.emptyList() instead
An empty immutable list.


ImmutableListClass

public static final java.lang.Class ImmutableListClass
Constructor Detail

ListUtil

public ListUtil()
Method Detail

list

public static <T> java.util.List<T> list()
Constructs a new type-safe List with a small initial capacity.

To construct a type-safe List:

For a raw List: There will be no compile warnings either way.

Returns:
new List

list

public static <T> java.util.List<T> list(int initialCapacity)
Primitive constructor. Constructs a List large enough to hold initialCapacity elements. The List will grow to accommodate additional objects, as needed.

To construct a type-safe List:

For a raw List: There will be no compile warnings either way.

Parameters:
initialCapacity - the initial capacity; must be greater than or equal to zero
Returns:
an empty List with the specified capacity

cloneList

public static <T> java.util.List<T> cloneList(java.util.List<? extends T> l)
Helper method to clone a List.

Parameters:
l - the list to clone
Returns:
a new list of the same type

subList

public static <V> java.util.List<V> subList(java.lang.Iterable<V> values,
                                            int fromIndex,
                                            int toIndex,
                                            boolean createNewList)
Returns a list which is a sub-collection of values from index fromIndex (inclusive) to toIndex (exclusive).

Parameters:
values - the collection of values
fromIndex - the beginning index, inclusive
toIndex - the end index, exclusive
createNewList - if true, this method uses a new list to create the sublist, else this method attempts to use a computationally efficient result which may refer to values (and so is not modifiable)

subList

public static <V> java.util.List<V> subList(java.util.Collection<V> values,
                                            int fromIndex,
                                            int toIndex)

arrayToList

public static <T> java.util.List<T> arrayToList(T[] array)
Creates a List from the objects in the given array. The elements in the array are copied.

Parameters:
array - the array to use as the initial contents of the list
Returns:
a List containing objects from the specified array

arrayToList

public static <T> java.util.List<T> arrayToList(T[] array,
                                                boolean copy)
Creates a List from the objects in the given array. The elements in the array are copied if the boolean is true.

Parameters:
array - the array to use as the initial contents of the list
copy - if true, the array is copied; if false the array is shared. However internal List operations may copy or modify the array at a later point, so sharing the array in a active manner should be avoided.
Returns:
a List containing objects from the specified array

collectionToList

public static <T> java.util.List<T> collectionToList(java.util.Collection<T> source)
Creates a new List with the same contents as the given Collection.

Parameters:
source - The collection to copy
Returns:
List with same contents as Collection

listAddAll

public static <T> java.util.List<T> listAddAll(java.util.Collection<T> source)
Returns new List with all the items in source Collection added to it. Combines ListUtil.list() and List addAll(Collection). Is easier to type and remember than collectionToList. Throws NullPointerException if source is null.


delimitedStringToList

public static java.util.List<java.lang.String> delimitedStringToList(java.lang.String str,
                                                                     char delimiter)
Tokenize a String with a specified separator character and return a list with the tokenized elements.

Takes a string in the form "Description.Price.Amount" with a delimiter of '.' and turns it into an list of strings:

        list.get(0) = "Description"
        list.get(1) = "Price"
        list.get(2) = "Amount"
        

Parameters:
str - a string to tokenize
delimiter - the delimiter to use when tokenizing
Returns:
a list of Strings containing each substring but excluding the delimiter character
See Also:
StringUtil.delimitedStringToArray(java.lang.String, char)

fromSerializedString

public static void fromSerializedString(java.util.List l,
                                        java.lang.String serialized)
Populates the list with serialized data from the string.

Parameters:
serialized - String containing serialized list data

copyList

public static java.util.List copyList(java.util.List source)
Copy a Collection. This method will copy the source list and output a destination list. For each list or hastable within the source list they will also be copied, all other types will be shared. So for a list of lists or hashtables, this will recurse.

Parameters:
source - the source list to copy.
Returns:
the destination list.

copyAndSortMapInList

public static java.util.List copyAndSortMapInList(java.util.List list)
This method will do 2 things: 1) Copy objects which are not of type Map into a new List object. 2) Copy the contents of the Map entries into a SortedMap and then copy the SortedMap back into the List.

Parameters:
list -
Returns:
a List with its original ordering intact and Map objects copied into a SortedMap.

addElementIfAbsent

public static <T> void addElementIfAbsent(java.util.List<T> l,
                                          T element)
Adds element as the last element of the List, if not already present within the List.

Parameters:
l - the List to add to
element - the element to add
Throws:
java.lang.NullPointerException - if element is null.

addToCollection

public static <T> void addToCollection(java.util.Collection<? super T> collection,
                                       T[] toAdd)
Simple convenience method that adds the array elements in toAdd to the collection.

Parameters:
collection - the collection to add the elements to; may not be null
toAdd - the array containing the elements to add; may not be null

addAll

public static <T> void addAll(java.util.Collection<? super T> collection,
                              java.lang.Iterable<T> toAdd)
Simple convenience method that adds the array elements in toAdd to the collection.

Parameters:
collection - the collection to add the elements to; may not be null
toAdd - the array containing the elements to add; may not be null

addElementsIfAbsent

public static <T> void addElementsIfAbsent(java.util.List<T> destList,
                                           java.util.Collection<? extends T> aColl)
Adds the elements contained in aList that are not already present in the List to the end of the List.

Parameters:
destList - the list to add elements to
aColl - a collection of the elements to be added to destList

appendAndRemoveIfPresent

public static void appendAndRemoveIfPresent(java.util.List l,
                                            java.lang.Object element)
Adds element as the last element of the List; delete the old element if existed .

Parameters:
l - the List to add to
element - the element to add
Throws:
java.lang.NullPointerException - if element is null.

appendAndRemoveIfPresent

public static void appendAndRemoveIfPresent(java.util.List destList,
                                            java.util.Collection aColl)
Adds the elements contained in aList; delete the old element if existed

Parameters:
destList - the list to add elements to
aColl - a collection of the elements to be added to destList

containsIdentical

public static <T> boolean containsIdentical(java.util.List<T> l,
                                            T element)
Checks if the list contains the element element using the == operator.

Parameters:
l - the list to search
element - the element to search for; the == operator is used for comparison
Returns:
true if the List contains element, false otherwise

indexOfIdentical

public static <T> int indexOfIdentical(java.util.List<T> l,
                                       T element)
Finds the location of an element in the List using the == operator for comparison.

Parameters:
element - the element to search for. The comparison is performed using == with each element.
l - the list to search
Returns:
the index of element in the List. Returns -1 if the element is not present.

lastIndexOfIdentical

public static <T> int lastIndexOfIdentical(java.util.List<T> l,
                                           T element,
                                           int startingAt)
Finds the last location of an element in the List using the == operator for comparison.

Parameters:
element - the element to search for. The comparison is performed using == with each element.
l - the list to search
startingAt - the starting element in the list to search back from
Returns:
the index of element in the List. Returns -1 if the element is not present.

lastIndexOfIdentical

public static <T> int lastIndexOfIdentical(java.util.List<T> l,
                                           T element)
Finds the last location of an element in the List using the == operator for comparison.

Parameters:
element - the element to search for. The comparison is performed using == with each element.
l - the list to search
Returns:
the index of element in the List. Returns -1 if the element is not present.

removeElementIdentical

public static <T> boolean removeElementIdentical(java.util.List<T> l,
                                                 T element)
Finds the location of an element in the List using the == operator for comparison.

Parameters:
element - the element to search for. The comparison is performed using == with each element.
l - the list to search
Returns:
the index of element in the List. Returns -1 if the element is not present.

firstElement

public static <T> T firstElement(java.util.List<T> l)
Returns the List's first element without modification of the List.

Parameters:
l - the list to look in
Returns:
the first element, or null if there are no elements.

lastElement

public static <T> T lastElement(java.util.List<T> l)
Returns the List's last element without modification of the List.

Parameters:
l - the list to look in
Returns:
the last element, or null if there are no elements.

insertElementAfter

public static <T> boolean insertElementAfter(java.util.List<T> l,
                                             T element,
                                             T existingElement)
Inserts element after existingElement in the List.

Parameters:
l - the list to insert into
element - the element to insert into the list
existingElement - the element to insert after. If existingElement is null or cannot be found, this method does nothing
Returns:
true if element was inserted and false if it was not.
Throws:
java.lang.NullPointerException - if element is null.

insertElementBefore

public static <T> boolean insertElementBefore(java.util.List<T> l,
                                              T element,
                                              T existingElement)
Inserts element before existingElement in the List.

Parameters:
l - the list to insert into
element - the element to insert into the list
existingElement - the element to insert before. If existingElement is null or cannot be found, this method does nothing
Returns:
true if element was inserted and false if it was not.
Throws:
java.lang.NullPointerException - if element is null.

sortStrings

public static void sortStrings(java.util.List<java.lang.String> l,
                               boolean ascending)
Sorts the List's contents. String comparisons are case sensitive.

Parameters:
l - the List to sort
ascending - if true the List will be sorted in ascending order, if false in descending order
Throws:
java.lang.ClassCastException - if the List's contents are not all Strings, or are not Comparable.

sortStrings

public static void sortStrings(java.util.List<java.lang.String> l,
                               boolean ascending,
                               boolean ignoreCase)
Sorts the List's contents, presuming all elements are of type String.

Parameters:
l - the List to sort
ascending - if true the List will be sorted in ascending order, if false in descending order
ignoreCase - if true the List's Strings will be sorted in a case insensitive manner, if false in a case sensitive manner
Throws:
java.lang.ClassCastException - if the List's contents are not all Strings.

copyInto

public static void copyInto(java.util.List l,
                            java.lang.Object[] anArray,
                            int startingAt)
Copies the List's elements into anArray at a specified offset. This array must be large enough to contain the elements.

Parameters:
l - the List to copy into
anArray - the array to copy the List's elements into. Any elements existing in anArray beyond the count of elements copied from this List are left unchanged.
startingAt - the location in anArray to begin copying into

copyInto

public static int copyInto(java.util.List from,
                           java.util.List to,
                           int fromIndex,
                           int length)
Copies length elements of the list from to the list to starting at the specified fromIndex.

Regardless of how big length actually is, we stop copying when we reach the end of from. The actual number of elements copied is returned.

Parameters:
from - the List to copy from
to - the List to copy to
fromIndex - the index of the first element in from to copy
length - the number of elements of from to copy
Returns:
the number of elements copied

list

public static <T> java.util.List<T> list(T object)
Helper function to create a new List containing one Object.

Parameters:
object - the Object to add to the List
Returns:
a new List containing the specified object

list

public static <T> java.util.List<T> list(T a,
                                         T b)
Helper function to create a new List containing two Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c)
Helper function to create a new List containing three Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d)
Helper function to create a new List containing four Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e)
Helper function to create a new List containing five Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e,
                                  java.lang.Object f)
Helper function to create a new List containing six Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
f - the sixth Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e,
                                  java.lang.Object f,
                                  java.lang.Object g)
Helper function to create a new List containing seven Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
f - the sixth Object to add to the List
g - the seventh Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e,
                                  java.lang.Object f,
                                  java.lang.Object g,
                                  java.lang.Object h)
Helper function to create a new List containing eight Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
f - the sixth Object to add to the List
g - the seventh Object to add to the List
h - the eighth Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e,
                                  java.lang.Object f,
                                  java.lang.Object g,
                                  java.lang.Object h,
                                  java.lang.Object i)
Helper function to create a new List containing nine Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
f - the sixth Object to add to the List
g - the seventh Object to add to the List
h - the eighth Object to add to the List
i - the ninth Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e,
                                  java.lang.Object f,
                                  java.lang.Object g,
                                  java.lang.Object h,
                                  java.lang.Object i,
                                  java.lang.Object j)
Helper function to create a new List containing ten Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
f - the sixth Object to add to the List
g - the seventh Object to add to the List
h - the eighth Object to add to the List
i - the ninth Object to add to the List
j - the tenth Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e,
                                  java.lang.Object f,
                                  java.lang.Object g,
                                  java.lang.Object h,
                                  java.lang.Object i,
                                  java.lang.Object j,
                                  java.lang.Object k)
Helper function to create a new List containing eleven Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
f - the sixth Object to add to the List
g - the seventh Object to add to the List
h - the eighth Object to add to the List
i - the ninth Object to add to the List
j - the tenth Object to add to the List
k - the eleventh Object to add to the List
Returns:
a new List containing the specified objects

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b,
                                  java.lang.Object c,
                                  java.lang.Object d,
                                  java.lang.Object e,
                                  java.lang.Object f,
                                  java.lang.Object g,
                                  java.lang.Object h,
                                  java.lang.Object i,
                                  java.lang.Object j,
                                  java.lang.Object k,
                                  java.lang.Object l)
Helper function to create a new List containing twelve Objects.

Parameters:
a - the first Object to add to the List
b - the second Object to add to the List
c - the third Object to add to the List
d - the fourth Object to add to the List
e - the fifth Object to add to the List
f - the sixth Object to add to the List
g - the seventh Object to add to the List
h - the eighth Object to add to the List
i - the ninth Object to add to the List
j - the tenth Object to add to the List
k - the eleventh Object to add to the List
l - the twelfth Object to add to the List
Returns:
a new List containing the specified objects

getListSize

public static int getListSize(java.util.List<?> list)
Null safe method to check the length of a List.

Parameters:
list - a list to check the size of. null is an acceptable value for this argument.
Returns:
the length of the list, or zero if it is null.

nullOrEmptyList

public static boolean nullOrEmptyList(java.util.List<?> list)
Determine if a List is null or empty.

Parameters:
list - a List object to check
Returns:
true if list is null or empty, false otherwise

removeFirstElement

public static <T> T removeFirstElement(java.util.List<T> l)
Removes and returns the element at index 0, or null if the List is empty.

Parameters:
l - the List object to process
Returns:
the first element that was in the list, but has now been removed.

removeLastElement

public static <T> T removeLastElement(java.util.List<T> l)
Removes and returns the element at the end (size-1), or null if the List is empty.

Parameters:
l - the List object to process
Returns:
the last element that was in the list, but has now been removed.

removeAll

public static <T> void removeAll(java.util.List<T> l,
                                 T o)
Removes all occurrences of element from the Vector.

Parameters:
l - the list to remove from
o - the element to remove.

removeEqualElements

public static void removeEqualElements(java.util.List v1,
                                       java.util.List v2)
Removes all elements from the two lists v1 and v2 which are contained in both. If a particular element appears N times in v1 and M times in v2, it will be deleted min(N, M) times from both lists.

Parameters:
v1 - the first List
v2 - the second List

equalElements

public static java.util.List equalElements(java.util.List l1,
                                           java.util.List l2)
Determine all elements common between two Lists.

Parameters:
l1 - the first List
l2 - the second List
Returns:
a list of all elements common to v1 and v2.The comparison is made using List.contains().

listToCSVString

public static java.lang.String listToCSVString(java.util.List l)
Generate a comma separated list of strings from a List.

Parameters:
l - a List of objects to put into the string
Returns:
a comma separated list of the strings in l

listToString

public static java.lang.String listToString(java.util.List l,
                                            java.lang.String separator)
Generate a string from a list, separating the elements with the specified string. Include a space on the separator if you want spaces after the separator literal.

Parameters:
l - a List of objects to put into the string
separator - a String that should separate each element of l
Returns:
a String containing elements of l separated by separator

listEquals

public static boolean listEquals(java.util.List v1,
                                 java.util.List v2)
Determine if the two lists are equal. Note: this is different from List.equals() method because this one is recursive.

Parameters:
v1 - the first List
v2 - the second List
Returns:
true if the two lists are equal, false otherwise

reverse

public static <T> java.util.List<T> reverse(java.util.List<T> list)
Return a new list with the keys reversed.

Parameters:
list - the list to reverse
Returns:
a new list with the keys in the opposite order

replace

public static java.lang.Object replace(java.util.List list,
                                       java.lang.Object o,
                                       java.lang.Object n)
Replaces the element o with n.

Parameters:
list - the list to search
o - which element to replace
n - the element to replace the existing element with
Returns:
o if it was replaced or null if it was not found.
Throws:
java.lang.NullPointerException - if n is null

immutableList

public static <T> java.util.List<T> immutableList(java.util.List<? extends T> l)
Returns a version of the list that is not modifiable If l is null, null will be returned.


writeExternal

public static void writeExternal(java.util.List l,
                                 java.io.ObjectOutput output)
                          throws java.io.IOException
Writes the List's data out to the given stream.

Parameters:
l - the list to write from
output - the stream to write the object to
Throws:
java.io.IOException - Includes any I/O exceptions that may occur

readExternal

public static void readExternal(java.util.List l,
                                java.io.ObjectInput input)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Reads object data from the given input and restores the contents of the given List.

Parameters:
input - the stream to read data from in order to restore the object
l - the list to read into
Throws:
java.io.IOException - if I/O errors occur
java.lang.ClassNotFoundException - If the class for an object being restored cannot be found.

isSubList

public static <T> boolean isSubList(java.util.List<T> subList,
                                    java.util.List<T> l)
Returns true if list subList is the subList of list l.
        For example, if list l is A[1..n], list subList is B[1..m], l contains
        the whole list subList if and only if
            A1, A2, A3, A4, ..., Am+2, ... An
                    B1, B2, ..., Bm
        such that A[3] == B[1], A[4] == B[2], ... , A[m+2] = B[m]
        

Parameters:
subList - the sub list
l - the containing list
Returns:
true if l contains all the elements of subList consecutively

hasSameElements

public static <T> boolean hasSameElements(java.util.List<T> l1,
                                          java.util.List<T> l2)
Returns true if the 2 input lists has the same size and contain the same elements, even though the elements may be stored at possibly a different order in the 2 lists.

Parameters:
l1 - one list
l2 - the other list
Returns:
true if the content of the two lists is identical without necessary using the same order

minus

public static <T> java.util.List<T> minus(java.util.List<T> l1,
                                          java.util.List<T> l2)
Returns values in one list which are not present in the other

Parameters:
l1 - one list
l2 - the other list
Returns:
values in one list (l1 which are not present in the other

createComparator

public static ListUtil.Comparator createComparator(java.util.Comparator elementComparator)
Returns a new instance of ListUtil.Comparator with the specified elementComparator.

Parameters:
elementComparator - the element Comparator the ListUtil.Comparator will use
Returns:
the new comparator

compare

public static int compare(java.util.List first,
                          java.util.List second,
                          java.util.Comparator elementComparator)
Compares the elements of first and second and returns a negative, zero or positive integer as first is less than, equal to or greater than second, respectively.

Everything else being equal, longer lists are greater than shorter lists.

Parameters:
first - the first List; may not be null
second - the second List; may not be null
elementComparator - the Comparator to be used when comparing elements of the Lists; may be null in which case the elements are assumed to be Comparables
Returns:
the result of the comparison
Throws:
java.lang.NullPointerException - if either of first or second is null

listToEnumeration

public static <T> java.util.Enumeration<T> listToEnumeration(java.util.List<T> list)
A simple wrapper to convert a List to an Enumeration. NOTE: the Enumeration returned is not thread safe.

Parameters:
list - the List to convert to an Enumeration
Returns:
an enumeration wrapped around the list

diff

public static java.util.List diff(java.util.List change,
                                  java.util.List baseline)

getChunkedLists

public static java.util.List[] getChunkedLists(java.util.List list,
                                               int maxChunkSize)

size

public static int size(java.util.Collection list)

concatenate

public static <T> java.util.List<T> concatenate(java.util.List<T>... lists)


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.