public class PredicatedList<E> extends PredicatedCollection<E> implements java.util.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>
Modifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID
Serialization version
|
predicate
Modifier | Constructor and Description |
---|---|
protected |
PredicatedList(java.util.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,
java.util.Collection<? extends E> coll) |
protected java.util.List<E> |
decorated()
Gets the list being decorated.
|
boolean |
equals(java.lang.Object object) |
E |
get(int index) |
int |
hashCode() |
int |
indexOf(java.lang.Object object) |
int |
lastIndexOf(java.lang.Object object) |
java.util.ListIterator<E> |
listIterator() |
java.util.ListIterator<E> |
listIterator(int i) |
static <T> PredicatedList<T> |
predicatedList(java.util.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) |
java.util.List<E> |
subList(int fromIndex,
int toIndex) |
add, addAll, builder, notNullBuilder, predicatedCollection, validate
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, setCollection, size, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
private static final long serialVersionUID
protected PredicatedList(java.util.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 nulljava.lang.NullPointerException
- if list or predicate is nulljava.lang.IllegalArgumentException
- if the list contains invalid elementspublic static <T> PredicatedList<T> predicatedList(java.util.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 nulljava.lang.NullPointerException
- if list or predicate is nulljava.lang.IllegalArgumentException
- if the list contains invalid elementsprotected java.util.List<E> decorated()
decorated
in class AbstractCollectionDecorator<E>
public boolean equals(java.lang.Object object)
public int hashCode()
public int indexOf(java.lang.Object object)
indexOf
in interface java.util.List<E>
public int lastIndexOf(java.lang.Object object)
lastIndexOf
in interface java.util.List<E>
public boolean addAll(int index, java.util.Collection<? extends E> coll)
addAll
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator()
listIterator
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator(int i)
listIterator
in interface java.util.List<E>