/** * If a value is present, returns a sequential {@link IntStream} containing * only that value, otherwise returns an empty {@code IntStream}. * * <p><b>API Note:</b><br> * This method can be used to transform a {@code Stream} of optional * integers to an {@code IntStream} of present integers: * * <pre>{@code * Stream<OptionalInt> os = .. * IntStream s = os.flatMapToInt(OptionalInt::stream) * }</pre> * * @return the optional value as an {@code IntStream} * @since 9 */ public IntStream stream() { if (isPresent) { return IntStreams.of(value); } else { return IntStreams.empty(); } }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.applyAsInt(i)); * }</pre> * * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static void parallelSetAll(int[] array, IntUnaryOperator generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.applyAsInt(i); }); }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i < endExclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endExclusive the exclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream range(int startInclusive, int endExclusive) { if (startInclusive >= endExclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false); } }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.applyAsDouble(i)); * }</pre> * * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static void parallelSetAll(double[] array, IntToDoubleFunction generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.applyAsDouble(i); }); }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i < endExclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endExclusive the exclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream range(int startInclusive, int endExclusive) { if (startInclusive >= endExclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false); } }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.applyAsLong(i)); * }</pre> * * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static void parallelSetAll(long[] array, IntToLongFunction generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.applyAsLong(i); }); }
/** * If a value is present, returns a sequential {@link IntStream} containing * only that value, otherwise returns an empty {@code IntStream}. * * <p><b>API Note:</b><br> * This method can be used to transform a {@code Stream} of optional * integers to an {@code IntStream} of present integers: * * <pre>{@code * Stream<OptionalInt> os = .. * IntStream s = os.flatMapToInt(OptionalInt::stream) * }</pre> * * @return the optional value as an {@code IntStream} * @since 9 */ public IntStream stream() { if (isPresent) { return IntStreams.of(value); } else { return IntStreams.empty(); } }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endInclusive} (inclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i <= endInclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endInclusive the inclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream rangeClosed(int startInclusive, int endInclusive) { if (startInclusive > endInclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false); } }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.applyAsDouble(i)); * }</pre> * * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static void parallelSetAll(double[] array, IntToDoubleFunction generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.applyAsDouble(i); }); }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endInclusive} (inclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i <= endInclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endInclusive the inclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream rangeClosed(int startInclusive, int endInclusive) { if (startInclusive > endInclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false); } }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.applyAsInt(i)); * }</pre> * * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static void parallelSetAll(int[] array, IntUnaryOperator generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.applyAsInt(i); }); }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.applyAsLong(i)); * }</pre> * * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static void parallelSetAll(long[] array, IntToLongFunction generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.applyAsLong(i); }); }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.apply(i)); * }</pre> * * @param <T> type of elements of the array * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static <T> void parallelSetAll(T[] array, IntFunction<? extends T> generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.apply(i); }); }
/** * Set all elements of the specified array, in parallel, using the * provided generator function to compute each element. * * <p>If the generator function throws an exception, an unchecked exception * is thrown from {@code parallelSetAll} and the array is left in an * indeterminate state. * * <p><b>API Note:</b><br> * Setting a subrange of an array, in parallel, using a generator function * to compute each element, can be written as follows: * <pre>{@code * IntStreams.range(startInclusive, endExclusive) * .parallel() * .forEach(i -> array[i] = generator.apply(i)); * }</pre> * * @param <T> type of elements of the array * @param array array to be initialized * @param generator a function accepting an index and producing the desired * value for that position * @throws NullPointerException if the generator is null * @since 1.8 */ public static <T> void parallelSetAll(T[] array, IntFunction<? extends T> generator) { Objects.requireNonNull(generator); IntStreams.range(0, array.length).parallel().forEach(i -> { array[i] = generator.apply(i); }); }
public Hashes getGuiHashes() { Sequence<SingleImage> sequence = getGuis(); return new Hashes(IntStreams.range(0, sequence.length()) .mapToObj(index -> sequence.getImage(index, null)) .map(SingleImage::hash) .collect(Collectors.toList())); }
public Hashes getSettlersHashes() { SequenceList<Image> settlers = getSettlers(); return new Hashes(IntStreams.range(0, settlers.size()) .mapToObj(settlers::get) .map(sequence -> sequence.getImage(0, null)) .filter(image -> image instanceof SingleImage) .map(image -> (SingleImage) image) .map(SingleImage::hash) .collect(Collectors.toList())); }