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.PredicatedListIterator
Inner class Iterator for the PredicatedList
|
PredicatedCollection.Builder<E>
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.
|
boolean |
equals(Object object) |
E |
get(int index) |
int |
hashCode() |
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, builder, notNullBuilder, predicatedCollection, validate
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArray
parallelStream, removeIf, stream
protected 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 nullNullPointerException
- 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 nullNullPointerException
- if list or predicate is nullIllegalArgumentException
- if the list contains invalid elementsprotected List<E> decorated()
decorated
in class AbstractCollectionDecorator<E>
public int hashCode()
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–2018 The Apache Software Foundation. All rights reserved.