Beispiel #1
0
 private static <T> Object[] toArray(Iterable<T> elements) {
   if (elements instanceof java.util.List) {
     final java.util.List<T> list = (java.util.List<T>) elements;
     return list.toArray();
   } else {
     final java.util.Iterator<? extends T> it = elements.iterator();
     final java.util.List<T> list = new java.util.ArrayList<>();
     while (it.hasNext()) {
       list.add(it.next());
     }
     return list.toArray();
   }
 }
Beispiel #2
0
 @Override
 public Array<T> filter(Predicate<? super T> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   final java.util.List<T> list = new ArrayList<>();
   for (T t : this) {
     if (predicate.test(t)) {
       list.add(t);
     }
   }
   if (list.isEmpty()) {
     return empty();
   } else if (list.size() == size()) {
     return this;
   } else {
     return wrap(list.toArray());
   }
 }