/** * Returns a predicated (validating) list backed by the given list. * <p> * Only objects that pass the test in the given predicate can be added to the list. * Trying to add an invalid object results in an IllegalArgumentException. * It is important not to use the original list after invoking this method, * as it is a backdoor for adding invalid objects. * * @param list the list to predicate, must not be null * @param predicate the predicate for the list, must not be null * @return a predicated list backed by the given list * @throws IllegalArgumentException if the List or Predicate is null */ public static List predicatedList(List list, Predicate predicate) { return PredicatedList.decorate(list, predicate); }
public List subList(int fromIndex, int toIndex) { List sub = getList().subList(fromIndex, toIndex); return new PredicatedList(sub, predicate); }
/** * Gets the list being decorated. * * @return the decorated list */ protected List getList() { return (List) getCollection(); }
public int lastIndexOf(Object object) { return getList().lastIndexOf(object); }
/** * Factory method to create a predicated (validating) list. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param list the list to decorate, must not be null * @param predicate the predicate to use for validation, must not be null * @throws IllegalArgumentException if list or predicate is null * @throws IllegalArgumentException if the list contains invalid elements */ public static List decorate(List list, Predicate predicate) { return new PredicatedList(list, predicate); }
public ListIterator listIterator() { return listIterator(0); }
public Object remove(int index) { return getList().remove(index); }
/** * Factory method to create a predicated (validating) list. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param list the list to decorate, must not be null * @param predicate the predicate to use for validation, must not be null * @throws IllegalArgumentException if list or predicate is null * @throws IllegalArgumentException if the list contains invalid elements */ public static List decorate(List list, Predicate predicate) { return new PredicatedList(list, predicate); }
public ListIterator listIterator() { return listIterator(0); }
public Object get(int index) { return getList().get(index); }
public List subList(int fromIndex, int toIndex) { List sub = getList().subList(fromIndex, toIndex); return new PredicatedList(sub, predicate); }
/** * Returns a predicated (validating) list backed by the given list. * <p> * Only objects that pass the test in the given predicate can be added to the list. * Trying to add an invalid object results in an IllegalArgumentException. * It is important not to use the original list after invoking this method, * as it is a backdoor for adding invalid objects. * * @param list the list to predicate, must not be null * @param predicate the predicate for the list, must not be null * @return a predicated list backed by the given list * @throws IllegalArgumentException if the List or Predicate is null */ public static List predicatedList(List list, Predicate predicate) { return PredicatedList.decorate(list, predicate); }
/** * Factory method to create a typed list. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param list the list to decorate, must not be null * @param type the type to allow into the collection, must not be null * @throws IllegalArgumentException if list or type is null * @throws IllegalArgumentException if the list contains invalid elements */ public static List decorate(List list, Class type) { return new PredicatedList(list, InstanceofPredicate.getInstance(type)); }
/** * Gets the list being decorated. * * @return the decorated list */ protected List getList() { return (List) getCollection(); }
public ListIterator listIterator() { return listIterator(0); }
public int indexOf(Object object) { return getList().indexOf(object); }