Java Code Examples for java.util.stream.StreamSupport#intStream()
The following examples show how to use
java.util.stream.StreamSupport#intStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CharSequence.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Returns a stream of {@code int} zero-extending the {@code char} values * from this sequence. Any char which maps to a <a * href="{@docRoot}/java/lang/Character.html#unicode">surrogate code * point</a> is passed through uninterpreted. * * <p>If the sequence is mutated while the stream is being read, the * result is undefined. * * @return an IntStream of char values from this sequence * @since 1.8 */ public default IntStream chars() { class CharIterator implements PrimitiveIterator.OfInt { int cur = 0; public boolean hasNext() { return cur < length(); } public int nextInt() { if (hasNext()) { return charAt(cur++); } else { throw new NoSuchElementException(); } } @Override public void forEachRemaining(IntConsumer block) { for (; cur < length(); cur++) { block.accept(charAt(cur)); } } } return StreamSupport.intStream(() -> Spliterators.spliterator( new CharIterator(), length(), Spliterator.ORDERED), Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED, false); }
Example 2
Source File: CharSequence.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a stream of {@code int} zero-extending the {@code char} values * from this sequence. Any char which maps to a <a * href="{@docRoot}/java/lang/Character.html#unicode">surrogate code * point</a> is passed through uninterpreted. * * <p>If the sequence is mutated while the stream is being read, the * result is undefined. * * @return an IntStream of char values from this sequence * @since 1.8 */ public default IntStream chars() { class CharIterator implements PrimitiveIterator.OfInt { int cur = 0; public boolean hasNext() { return cur < length(); } public int nextInt() { if (hasNext()) { return charAt(cur++); } else { throw new NoSuchElementException(); } } @Override public void forEachRemaining(IntConsumer block) { for (; cur < length(); cur++) { block.accept(charAt(cur)); } } } return StreamSupport.intStream(() -> Spliterators.spliterator( new CharIterator(), length(), Spliterator.ORDERED), Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED, false); }
Example 3
Source File: BitSet.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns a stream of indices for which this {@code 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 #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. * * @return a stream of integers representing set indices * @since 1.8 */ public IntStream stream() { class BitSetIterator implements PrimitiveIterator.OfInt { int next = nextSetBit(0); @Override public boolean hasNext() { return next != -1; } @Override public int nextInt() { if (next != -1) { int ret = next; next = nextSetBit(next+1); return ret; } else { throw new NoSuchElementException(); } } } return StreamSupport.intStream( () -> Spliterators.spliterator( new BitSetIterator(), cardinality(), Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED), Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED, false); }
Example 4
Source File: BitSet.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Returns a stream of indices for which this {@code 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 #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. * * @return a stream of integers representing set indices * @since 1.8 */ public IntStream stream() { class BitSetIterator implements PrimitiveIterator.OfInt { int next = nextSetBit(0); @Override public boolean hasNext() { return next != -1; } @Override public int nextInt() { if (next != -1) { int ret = next; next = nextSetBit(next+1); return ret; } else { throw new NoSuchElementException(); } } } return StreamSupport.intStream( () -> Spliterators.spliterator( new BitSetIterator(), cardinality(), Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED), Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED, false); }
Example 5
Source File: StoreGraph.java From constellation with Apache License 2.0 | 4 votes |
@Override public IntStream linkStream() { return StreamSupport.intStream(new LinkSpliterator(this), false); }
Example 6
Source File: StoreGraph.java From constellation with Apache License 2.0 | 4 votes |
@Override public IntStream edgeStream() { return StreamSupport.intStream(new EdgeSpliterator(this), false); }
Example 7
Source File: Random.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Returns a stream producing the given {@code streamSize} number * of pseudorandom {@code int} values, each conforming to the given * origin (inclusive) and bound (exclusive). * * <p>A pseudorandom {@code int} value is generated as if it's the result of * calling the following method with the origin and bound: * <pre> {@code * int nextInt(int origin, int bound) { * int n = bound - origin; * if (n > 0) { * return nextInt(n) + origin; * } * else { // range not representable as int * int r; * do { * r = nextInt(); * } while (r < origin || r >= bound); * return r; * } * }}</pre> * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code streamSize} is * less than zero, or {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} * @since 1.8 */ public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { if (streamSize < 0L) throw new IllegalArgumentException(BadSize); if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, streamSize, randomNumberOrigin, randomNumberBound), false); }
Example 8
Source File: Random.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code * int} values, each conforming to the given origin (inclusive) and bound * (exclusive). * * <p>A pseudorandom {@code int} value is generated as if it's the result of * calling the following method with the origin and bound: * <pre> {@code * int nextInt(int origin, int bound) { * int n = bound - origin; * if (n > 0) { * return nextInt(n) + origin; * } * else { // range not representable as int * int r; * do { * r = nextInt(); * } while (r < origin || r >= bound); * return r; * } * }}</pre> * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} * @since 1.8 */ public IntStream ints(int randomNumberOrigin, int randomNumberBound) { if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), false); }
Example 9
Source File: Random.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * 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 #nextInt()}. * * @param streamSize the number of values to generate * @return a stream of pseudorandom {@code int} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero * @since 1.8 */ public IntStream ints(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BadSize); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, streamSize, Integer.MAX_VALUE, 0), false); }
Example 10
Source File: Random.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Returns a stream producing the given {@code streamSize} number * of pseudorandom {@code int} values, each conforming to the given * origin (inclusive) and bound (exclusive). * * <p>A pseudorandom {@code int} value is generated as if it's the result of * calling the following method with the origin and bound: * <pre> {@code * int nextInt(int origin, int bound) { * int n = bound - origin; * if (n > 0) { * return nextInt(n) + origin; * } * else { // range not representable as int * int r; * do { * r = nextInt(); * } while (r < origin || r >= bound); * return r; * } * }}</pre> * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code streamSize} is * less than zero, or {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} * @since 1.8 */ public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { if (streamSize < 0L) throw new IllegalArgumentException(BadSize); if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, streamSize, randomNumberOrigin, randomNumberBound), false); }
Example 11
Source File: Random.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code * int} values, each conforming to the given origin (inclusive) and bound * (exclusive). * * <p>A pseudorandom {@code int} value is generated as if it's the result of * calling the following method with the origin and bound: * <pre> {@code * int nextInt(int origin, int bound) { * int n = bound - origin; * if (n > 0) { * return nextInt(n) + origin; * } * else { // range not representable as int * int r; * do { * r = nextInt(); * } while (r < origin || r >= bound); * return r; * } * }}</pre> * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} * @since 1.8 */ public IntStream ints(int randomNumberOrigin, int randomNumberBound) { if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), false); }
Example 12
Source File: ThreadLocalRandom.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code int} values. * * @param streamSize the number of values to generate * @return a stream of pseudorandom {@code int} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero * @since 1.8 */ public IntStream ints(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BadSize); return StreamSupport.intStream (new RandomIntsSpliterator (0L, streamSize, Integer.MAX_VALUE, 0), false); }
Example 13
Source File: ThreadLocalRandom.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values. * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code int} values * @since 1.8 */ public IntStream ints() { return StreamSupport.intStream (new RandomIntsSpliterator (0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0), false); }
Example 14
Source File: SplittableRandom.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code * int} values from this generator and/or one split from it; each value * conforms to the given origin (inclusive) and bound (exclusive). * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} */ public IntStream ints(int randomNumberOrigin, int randomNumberBound) { if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), false); }
Example 15
Source File: ThreadLocalRandom.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code * int} values, each conforming to the given origin (inclusive) and bound * (exclusive). * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} * @since 1.8 */ public IntStream ints(int randomNumberOrigin, int randomNumberBound) { if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), false); }
Example 16
Source File: SplittableRandom.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values from this generator and/or one split from it. * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code int} values */ public IntStream ints() { return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0), false); }
Example 17
Source File: ThreadLocalRandom.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values. * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code int} values * @since 1.8 */ public IntStream ints() { return StreamSupport.intStream (new RandomIntsSpliterator (0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0), false); }
Example 18
Source File: SplittableRandom.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Returns an effectively unlimited stream of pseudorandom {@code * int} values from this generator and/or one split from it; each value * conforms to the given origin (inclusive) and bound (exclusive). * * @implNote This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} */ public IntStream ints(int randomNumberOrigin, int randomNumberBound) { if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), false); }
Example 19
Source File: Random.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Returns a stream producing the given {@code streamSize} number * of pseudorandom {@code int} values, each conforming to the given * origin (inclusive) and bound (exclusive). * * <p>A pseudorandom {@code int} value is generated as if it's the result of * calling the following method with the origin and bound: * <pre> {@code * int nextInt(int origin, int bound) { * int n = bound - origin; * if (n > 0) { * return nextInt(n) + origin; * } * else { // range not representable as int * int r; * do { * r = nextInt(); * } while (r < origin || r >= bound); * return r; * } * }}</pre> * * @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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code streamSize} is * less than zero, or {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} * @since 1.8 */ public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { if (streamSize < 0L) throw new IllegalArgumentException(BadSize); if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, streamSize, randomNumberOrigin, randomNumberBound), false); }
Example 20
Source File: ThreadLocalRandom.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * 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 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, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code streamSize} is * less than zero, or {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} * @since 1.8 */ public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) { if (streamSize < 0L) throw new IllegalArgumentException(BadSize); if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BadRange); return StreamSupport.intStream (new RandomIntsSpliterator (0L, streamSize, randomNumberOrigin, randomNumberBound), false); }