|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.collections.ListUtils
Contains static utility methods and decorators for List
instances.
Constructor Summary | |
ListUtils()
Please don't ever instantiate a ListUtils . |
Method Summary | |
static java.util.List |
fixedSizeList(java.util.List list)
Returns a fixed-sized list backed by the given list. |
static java.util.List |
intersection(java.util.List list1,
java.util.List list2)
Returns a new list containing all elements that are contained in both given lists. |
static java.util.List |
lazyList(java.util.List list,
Factory factory)
Returns a "lazy" list whose elements will be created on demand. |
static java.util.List |
predicatedList(java.util.List list,
Predicate predicate)
Returns a predicated list backed by the given list. |
static java.util.List |
subtract(java.util.List list1,
java.util.List list2)
Subtracts all elements in the second list from the first list, placing the results in a new list. |
static java.util.List |
sum(java.util.List list1,
java.util.List list2)
Returns the sum of the given lists. |
static java.util.List |
union(java.util.List list1,
java.util.List list2)
Returns a new list containing the second list appended to the first list. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ListUtils()
ListUtils
.
Method Detail |
public static java.util.List intersection(java.util.List list1, java.util.List list2)
list1
- the first listlist2
- the second list
java.lang.NullPointerException
- if either list is nullpublic static java.util.List subtract(java.util.List list1, java.util.List list2)
List.removeAll(Collection)
in that
cardinality is respected; if list1
contains two
occurrences of null
and list2
only
contains one occurrence, then the returned list will still contain
one occurrence.
list1
- the list to subtract fromlist2
- the lsit to subtract
java.lang.NullPointerException
- if either list is nullpublic static java.util.List sum(java.util.List list1, java.util.List list2)
list1
- the first listlist2
- the second list
java.lang.NullPointerException
- if either list is nullpublic static java.util.List union(java.util.List list1, java.util.List list2)
List.addAll(Collection)
operation is
used to append the two given lists into a new list.
list1
- the first listlist2
- the second list
java.lang.NullPointerException
- if either list is nullpublic static java.util.List predicatedList(java.util.List list, Predicate predicate)
list
- the list to predicate, must not be nullpredicate
- the predicate for the list, must not be null
java.lang.IllegalArgumentException
- if the List or Predicate is nullpublic static java.util.List lazyList(java.util.List list, Factory factory)
When the index passed to the returned list's get
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 new Date
instance. Furthermore, that Date
instance is the fourth element in the list. The first, second,
and third element are all set to null
.
list
- the list to make lazy, must not be nullfactory
- the factory for creating new objects, must not be null
java.lang.IllegalArgumentException
- if the List or Factory is nullpublic static java.util.List fixedSizeList(java.util.List list)
List.set(int,Object)
method).
list
- the list whose size to fix, must not be null
java.lang.IllegalArgumentException
- if the List is null
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |