/** * 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); }); }
a.spliterator(), b.spliterator()); IntStream stream = StreamSupport.intStream(split, a.isParallel() || b.isParallel()); return stream.onClose(Streams.composedClose(a, b));
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 int getCountOfMovablesOfPlayer(IPlayer player, Set<EMovableType> types) { byte playerId = player.getPlayerId(); return stream(types).mapToInt(type -> getPositionsOfMovablesWithTypeForPlayer(playerId, type).size()).sum(); }
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())); }
@Override protected boolean loadUp(ITradeBuilding tradeBuilding) { for (int stackIndex = 0; stackIndex < CARGO_STACKS; stackIndex++) { if (getCargoCount(stackIndex) > 0) { continue; } final int finalStackIndex = stackIndex; tradeBuilding.tryToTakeMaterial(Constants.STACK_SIZE).ifPresent(materialTypeWithCount -> { setCargoType(materialTypeWithCount.materialType, finalStackIndex); setCargoCount(materialTypeWithCount.count, finalStackIndex); }); } return J8Arrays.stream(cargoCount).sum() > 0; }
a.spliterator(), b.spliterator()); IntStream stream = StreamSupport.intStream(split, a.isParallel() || b.isParallel()); return stream.onClose(Streams.composedClose(a, b));
/** * 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); }); }
/** * Returns a stream consisting of elements of the passed stream that match * the given predicate up to, but discarding, the first element encountered * that does not match the predicate. All subsequently encountered elements * are discarded. * * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting * stateful intermediate operation</a>. * * @param stream the stream to wrap for the {@code takeWhile()} operation * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, * predicate to apply to each element to determine if it * should be included, or it and all subsequently * encountered elements be discarded. * @return the new stream * @since 9 */ public static IntStream takeWhile(IntStream stream, IntPredicate predicate) { Objects.requireNonNull(stream); Objects.requireNonNull(predicate); // Reuses the unordered spliterator, which, when encounter is present, // is safe to use as long as it configured not to split return StreamSupport.intStream( new WhileOps.UnorderedWhileSpliterator.OfInt.Taking(stream.spliterator(), true, predicate), stream.isParallel()).onClose(StreamSupport.closeHandler(stream)); }
/** * 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); }); }
/** * Returns a stream consisting of elements of the passed stream that match * the given predicate up to, but discarding, the first element encountered * that does not match the predicate. All subsequently encountered elements * are discarded. * * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting * stateful intermediate operation</a>. * * @param stream the stream to wrap for the {@code takeWhile()} operation * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, * predicate to apply to each element to determine if it * should be included, or it and all subsequently * encountered elements be discarded. * @return the new stream * @since 9 */ public static IntStream takeWhile(IntStream stream, IntPredicate predicate) { Objects.requireNonNull(stream); Objects.requireNonNull(predicate); // Reuses the unordered spliterator, which, when encounter is present, // is safe to use as long as it configured not to split return StreamSupport.intStream( new WhileOps.UnorderedWhileSpliterator.OfInt.Taking(stream.spliterator(), true, predicate), stream.isParallel()).onClose(StreamSupport.closeHandler(stream)); }
/** * 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 stream consisting of the remaining elements of the passed * stream after discarding elements that match the given predicate up to, * but not discarding, the first element encountered that does not match * the predicate. All subsequently encountered elements are not discarded. * * <p>This is a <a href="package-summary.html#StreamOps">stateful * intermediate operation</a>. * * @param stream the stream to wrap for the {@code dropWhile()} operation * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, * predicate to apply to each element to determine if it * should be discarded, or it and all subsequently * encountered elements be included. * @return the new stream * @since 9 */ public static IntStream dropWhile(IntStream stream, IntPredicate predicate) { Objects.requireNonNull(stream); Objects.requireNonNull(predicate); // Reuses the unordered spliterator, which, when encounter is present, // is safe to use as long as it configured not to split return StreamSupport.intStream( new WhileOps.UnorderedWhileSpliterator.OfInt.Dropping(stream.spliterator(), true, predicate), stream.isParallel()).onClose(StreamSupport.closeHandler(stream)); }
/** * 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 stream consisting of the remaining elements of the passed * stream after discarding elements that match the given predicate up to, * but not discarding, the first element encountered that does not match * the predicate. All subsequently encountered elements are not discarded. * * <p>This is a <a href="package-summary.html#StreamOps">stateful * intermediate operation</a>. * * @param stream the stream to wrap for the {@code dropWhile()} operation * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, * predicate to apply to each element to determine if it * should be discarded, or it and all subsequently * encountered elements be included. * @return the new stream * @since 9 */ public static IntStream dropWhile(IntStream stream, IntPredicate predicate) { Objects.requireNonNull(stream); Objects.requireNonNull(predicate); // Reuses the unordered spliterator, which, when encounter is present, // is safe to use as long as it configured not to split return StreamSupport.intStream( new WhileOps.UnorderedWhileSpliterator.OfInt.Dropping(stream.spliterator(), true, predicate), stream.isParallel()).onClose(StreamSupport.closeHandler(stream)); }
/** * 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.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); }); }