Executes map on the provided stream. If the Stream is parallel, it is
executed using the custom pool, else it is executed directly from the
main thread.

@param <T>
@param <R>
@param stream
@param mapper
@return
170856
public <T, R> Stream<R> map(Stream<T> stream, Function<? super T, ? extends R> mapper) {
        Callable<Stream<R>> callable = () -> stream.map(mapper);
        return ThreadMethods.forkJoinExecution(callable, concurrencyConfiguration, stream.isParallel());
    }
1122387
@SafeVarargs
    @SuppressWarnings("unchecked")
    public static <T> Stream<T> stream(Iterable<T>... iterables) {
        List<Iterator<T>> iterators = Arrays.stream(iterables)
            .map(Iterable::iterator)
            .collect(Collectors.toList());

        return stream(iterators.toArray(new Iterator[iterables.length]));
    }
1061550
public static Map<HeaderName<?>, Object> copyFromStream(@Nullable final Stream<Map.Entry<HeaderName<?>, Object>> stream) {
        Map<HeaderName<?>, Object> headerMap;

        if (stream == null) {
            headerMap = new HashMap<>();
        } else {
            headerMap = stream.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        }

        return headerMap;
    }
893362
public static <T> Stream<T> toStream(@javax.annotation.Nonnull final Iterator<T> iterator, final int size, final boolean parallel) {
    return StreamSupport.stream(Spliterators.spliterator(iterator, size, Spliterator.ORDERED), parallel);
  }
315366
@Override
    public <U> U chain(Function<? super IntStreamEx, U> mapper) {
        return mapper.apply(this);
    }
15514
public static Map makeMap(Mapper mapper, Object[] a) {
        return makeMap(mapper, java.util.Arrays.asList(a), false);
    }
320300
public final static <T, R> R foldMap(final Stream<T> stream, final Function<? super T, ? extends R> mapper, final Monoid<R> reducer) {
        return reducer.foldLeft(stream.map(mapper));
    }
616678
public static <T> Stream<T> parallelConcatt(final Collection<? extends Iterator<? extends T>> c) {
        return parallelConcatt(c, DEFAULT_READING_THREAD_NUM);
    }
96048
public static Collection map(Mapper mapper, Iterator i) {
        return map(mapper, i, false);
    }
827026
public static <T, R> Iterator<R> map(final Iterator<T> iterator, final IFunction<T, R> mapper) {
        return new Iterator<R>() {
            @Override
            public boolean hasNext() {
                return iterator.hasNext();
            }

            @Override
            public R next() {
                return mapper.apply(iterator.next());
            }

            @Override
            public void remove() {
                iterator.remove();
            }
        };
    }
27392
public static <K extends Comparable<K>, V> Stream<Entry<K, V>>
    sortedStream(Map<K, V> map) {
        synchronized (map) {
            return buildEntryStream(map).sorted(comparing(Entry::getKey));
        }
    }
399740
public <T> void addMapper(Class<T> clazz, StringMapper<T> mapper) {
		addParser(clazz, mapper);
		mappers.put(clazz, mapper);
	}
1183848
public static <R> Stream<R> of(Iterator<R> iterator) {
        return new Stream<R>(iterator);
    }
878034
public static void addTypeMapper(Class<?> clz, Class<?> mapper) {
		synchronized (classMapper) {
			LinkedHashSet<Class<?>> h = classMapper.get(clz);
			if (h == null) {
				h = new LinkedHashSet<Class<?>>();
				classMapper.put(clz, h);
			}
			
			h.add(mapper);
		}
	}
410798
@SuppressWarnings("rawtypes")
    public static <T, R> Collector<T, ?, R> streaming(final Supplier<? extends BlockingQueue<T>> queueSupplier,
            final Function<? super Stream<T>, ContinuableFuture<R>> streamingCollector, final long maxWaitIntervalInMillis) {
        final T NULL = (T) NONE;

        final Supplier<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>> supplier = new Supplier<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>>() {
            @Override
            public Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>> get() {
                return Tuple.of((BlockingQueue<T>) queueSupplier.get(), MutableBoolean.of(true), MutableBoolean.of(false), new Holder<ContinuableFuture<R>>()); // _1 = queue, _2 = hasMore, _3 = isComplete, _4=future.
            }
        };

        final BiConsumer<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>, T> accumulator = new BiConsumer<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>, T>() {
            @Override
            public void accept(Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>> xxx, T t) {
                if (xxx._4.value() == null) {
                    initStream(xxx, streamingCollector, maxWaitIntervalInMillis, NULL);
                }

                t = t == null ? NULL : t;

                if (xxx._3.isFalse() && xxx._1.offer(t) == false) {
                    try {
                        while (xxx._3.isFalse() && xxx._1.offer(t, maxWaitIntervalInMillis, TimeUnit.MILLISECONDS) == false) {
                        }
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        final BinaryOperator<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>> combiner = new BinaryOperator<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>>() {
            @Override
            public Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>> apply(
                    Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>> t,
                    Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>> u) {
                throw new UnsupportedOperationException("Should not happen");
            }
        };

        final Function<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>, R> finisher = new Function<Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>>, R>() {
            @Override
            public R apply(Tuple4<BlockingQueue<T>, MutableBoolean, MutableBoolean, Holder<ContinuableFuture<R>>> xxx) {
                if (xxx._4.value() == null) {
                    initStream(xxx, streamingCollector, maxWaitIntervalInMillis, NULL);
                }

                xxx._2.setFalse();

                try {
                    return xxx._4.value().get();
                } catch (InterruptedException | ExecutionException e) {
                    throw new RuntimeException(e);
                }
            }
        };

        return new CollectorImpl(supplier, accumulator, combiner, finisher, CH_CONCURRENT_NOID);
    }
314450
@Override
    public <U> U chain(Function<? super LongStreamEx, U> mapper) {
        return mapper.apply(this);
    }
1191610
public static Map makeMap(Mapper mapper, Iterator i) {
        return makeMap(mapper, i, false);
    }