<commit_before>package kr.jm.utils.helper;

import kr.jm.utils.datastructure.JMCollections;

import java.util.*;
import java.util.Map.Entry;
import java.util.function.IntPredicate;
import java.util.stream.*;

/**
 * The Class JMStream.
 */
public class JMStream {

    /**
     * Number range.
     *
     * @param startInclusive the start inclusive
     * @param endExclusive   the end exclusive
     * @param interval       the interval
     * @return the int stream
     */
    public static IntStream numberRange(int startInclusive, int endExclusive,
            int interval) {
        return numberRange(startInclusive, endExclusive, interval,
                n -> n < endExclusive);
    }

    /**
     * Number range closed.
     *
     * @param startInclusive the start inclusive
     * @param endInclusive   the end inclusive
     * @param interval       the interval
     * @return the int stream
     */
    public static IntStream numberRangeClosed(int startInclusive,
            int endInclusive, int interval) {
        return numberRange(startInclusive, endInclusive, interval,
                n -> n <= endInclusive);
    }

    private static IntStream numberRange(int start, int end, int interval,
            IntPredicate predicate) {
        int maxSize = (end - start) / interval + 1;
        return IntStream.iterate(start, n -> n + interval).limit(maxSize)
                .filter(predicate);
    }

    /**
     * Number range with count.
     *
     * @param start    the start
     * @param interval the interval
     * @param count    the count
     * @return the double stream
     */
    public static DoubleStream numberRangeWithCount(float start, float interval,
            int count) {
        return DoubleStream.iterate(start, n -> n + interval).limit(count);
    }

    /**
     * Number range with count.
     *
     * @param start    the start
     * @param interval the interval
     * @param count    the count
     * @return the long stream
     */
    public static LongStream numberRangeWithCount(int start, int interval,
            int count) {
        return LongStream.iterate(start, n -> n + interval).limit(count);
    }

    /**
     * Builds the int stream.
     *
     * @param <N>              the number type
     * @param numberCollection the number collection
     * @return the int stream
     */
    public static <N extends Number> IntStream
    buildIntStream(Collection<N> numberCollection) {
        return numberCollection.stream().mapToInt(Number::intValue);
    }

    /**
     * Builds the long stream.
     *
     * @param <N>              the number type
     * @param numberCollection the number collection
     * @return the long stream
     */
    public static <N extends Number> LongStream
    buildLongStream(Collection<N> numberCollection) {
        return numberCollection.stream().mapToLong(Number::longValue);
    }

    /**
     * Builds the double stream.
     *
     * @param <N>              the number type
     * @param numberCollection the number collection
     * @return the double stream
     */
    public static <N extends Number> DoubleStream
    buildDoubleStream(Collection<N> numberCollection) {
        return numberCollection.stream().mapToDouble(Number::doubleValue);
    }

    /**
     * Builds the reversed stream.
     *
     * @param <T>        the generic type
     * @param collection the collection
     * @return the stream
     */
    public static <T> Stream<T> buildReversedStream(Collection<T> collection) {
        return JMCollections.getReversed(collection).stream();
    }

    /**
     * Builds the stream.
     *
     * @param <T>   the generic type
     * @param array the array
     * @return the stream
     */
    @SafeVarargs
    public static <T> Stream<T> buildStream(T... array) {
        return Arrays.stream(array);
    }

    /**
     * Builds the stream.<commit_msg>refactoring JMStream<commit_after>package kr.jm.utils.helper;

import kr.jm.utils.datastructure.JMCollections;

import java.util.*;
import java.util.Map.Entry;
import java.util.function.IntPredicate;
import java.util.stream.*;

/**
 * The Class JMStream.
 */
public class JMStream {

    /**
     * Number range.
     *
     * @param startInclusive the start inclusive
     * @param endExclusive   the end exclusive
     * @param interval       the interval
     * @return the int stream
     */
    public static IntStream numberRange(int startInclusive, int endExclusive,
            int interval) {
        return numberRange(startInclusive, endExclusive, interval,
                n -> n < endExclusive);
    }

    /**
     * Number range closed.
     *
     * @param startInclusive the start inclusive
     * @param endInclusive   the end inclusive
     * @param interval       the interval
     * @return the int stream
     */
    public static IntStream numberRangeClosed(int startInclusive,
            int endInclusive, int interval) {
        return numberRange(startInclusive, endInclusive, interval,
                n -> n <= endInclusive);
    }

    public static IntStream numberRange(int start, int end, int interval,
            IntPredicate predicate) {
        return numberRangeWithCount(start, interval,
                (end - start) / interval + 1).filter(predicate);
    }

    /**
     * Number range with count.
     *
     * @param start    the start
     * @param interval the interval
     * @param count    the count
     * @return the long stream
     */
    public static IntStream numberRangeWithCount(int start, int interval,
            int count) {
        return IntStream.iterate(start, n -> n + interval).limit(count);
    }

    public static IntStream increaseRange(int size) {
        return IntStream.range(0, size);
    }


    /**
     * Builds the int stream.
     *
     * @param <N>              the number type
     * @param numberCollection the number collection
     * @return the int stream
     */
    public static <N extends Number> IntStream
    buildIntStream(Collection<N> numberCollection) {
        return numberCollection.stream().mapToInt(Number::intValue);
    }

    /**
     * Builds the long stream.
     *
     * @param <N>              the number type
     * @param numberCollection the number collection
     * @return the long stream
     */
    public static <N extends Number> LongStream
    buildLongStream(Collection<N> numberCollection) {
        return numberCollection.stream().mapToLong(Number::longValue);
    }

    /**
     * Builds the double stream.
     *
     * @param <N>              the number type
     * @param numberCollection the number collection
     * @return the double stream
     */
    public static <N extends Number> DoubleStream
    buildDoubleStream(Collection<N> numberCollection) {
        return numberCollection.stream().mapToDouble(Number::doubleValue);
    }

    /**
     * Builds the reversed stream.
     *
     * @param <T>        the generic type
     * @param collection the collection
     * @return the stream
     */
    public static <T> Stream<T> buildReversedStream(Collection<T> collection) {
        return JMCollections.getReversed(collection).stream();
    }

    /**
     * Builds the stream.
     *
     * @param <T>   the generic type
     * @param array the array
     * @return the stream
     */
    @SafeVarargs
    public static <T> Stream<T> buildStream(T... array) {
        return JMOptional.getOptional(array).map(Arrays::stream)
                .orElseGet(Stream::empty);
    }

    /**
     * Builds the stream.
{'fraction_non_alphanumeric': 0.09328209884722406, 'fraction_numerical': 0.00039750894395123893, 'mean_word_length': 2.224263135412217, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2227422', 'n_tokens_mistral': 2065, 'n_tokens_neox': 2012, 'n_words': 604}