List of usage examples for org.apache.commons.functor UnaryPredicate test
boolean test(A obj);
From source file:declarative.Sample1.java
public static void main(String[] args) { UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() { public boolean test(Integer number) { return number % 2 == 0; }/*from w w w. j a v a 2 s . c o m*/ }; IntegerRange zeroToTen = new IntegerRange(0, 11); for (Integer number : zeroToTen.toCollection()) { if (isEven.test(number)) { System.out.println(number + " is even"); } } }
From source file:com.aw.support.collection.ListUtils.java
public static void apply(Collection list, UnaryPredicate predicate, UnaryFunction function) { for (Object o : list) { if (predicate == null || predicate.test(o)) { function.evaluate(o);//from w ww . j a v a 2 s . c o m } } }
From source file:com.aw.support.collection.ListUtils.java
/** * Return the index of the element in the list that satisfied the predicate * * @param list/*from ww w .ja v a 2 s .c o m*/ * @param predicate * @return -1 if no exist any element that satisfied the predicate */ public static int indexOf(List list, UnaryPredicate predicate) { for (int i = 0; i < list.size(); i++) { Object obj = list.get(i); if (predicate.test(obj)) { return i; } } return -1; }
From source file:com.aw.support.collection.ListUtils.java
/** * Returns a list with the elements that meet the criteria * * @param list/*from w w w .j a v a2 s .c o m*/ * @return */ public static <E> List<E> getSubList(Collection<E> list, UnaryPredicate predicate) { List subList = new ArrayList(); for (Iterator<E> iterator = list.iterator(); iterator.hasNext();) { Object o = iterator.next(); if (predicate.test(o)) { subList.add(o); } } return subList; }