/** * Returns a sequential ordered {@code LongStreamEx} 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 LongStreamEx of(Long[] array) { return seq(Arrays.stream(array).mapToLong(Long::longValue)); }
/** * Returns a sequential ordered {@code LongStreamEx} 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 LongStreamEx of(Collection<Long> collection) { return seq(collection.stream().mapToLong(Long::longValue)); }
/** * Returns a sequential ordered {@code LongStreamEx} from 0 (inclusive) to * {@code endExclusive} (exclusive) by an incremental step of {@code 1}. * * @param endExclusive the exclusive upper bound * @return a sequential {@code LongStreamEx} for the range of {@code int} * elements * @see #range(long, long) * @since 0.1.1 */ public static LongStreamEx range(long endExclusive) { return seq(LongStream.range(0, endExclusive)); }
/** * Returns an infinite sequential unordered stream where each element is * generated by the provided {@code LongSupplier}. This is suitable for * generating constant streams, streams of random elements, etc. * * @param s the {@code LongSupplier} for generated elements * @return a new infinite sequential unordered {@code LongStreamEx} * @see LongStream#generate(LongSupplier) */ public static LongStreamEx generate(LongSupplier s) { return seq(LongStream.generate(s)); }
/** * Returns a sequential ordered {@code LongStreamEx} from 0 (inclusive) to * {@code Long.MAX_VALUE} (exclusive) by an incremental step of {@code 1}. * * @return a sequential {@code LongStreamEx} for the range of {@code long} * elements * @see #range(long, long) * @since 0.5.5 */ public static LongStreamEx longs() { return seq(LongStream.range(0, Long.MAX_VALUE)); }
/** * Returns a sequential ordered {@code LongStreamEx} 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 LongStreamEx} for the range of {@code long} * elements * @see LongStream#rangeClosed(long, long) */ public static LongStreamEx rangeClosed(long startInclusive, long endInclusive) { return seq(LongStream.rangeClosed(startInclusive, endInclusive)); }
/** * Returns an effectively unlimited stream of pseudorandom {@code long} * 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 long} values * @see Random#longs(long, long, long) */ public static LongStreamEx of(Random random, long randomNumberOrigin, long randomNumberBound) { return seq(random.longs(randomNumberOrigin, randomNumberBound)); }
/** * Returns a sequential ordered {@code LongStreamEx} 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 LongStreamEx} for the range of {@code long} * elements * @see LongStream#range(long, long) */ public static LongStreamEx range(long startInclusive, long endExclusive) { return seq(LongStream.range(startInclusive, endExclusive)); }
/** * Returns an effectively unlimited stream of pseudorandom {@code long} * values produced by given {@link Random} object. * * <p> * A pseudorandom {@code long} value is generated as if it's the result of * calling the method {@link Random#nextLong()}. * * @param random a {@link Random} object to produce the stream from * @return a stream of pseudorandom {@code long} values * @see Random#longs() */ public static LongStreamEx of(Random random) { return seq(random.longs()); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code long} 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 long} values * @see Random#longs(long, long, long) */ public static LongStreamEx of(Random random, long streamSize, long randomNumberOrigin, long randomNumberBound) { return seq(random.longs(streamSize, randomNumberOrigin, randomNumberBound)); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code long} values. * * <p> * A pseudorandom {@code long} value is generated as if it's the result of * calling the method {@link Random#nextLong()} * * @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 long} values * @see Random#longs(long) */ public static LongStreamEx of(Random random, long streamSize) { return seq(random.longs(streamSize)); }
throw new IllegalArgumentException("step = 0"); if (step == 1) return seq(LongStream.rangeClosed(startInclusive, endInclusive)); if (step == -1) { return seq(LongStream.rangeClosed(endInclusive, startInclusive).map(x -> sum - x)); long limit = (endInclusive - startInclusive) * Long.signum(step); limit = Long.divideUnsigned(limit, Math.abs(step)); return seq(LongStream.rangeClosed(0, limit).map(x -> x * step + startInclusive));