コード例 #1
0
 /**
  * Removes up to N elements from the given iterable
  *
  * @param <I>
  * @param iterable
  * @param amountOfElements Non negative
  * @return the given iterable
  */
 @NonNull
 public static <I extends Iterable<?>> I remove(
     @NonNull I iterable, @NotNegative int amountOfElements) {
   Iterator<?> iter = iterable.iterator();
   for (int i = 0; i < amountOfElements && iter.hasNext(); i++) iter.remove();
   return iterable;
 }
コード例 #2
0
 /**
  * Removes from the given iterable all the elements that evaluate to true
  *
  * @param iterable
  * @param predicate
  * @param <T>
  * @param <I>
  * @return the given iterable
  */
 @NonNull
 public static <T, I extends Iterable<T>> I removeAll(
     @NonNull I iterable, @NonNull Evaluable<? super T> predicate) {
   for (Iterator<T> iter = iterable.iterator(); iter.hasNext(); )
     if (predicate.eval(iter.next())) iter.remove();
   return iterable;
 }