Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.collections.ListUtils
public class ListUtils
extends java.lang.Object
List
instances.
Constructor Summary | |
|
Method Summary | |
static List |
|
static List |
|
static List | |
static List |
|
static List |
|
static List |
|
static List |
|
public static List fixedSizeList(List list)
Returns a fixed-sized list backed by the given list. Elements may not be added or removed from the returned list, but existing elements can be changed (for instance, via theList.set(int,Object)
method).
- Parameters:
list
- the list whose size to fix, must not be null
- Returns:
- a fixed-size list backed by that list
public static List intersection(List list1, List list2)
Returns a new list containing all elements that are contained in both given lists.
- Parameters:
list1
- the first listlist2
- the second list
- Returns:
- the intersection of those two lists
public static List lazyList(List list, Factory factory)
Returns a "lazy" list whose elements will be created on demand. When the index passed to the returned list'sget
method is greater than the list's size, then the factory will be used to create a new object and that object will be inserted at that index. For instance:Factory factory = new Factory() { public Object create() { return new Date(); } } List lazy = ListUtils.lazyList(new ArrayList(), factory); Object obj = lazy.get(3);After the above code is executed,obj
will contain a newDate
instance. Furthermore, thatDate
instance is the fourth element in the list. The first, second, and third element are all set tonull
.
- Parameters:
list
- the list to make lazy, must not be nullfactory
- the factory for creating new objects, must not be null
- Returns:
- a lazy list backed by the given list
public static List predicatedList(List list, Predicate predicate)
Returns a predicated list backed by the given list. Only objects that pass the test in the given predicate can be added to the list. It is important not to use the original list after invoking this method, as it is a backdoor for adding unvalidated objects.
- Parameters:
list
- the list to predicate, must not be nullpredicate
- the predicate for the list, must not be null
- Returns:
- a predicated list backed by the given list
public static List subtract(List list1, List list2)
Subtracts all elements in the second list from the first list, placing the results in a new list. This differs fromList.removeAll(Collection)
in that cardinality is respected; iflist1
contains two occurrences ofnull
andlist2
only contains one occurrence, then the returned list will still contain one occurrence.
- Parameters:
list1
- the list to subtract fromlist2
- the lsit to subtract
- Returns:
- a new list containing the results
public static List sum(List list1, List list2)
Returns the sum of the given lists. This is their intersection subtracted from their union.
- Parameters:
list1
- the first listlist2
- the second list
- Returns:
- a new list containing the sum of those lists
public static List union(List list1, List list2)
Returns a new list containing the second list appended to the first list. TheList.addAll(Collection)
operation is used to append the two given lists into a new list.
- Parameters:
list1
- the first listlist2
- the second list
- Returns:
- a new list containing the union of those lists