public static <T> void filter(Collection<T> target, IPredicate<T> predicate) {
   Iterator<T> iter = target.iterator();
   while (iter.hasNext()) {
     T element = iter.next();
     if (!predicate.apply(element)) {
       iter.remove();
     }
   }
 }
Esempio n. 2
0
  public static <TSource> TSource FirstOrDefault(
      Iterable<TSource> source, IPredicate<TSource> predicate) {
    for (TSource item : source) {
      if (predicate.Match(item)) {
        return item;
      }
    }

    return null;
  }
Esempio n. 3
0
  public static <TSource> Iterable<TSource> Where(
      Iterable<TSource> source, IPredicate<TSource> predicate) {
    ArrayList<TSource> list = new ArrayList<TSource>();

    for (TSource item : source) {
      if (predicate.Match(item)) {
        list.add(item);
      }
    }

    return list;
  }