/** * Returns a sequential ordered {@code IntStreamEx} from 0 (inclusive) to * {@code Integer.MAX_VALUE} (exclusive) by an incremental step of {@code 1} * . * * @return a sequential {@code IntStreamEx} for the range of {@code int} * elements * @see #range(int, int) * @since 0.5.5 */ public static IntStreamEx ints() { return seq(IntStream.range(0, Integer.MAX_VALUE)); }
/** * Returns a sequential ordered {@code IntStreamEx} from * {@code startInclusive} (inclusive) to {@code endExclusive} (exclusive) by * an incremental step of {@code 1}. * * @param startInclusive the (inclusive) initial value * @param endExclusive the exclusive upper bound * @return a sequential {@code IntStreamEx} for the range of {@code int} * elements * @see IntStream#range(int, int) */ public static IntStreamEx range(int startInclusive, int endExclusive) { return seq(IntStream.range(startInclusive, endExclusive)); }
/** * Returns a sequential ordered {@code IntStreamEx} from 0 (inclusive) to * {@code endExclusive} (exclusive) by an incremental step of {@code 1}. * * @param endExclusive the exclusive upper bound * @return a sequential {@code IntStreamEx} for the range of {@code int} * elements * @see #range(int, int) * @since 0.1.1 */ public static IntStreamEx range(int endExclusive) { return seq(IntStream.range(0, endExclusive)); }
/** * Returns a sequential ordered {@code IntStreamEx} from * {@code startInclusive} (inclusive) to {@code endInclusive} (inclusive) by * an incremental step of {@code 1}. * * @param startInclusive the (inclusive) initial value * @param endInclusive the inclusive upper bound * @return a sequential {@code IntStreamEx} for the range of {@code int} * elements * @see IntStream#rangeClosed(int, int) */ public static IntStreamEx rangeClosed(int startInclusive, int endInclusive) { return seq(IntStream.rangeClosed(startInclusive, endInclusive)); }
/** * Returns a sequential ordered {@code IntStreamEx} whose elements are the * unboxed elements of supplied array. * * @param array the array to create the stream from. * @return the new stream * @see Arrays#stream(Object[]) * @since 0.5.0 */ public static IntStreamEx of(Integer[] array) { return seq(Arrays.stream(array).mapToInt(Integer::intValue)); }
/** * Returns a sequential ordered {@code IntStreamEx} whose elements are the * unboxed elements of supplied collection. * * @param collection the collection to create the stream from. * @return the new stream * @see Collection#stream() */ public static IntStreamEx of(Collection<Integer> collection) { return seq(collection.stream().mapToInt(Integer::intValue)); }
/** * Returns a sequential ordered {@code IntStreamEx} containing all the * indices of the supplied array elements which match given predicate. * * @param <T> array element type * @param array array to get the stream of its indices * @param predicate a predicate to test array elements * @return a sequential {@code IntStreamEx} of the matched array indices * @since 0.1.1 */ public static <T> IntStreamEx ofIndices(T[] array, Predicate<T> predicate) { return seq(IntStream.range(0, array.length).filter(i -> predicate.test(array[i]))); }
/** * Returns a sequential ordered {@code IntStreamEx} containing all the * indices of the supplied array elements which match given predicate. * * @param array array to get the stream of its indices * @param predicate a predicate to test array elements * @return a sequential {@code IntStreamEx} of the matched array indices * @since 0.1.1 */ public static IntStreamEx ofIndices(int[] array, IntPredicate predicate) { return seq(IntStream.range(0, array.length).filter(i -> predicate.test(array[i]))); }
/** * Returns an infinite sequential unordered stream where each element is * generated by the provided {@code IntSupplier}. This is suitable for * generating constant streams, streams of random elements, etc. * * @param s the {@code IntSupplier} for generated elements * @return a new infinite sequential unordered {@code IntStreamEx} * @see IntStream#generate(IntSupplier) */ public static IntStreamEx generate(IntSupplier s) { return seq(IntStream.generate(s)); }
/** * Returns a sequential ordered {@code IntStreamEx} containing all the * indices of the supplied array elements which match given predicate. * * @param array array to get the stream of its indices * @param predicate a predicate to test array elements * @return a sequential {@code IntStreamEx} of the matched array indices * @since 0.1.1 */ public static IntStreamEx ofIndices(double[] array, DoublePredicate predicate) { return seq(IntStream.range(0, array.length).filter(i -> predicate.test(array[i]))); }
/** * Returns a sequential ordered {@code IntStreamEx} containing all the * indices of the supplied array elements which match given predicate. * * @param array array to get the stream of its indices * @param predicate a predicate to test array elements * @return a sequential {@code IntStreamEx} of the matched array indices * @since 0.1.1 */ public static IntStreamEx ofIndices(long[] array, LongPredicate predicate) { return seq(IntStream.range(0, array.length).filter(i -> predicate.test(array[i]))); }
/** * Returns a sequential ordered {@code IntStreamEx} containing all the * indices of the supplied list elements which match given predicate. * * <p> * The list elements are accessed using {@link List#get(int)}, so the list * should provide fast random access. The list is assumed to be unmodifiable * during the stream operations. * * @param <T> list element type * @param list list to get the stream of its indices * @param predicate a predicate to test list elements * @return a sequential {@code IntStreamEx} of the matched list indices * @since 0.1.1 */ public static <T> IntStreamEx ofIndices(List<T> list, Predicate<T> predicate) { return seq(IntStream.range(0, list.size()).filter(i -> predicate.test(list.get(i)))); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code int} values, each conforming to the given origin * (inclusive) and bound (exclusive). * * @param random a {@link Random} object to produce the stream from * @param streamSize the number of values to generate * @param randomNumberOrigin the origin (inclusive) of each random value * @param randomNumberBound the bound (exclusive) of each random value * @return a stream of pseudorandom {@code int} values * @see Random#ints(long, int, int) */ public static IntStreamEx of(Random random, long streamSize, int randomNumberOrigin, int randomNumberBound) { return seq(random.ints(streamSize, randomNumberOrigin, randomNumberBound)); }
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values, each conforming to the given origin (inclusive) and bound * (exclusive). * * @param random a {@link Random} object to produce the stream from * @param randomNumberOrigin the origin (inclusive) of each random value * @param randomNumberBound the bound (exclusive) of each random value * @return a stream of pseudorandom {@code int} values * @see Random#ints(long, int, int) */ public static IntStreamEx of(Random random, int randomNumberOrigin, int randomNumberBound) { return seq(random.ints(randomNumberOrigin, randomNumberBound)); }
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values produced by given {@link Random} object. * * <p> * A pseudorandom {@code int} value is generated as if it's the result of * calling the method {@link Random#nextInt()}. * * @param random a {@link Random} object to produce the stream from * @return a stream of pseudorandom {@code int} values * @see Random#ints() */ public static IntStreamEx of(Random random) { return seq(random.ints()); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code int} values. * * <p> * A pseudorandom {@code int} value is generated as if it's the result of * calling the method {@link Random#nextInt()}. * * @param random a {@link Random} object to produce the stream from * @param streamSize the number of values to generate * @return a stream of pseudorandom {@code int} values * @see Random#ints(long) */ public static IntStreamEx of(Random random, long streamSize) { return seq(random.ints(streamSize)); }
/** * Returns an {@code IntStreamEx} of indices for which the specified * {@link BitSet} contains a bit in the set state. The indices are returned * in order, from lowest to highest. The size of the stream is the number of * bits in the set state, equal to the value returned by the * {@link BitSet#cardinality()} method. * * <p> * The bit set must remain constant during the execution of the terminal * stream operation. Otherwise, the result of the terminal stream operation * is undefined. * * @param bitSet a {@link BitSet} to produce the stream from * @return a stream of integers representing set indices * @see BitSet#stream() */ public static IntStreamEx of(BitSet bitSet) { return seq(bitSet.stream()); }
throw new IllegalArgumentException("step = 0"); if (step == 1) return seq(IntStream.rangeClosed(startInclusive, endInclusive)); if (step == -1) { return seq(IntStream.rangeClosed(endInclusive, startInclusive).map(x -> sum - x)); int limit = (endInclusive - startInclusive) * Integer.signum(step); limit = Integer.divideUnsigned(limit, Math.abs(step)); return seq(IntStream.rangeClosed(0, limit).map(x -> x * step + startInclusive));