|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectariba.util.core.ListUtil
public abstract class ListUtil
List Utilities. These are helper functions for dealing with lists.
| Nested Class Summary | |
|---|---|
static class |
ListUtil.Comparator<T extends 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 List |
ImmutableEmptyList
Deprecated. use Collections.emptyList() instead |
static Class |
ImmutableListClass
|
| Constructor Summary | |
|---|---|
ListUtil()
|
|
| Method Summary | ||
|---|---|---|
static
|
addElementIfAbsent(List<T> l,
T element)
Adds element as the last element of the List, if not already present within the List. |
|
static
|
addElementsIfAbsent(List<T> destList,
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
|
addToCollection(Collection<? super T> collection,
T[] toAdd)
Simple convenience method that adds the array elements in toAdd
to the collection. |
|
static void |
appendAndRemoveIfPresent(List destList,
Collection aColl)
Adds the elements contained in aList; delete the old element if existed |
|
static void |
appendAndRemoveIfPresent(List l,
Object element)
Adds element as the last element of the List; delete the old element if existed . |
|
static
|
arrayToList(T[] array)
Creates a List from the objects in the given array. |
|
static
|
arrayToList(T[] array,
boolean copy)
Creates a List from the objects in the given array. |
|
static
|
cloneList(List<? extends T> l)
Helper method to clone a List. |
|
static
|
collectionToList(Collection<T> source)
Creates a new List with the same contents as the given Collection. |
|
static int |
compare(List first,
List second,
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
|
containsIdentical(List<T> l,
T element)
Checks if the list contains the element element using the == operator. |
|
static int |
copyInto(List from,
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(List l,
Object[] anArray,
int startingAt)
Copies the List's elements into anArray at a specified offset. |
|
static List |
copyList(List source)
Copy a Collection. |
|
static ListUtil.Comparator |
createComparator(Comparator elementComparator)
Returns a new instance of ListUtil.Comparator with the
specified elementComparator. |
|
static List<String> |
delimitedStringToList(String str,
char delimiter)
Tokenize a String with a specified separator character and return a list with the tokenized elements. |
|
static List |
diff(List change,
List baseline)
|
|
static List |
equalElements(List l1,
List l2)
Determine all elements common between two Lists. |
|
static
|
firstElement(List<T> l)
Returns the List's first element without modification of the List. |
|
static int |
getListSize(List<?> list)
Null safe method to check the length of a List. |
|
static
|
hasSameElements(List<T> l1,
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
|
immutableList(List<? extends T> l)
Returns a version of the list that is not modifiable If l is null, null will be returned. |
|
static
|
indexOfIdentical(List<T> l,
T element)
Finds the location of an element in the List using the == operator for comparison. |
|
static
|
insertElementAfter(List<T> l,
T element,
T existingElement)
Inserts element after existingElement in the List. |
|
static
|
insertElementBefore(List<T> l,
T element,
T existingElement)
Inserts element before existingElement in the List. |
|
static
|
isSubList(List<T> subList,
List<T> l)
Returns true if list subList is the subList of
list l. |
|
static
|
lastElement(List<T> l)
Returns the List's last element without modification of the List. |
|
static
|
lastIndexOfIdentical(List<T> l,
T element)
Finds the last location of an element in the List using the == operator for comparison. |
|
static
|
lastIndexOfIdentical(List<T> l,
T element,
int startingAt)
Finds the last location of an element in the List using the == operator for comparison. |
|
static
|
list()
Constructs a new type-safe List with a small initial capacity. |
|
static
|
list(int initialCapacity)
Primitive constructor. |
|
static List |
list(Object a,
Object b,
Object c)
Helper function to create a new List containing three Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d)
Helper function to create a new List containing four Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e)
Helper function to create a new List containing five Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f)
Helper function to create a new List containing six Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g)
Helper function to create a new List containing seven Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h)
Helper function to create a new List containing eight Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i)
Helper function to create a new List containing nine Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i,
Object j)
Helper function to create a new List containing ten Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i,
Object j,
Object k)
Helper function to create a new List containing eleven Objects. |
|
static List |
list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i,
Object j,
Object k,
Object l)
Helper function to create a new List containing twelve Objects. |
|
static
|
list(T object)
Helper function to create a new List containing one Object. |
|
static
|
list(T a,
T b)
Helper function to create a new List containing two Objects. |
|
static boolean |
listEquals(List v1,
List v2)
Determine if the two lists are equal. |
|
static String |
listToCSVString(List l)
Generate a comma separated list of strings from a List. |
|
static
|
listToEnumeration(List<T> list)
A simple wrapper to convert a List to an Enumeration. |
|
static String |
listToString(List l,
String separator)
Generate a string from a list, separating the elements with the specified string. |
|
static
|
minus(List<T> l1,
List<T> l2)
Returns values in one list which are not present in the other |
|
static boolean |
nullOrEmptyList(List<?> list)
Determine if a List is null or empty. |
|
static void |
readExternal(List l,
ObjectInput input)
Reads object data from the given input and restores the contents of the given List. |
|
static
|
removeAll(List<T> l,
T o)
Removes all occurrences of element from the Vector. |
|
static
|
removeElementIdentical(List<T> l,
T element)
Finds the location of an element in the List using the == operator for comparison. |
|
static void |
removeEqualElements(List v1,
List v2)
Removes all elements from the two lists v1 and v2 which are contained in both. |
|
static
|
removeFirstElement(List<T> l)
Removes and returns the element at index 0, or null if the List is empty. |
|
static
|
removeLastElement(List<T> l)
Removes and returns the element at the end (size-1), or null if the List is empty. |
|
static Object |
replace(List list,
Object o,
Object n)
Replaces the element o with n. |
|
static
|
reverse(List<T> list)
Return a new list with the keys reversed. |
|
static void |
sortStrings(List<String> l,
boolean ascending)
Sorts the List's contents. |
|
static void |
sortStrings(List<String> l,
boolean ascending,
boolean ignoreCase)
Sorts the List's contents, presuming all elements are of type String. |
|
static
|
subList(Collection<V> values,
int fromIndex,
int toIndex)
|
|
static
|
subList(Collection<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(List l,
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 |
|---|
public static List ImmutableEmptyList
Collections.emptyList() instead
public static final Class ImmutableListClass
| Constructor Detail |
|---|
public ListUtil()
| Method Detail |
|---|
public static <T> List<T> list()
List:List<X> typesafe = ListUtil.list()
List:List raw = ListUtil.list()
public static <T> List<T> list(int initialCapacity)
List:List<X> typesafe = ListUtil.list()
List:List raw = ListUtil.list()
initialCapacity - the initial capacity; must be greater
than or equal to zero
public static <T> List<T> cloneList(List<? extends T> l)
l - the list to clone
public static <V> List<V> subList(Collection<V> values,
int fromIndex,
int toIndex,
boolean createNewList)
values
from index fromIndex (inclusive) to toIndex
(exclusive).
values - the collection of valuesfromIndex - the beginning index, inclusivetoIndex - the end index, exclusivecreateNewList - 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)
public static <V> List<V> subList(Collection<V> values,
int fromIndex,
int toIndex)
public static <T> List<T> arrayToList(T[] array)
array - the array to use as the initial contents of the
list
public static <T> List<T> arrayToList(T[] array,
boolean copy)
array - the array to use as the initial contents of the
listcopy - 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.
public static <T> List<T> collectionToList(Collection<T> source)
source - The collection to copy
public static List<String> delimitedStringToList(String str,
char delimiter)
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"
str - a string to tokenizedelimiter - the delimiter to use when tokenizing
StringUtil.delimitedStringToArray(java.lang.String, char)public static List copyList(List source)
source - the source list to copy.
public static <T> void addElementIfAbsent(List<T> l,
T element)
l - the List to add toelement - the element to add
NullPointerException - if element is null.
public static <T> void addToCollection(Collection<? super T> collection,
T[] toAdd)
toAdd
to the collection.
collection - the collection to add the elements to; may not be
nulltoAdd - the array containing the elements to add; may not be
null
public static <T> void addElementsIfAbsent(List<T> destList,
Collection<? extends T> aColl)
destList - the list to add elements toaColl - a collection of the elements to be added to destList
public static void appendAndRemoveIfPresent(List l,
Object element)
l - the List to add toelement - the element to add
NullPointerException - if element is null.
public static void appendAndRemoveIfPresent(List destList,
Collection aColl)
destList - the list to add elements toaColl - a collection of the elements to be added to destList
public static <T> boolean containsIdentical(List<T> l,
T element)
l - the list to searchelement - the element to search for; the ==
operator is used for comparison
public static <T> int indexOfIdentical(List<T> l,
T element)
element - the element to search for. The comparison is
performed using == with each element.l - the list to search
public static <T> int lastIndexOfIdentical(List<T> l,
T element,
int startingAt)
element - the element to search for. The comparison is
performed using == with each element.l - the list to searchstartingAt - the starting element in the list to search
back from
public static <T> int lastIndexOfIdentical(List<T> l,
T element)
element - the element to search for. The comparison is
performed using == with each element.l - the list to search
public static <T> boolean removeElementIdentical(List<T> l,
T element)
element - the element to search for. The comparison is
performed using == with each element.l - the list to search
public static <T> T firstElement(List<T> l)
l - the list to look in
public static <T> T lastElement(List<T> l)
l - the list to look in
public static <T> boolean insertElementAfter(List<T> l,
T element,
T existingElement)
l - the list to insert intoelement - the element to insert into the listexistingElement - the element to insert after. If
existingElement is null or cannot be found, this
method does nothing
NullPointerException - if element is null.
public static <T> boolean insertElementBefore(List<T> l,
T element,
T existingElement)
l - the list to insert intoelement - the element to insert into the listexistingElement - the element to insert before. If
existingElement is null or cannot be found, this
method does nothing
NullPointerException - if element is null.
public static void sortStrings(List<String> l,
boolean ascending)
l - the List to sortascending - if true the List will be sorted in
ascending order, if false in descending order
ClassCastException - if the
List's contents are not all Strings, or are not Comparable.
public static void sortStrings(List<String> l,
boolean ascending,
boolean ignoreCase)
l - the List to sortascending - if true the List will be sorted in
ascending order, if false in descending orderignoreCase - if true the List's Strings will be
sorted in a case insensitive manner, if false in a case
sensitive manner
ClassCastException - if the List's contents are not
all Strings.
public static void copyInto(List l,
Object[] anArray,
int startingAt)
l - the List to copy intoanArray - 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
public static int copyInto(List from,
List to,
int fromIndex,
int length)
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.
from - the List to copy fromto - the List to copy tofromIndex - the index of the first element in from
to copylength - the number of elements of from to copy
public static <T> List<T> list(T object)
object - the Object to add to the List
public static <T> List<T> list(T a,
T b)
a - the first Object to add to the Listb - the second Object to add to the List
public static List list(Object a,
Object b,
Object c)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the Listf - the sixth Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the Listf - the sixth Object to add to the Listg - the seventh Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the Listf - the sixth Object to add to the Listg - the seventh Object to add to the Listh - the eighth Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the Listf - the sixth Object to add to the Listg - the seventh Object to add to the Listh - the eighth Object to add to the Listi - the ninth Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i,
Object j)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the Listf - the sixth Object to add to the Listg - the seventh Object to add to the Listh - the eighth Object to add to the Listi - the ninth Object to add to the Listj - the tenth Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i,
Object j,
Object k)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the Listf - the sixth Object to add to the Listg - the seventh Object to add to the Listh - the eighth Object to add to the Listi - the ninth Object to add to the Listj - the tenth Object to add to the Listk - the eleventh Object to add to the List
public static List list(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i,
Object j,
Object k,
Object l)
a - the first Object to add to the Listb - the second Object to add to the Listc - the third Object to add to the Listd - the fourth Object to add to the Liste - the fifth Object to add to the Listf - the sixth Object to add to the Listg - the seventh Object to add to the Listh - the eighth Object to add to the Listi - the ninth Object to add to the Listj - the tenth Object to add to the Listk - the eleventh Object to add to the Listl - the twelfth Object to add to the List
public static int getListSize(List<?> list)
list - a list to check the size of. null is an
acceptable value for this argument.
public static boolean nullOrEmptyList(List<?> list)
list - a List object to check
public static <T> T removeFirstElement(List<T> l)
l - the List object to process
public static <T> T removeLastElement(List<T> l)
l - the List object to process
public static <T> void removeAll(List<T> l,
T o)
l - the list to remove fromo - the element to remove.
public static void removeEqualElements(List v1,
List v2)
v1 - the first Listv2 - the second List
public static List equalElements(List l1,
List l2)
l1 - the first Listl2 - the second List
public static String listToCSVString(List l)
l - a List of objects to put into the string
public static String listToString(List l,
String separator)
l - a List of objects to put into the stringseparator - a String that should separate each element of l
public static boolean listEquals(List v1,
List v2)
v1 - the first Listv2 - the second List
public static <T> List<T> reverse(List<T> list)
list - the list to reverse
public static Object replace(List list,
Object o,
Object n)
list - the list to searcho - which element to replacen - the element to replace the existing element with
NullPointerException - if n is
nullpublic static <T> List<T> immutableList(List<? extends T> l)
public static void writeExternal(List l,
ObjectOutput output)
throws IOException
l - the list to write fromoutput - the stream to write the object to
IOException - Includes any I/O exceptions that may occur
public static void readExternal(List l,
ObjectInput input)
throws IOException,
ClassNotFoundException
input - the stream to read data from in order to restore the objectl - the list to read into
IOException - if I/O errors occur
ClassNotFoundException - If the class for an object being
restored cannot be found.
public static <T> boolean isSubList(List<T> subList,
List<T> l)
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]
subList - the sub listl - the containing list
true if l contains all the elements of subList
consecutively
public static <T> boolean hasSameElements(List<T> l1,
List<T> l2)
l1 - one listl2 - the other list
true if the content of the two lists is identical
without necessary using the same order
public static <T> List<T> minus(List<T> l1,
List<T> l2)
l1 - one listl2 - the other list
l1 which are not present in
the otherpublic static ListUtil.Comparator createComparator(Comparator elementComparator)
ListUtil.Comparator with the
specified elementComparator.
elementComparator - the element Comparator the
ListUtil.Comparator will use
public static int compare(List first,
List second,
Comparator elementComparator)
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.
first - the first List; may not be nullsecond - the second List; may not be nullelementComparator - the Comparator to be used
when comparing elements of the Lists; may be
null in which case the elements are assumed to
be Comparables
NullPointerException - if either of first or
second is nullpublic static <T> Enumeration<T> listToEnumeration(List<T> list)
list - the List to convert to an Enumeration
public static List diff(List change,
List baseline)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||