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<String> list = PredicatedList.predicatedList(new ArrayList<String>(), PredicateUtils.notNullPredicate());
This class is Serializable from Commons Collections 3.1.
| Modifier and Type | Class and Description |
|---|---|
protected class |
PredicatedList
Inner class Iterator for the PredicatedList
|
PredicatedCollection.Builder <E> predicate| Modifier | Constructor and Description |
|---|---|
protected |
PredicatedList(List
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index, E object)
|
boolean |
addAll(int index, Collection
|
protected List |
decorated()
Gets the list being decorated.
|
boolean |
equals(Object
|
E |
get(int index)
|
int |
hashCode()
|
int |
indexOf(Object
|
int |
lastIndexOf(Object
|
ListIterator |
listIterator()
|
ListIterator |
listIterator(int i)
|
static <T> PredicatedList |
predicatedList(List
Factory method to create a predicated (validating) list.
|
E |
remove(int index)
|
E |
set(int index, E object)
|
List |
subList(int fromIndex, int toIndex)
|
add, addAll, builder, notNullBuilder, predicatedCollection, validateclear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArrayparallelStream, removeIf, streamprotected 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 null
predicate - the predicate to use for validation, must not be null
NullPointerException - if list or predicate is null
IllegalArgumentException - if the list contains invalid elements
public 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 list
list - the list to decorate, must not be null
predicate - the predicate to use for validation, must not be null
NullPointerException - if list or predicate is null
IllegalArgumentException - if the list contains invalid elements
protected List<E> decorated()
decorated in class
AbstractCollectionDecorator<E>
public boolean equals(Objectobject)
public int hashCode()
public E get(int index)
public int indexOf(Objectobject)
public int lastIndexOf(Objectobject)
public E remove(int index)
public void add(int index,
E object)public boolean addAll(int index,
Collection<? extends E> coll) public ListIterator<E> listIterator()
public ListIterator<E> listIterator(int i)