public class PredicatedList<E> extends PredicatedCollection<E> implements List<E>
List to validate that all additions
match a specified predicate.
This list exists to provide validation for the decorated list. It is normally created to decorate an empty list. If an object cannot be added to the list, an IllegalArgumentException is thrown.
One usage would be to ensure that no null entries are added to the list.
List list = PredicatedList.decorate(new ArrayList(), NotNullPredicate.INSTANCE);
This class is Serializable from Commons Collections 3.1.
| Modifier and Type | Class and Description |
|---|---|
protected class |
PredicatedList.PredicatedListIterator
Inner class Iterator for the PredicatedList
|
predicate| Modifier | Constructor and Description |
|---|---|
protected |
PredicatedList(List<E> list,
Predicate<? super E> predicate)
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
E object) |
boolean |
addAll(int index,
Collection<? extends E> coll) |
protected List<E> |
decorated()
Gets the list being decorated.
|
E |
get(int index) |
int |
indexOf(Object object) |
int |
lastIndexOf(Object object) |
ListIterator<E> |
listIterator() |
ListIterator<E> |
listIterator(int i) |
static <T> PredicatedList<T> |
predicatedList(List<T> list,
Predicate<? super T> predicate)
Factory method to create a predicated (validating) list.
|
E |
remove(int index) |
E |
set(int index,
E object) |
List<E> |
subList(int fromIndex,
int toIndex) |
add, addAll, predicatedCollection, validateclear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toStringprotected PredicatedList(List<E> list, Predicate<? super E> predicate)
If there are any elements already in the list being decorated, they are validated.
list - the list to decorate, must not be nullpredicate - the predicate to use for validation, must not be nullIllegalArgumentException - if list or predicate is nullIllegalArgumentException - if the list contains invalid elementspublic static <T> PredicatedList<T> predicatedList(List<T> list, Predicate<? super T> predicate)
If there are any elements already in the list being decorated, they are validated.
T - the type of the elements in the listlist - the list to decorate, must not be nullpredicate - the predicate to use for validation, must not be nullIllegalArgumentException - if list or predicate is nullIllegalArgumentException - if the list contains invalid elementsprotected List<E> decorated()
decorated in class AbstractCollectionDecorator<E>public int lastIndexOf(Object object)
lastIndexOf in interface List<E>public boolean addAll(int index, Collection<? extends E> coll)
public ListIterator<E> listIterator()
listIterator in interface List<E>public ListIterator<E> listIterator(int i)
listIterator in interface List<E>Copyright © 2001–2013 The Apache Software Foundation. All rights reserved.