@Override public Flow<T> concat(Collection<? extends T> collection) { return concat(F.flow(collection)); }
@Override public Set<T> toSet() { Set<T> set = new HashSet<T>(); each(F.addToCollection(set)); return Collections.unmodifiableSet(set); }
@Override public Flow<T> remove(Predicate<? super T> predicate) { assert predicate != null; return filter(F.not(predicate)); }
@Override public List<T> toList() { if (isEmpty()) return Collections.emptyList(); return Collections.unmodifiableList(toMutableList()); }
@Override public int count() { if (isEmpty()){ return 0; } int count = 0; for(Flow<T> flow = this; flow != null && !flow.isEmpty(); flow = flow.rest()){ count++; } return count; }
/** * Method limited to just AbstractFlow and its subclasses. Forces a resolve of the entire Flow, * and results in a mutable list of the values in the flow. */ protected List<T> toMutableList() { return toMutableList(this); }
@Override public Flow<T> removeNulls() { return remove(F.isNull()); }
@Override public <X> Flow<X> mapcat(Mapper<T, Flow<X>> mapper) { Flow<Flow<X>> flows = map(mapper); if (flows.isEmpty()) return F.emptyFlow(); return flows.rest().reduce(new Reducer<Flow<X>, Flow<X>>() { @Override public Flow<X> reduce(Flow<X> accumulator, Flow<X> value) { return accumulator.concat(value); } }, flows.first()); }
@Override public int count() { if (isEmpty()){ return 0; } int count = 0; for(Flow<T> flow = this; flow != null && !flow.isEmpty(); flow = flow.rest()){ count++; } return count; }
@Override public List<T> toList() { if (isEmpty()) return Collections.emptyList(); return Collections.unmodifiableList(toMutableList()); }
/** * Method limited to just AbstractFlow and its subclasses. Forces a resolve of the entire Flow, * and results in a mutable list of the values in the flow. */ protected List<T> toMutableList() { return toMutableList(this); }
@Override public Flow<T> removeNulls() { return remove(F.isNull()); }
@Override public <X> Flow<X> mapcat(Mapper<T, Flow<X>> mapper) { Flow<Flow<X>> flows = map(mapper); if (flows.isEmpty()) return F.emptyFlow(); return flows.rest().reduce(new Reducer<Flow<X>, Flow<X>>() { @Override public Flow<X> reduce(Flow<X> accumulator, Flow<X> value) { return accumulator.concat(value); } }, flows.first()); }
@Override public Flow<T> sort() { if (isEmpty()) return F.emptyFlow(); return new ArrayFlow<T>(this).sort(); }
@Override @SuppressWarnings("unchecked") public T[] toArray(Class<T> type) { assert type != null; List<T> list = toMutableList(); Object array = Array.newInstance(type, list.size()); return list.toArray((T[]) array); }
@Override public <V extends T> Flow<T> append(V... values) { return concat(F.flow(values)); }
@Override public Flow<T> remove(Predicate<? super T> predicate) { assert predicate != null; return filter(F.not(predicate)); }
@Override public Set<T> toSet() { Set<T> set = new HashSet<T>(); each(F.addToCollection(set)); return Collections.unmodifiableSet(set); }
@Override public Flow<T> reverse() { if (isEmpty()) return F.emptyFlow(); return new ArrayFlow<T>(this).reverse(); }
@Override @SuppressWarnings("unchecked") public T[] toArray(Class<T> type) { assert type != null; List<T> list = toMutableList(); Object array = Array.newInstance(type, list.size()); return list.toArray((T[]) array); }