java.io.Serializable
, java.lang.Iterable
, java.util.Collection
, java.util.List
public class PredicatedList extends PredicatedCollection implements java.util.List
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 | Description |
---|---|---|
protected class |
PredicatedList.PredicatedListIterator |
Inner class Iterator for the PredicatedList
|
collection
predicate
Modifier | Constructor | Description |
---|---|---|
protected |
PredicatedList(java.util.List list,
Predicate predicate) |
Constructor that wraps (not copies).
|
Modifier and Type | Method | Description |
---|---|---|
void |
add(int index,
java.lang.Object object) |
|
boolean |
addAll(int index,
java.util.Collection coll) |
|
static java.util.List |
decorate(java.util.List list,
Predicate predicate) |
Factory method to create a predicated (validating) list.
|
java.lang.Object |
get(int index) |
|
protected java.util.List |
getList() |
Gets the list being decorated.
|
int |
indexOf(java.lang.Object object) |
|
int |
lastIndexOf(java.lang.Object object) |
|
java.util.ListIterator |
listIterator() |
|
java.util.ListIterator |
listIterator(int i) |
|
java.lang.Object |
remove(int index) |
|
java.lang.Object |
set(int index,
java.lang.Object object) |
|
java.util.List |
subList(int fromIndex,
int toIndex) |
clear, contains, containsAll, equals, getCollection, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add, addAll, decorate, validate
protected PredicatedList(java.util.List list, Predicate 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.IllegalArgumentException
- if list or predicate is nulljava.lang.IllegalArgumentException
- if the list contains invalid elementspublic static java.util.List decorate(java.util.List list, Predicate 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.IllegalArgumentException
- if list or predicate is nulljava.lang.IllegalArgumentException
- if the list contains invalid elementsprotected java.util.List getList()
public java.lang.Object get(int index)
get
in interface java.util.List
public int indexOf(java.lang.Object object)
indexOf
in interface java.util.List
public int lastIndexOf(java.lang.Object object)
lastIndexOf
in interface java.util.List
public java.lang.Object remove(int index)
remove
in interface java.util.List
public void add(int index, java.lang.Object object)
add
in interface java.util.List
public boolean addAll(int index, java.util.Collection coll)
addAll
in interface java.util.List
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
public java.util.ListIterator listIterator(int i)
listIterator
in interface java.util.List
public java.lang.Object set(int index, java.lang.Object object)
set
in interface java.util.List
public java.util.List subList(int fromIndex, int toIndex)
subList
in interface java.util.List
Copyright © 2001-2017 Apache Software Foundation. All Rights Reserved.