Box<Boolean> wasChanged = Box.of(false); ImmutableSet<File> result = cached.computeIfAbsent(ImmutableSet.copyOf(mavenCoords), coords -> { wasChanged.set(true); return ImmutableSet.copyOf(input.get().provisionWithTransitives(withTransitives, coords)); });
/** Delegates to set(). */ default void accept(T value) { set(value); }
/** * Delegates to {@link #set}. * * @deprecated Provided to satisfy the {@link Consumer} interface; use {@link #set} instead. */ @Deprecated default void accept(T value) { set(value); }
/** * Delegates to set(). * * @deprecated Provided to satisfy the {@link Consumer} interface; use {@link #set} instead. */ @Deprecated default void accept(T value) { set(value); }
public <T> CompletionStage<T> filter(CompletionStage<T> obj) { box.set(obj.toCompletableFuture()); return obj; } }
/** * Performs a set() on the result of a get(). * * Some implementations may provide atomic semantics, * but it's not required. */ default T modify(Function<? super T, ? extends T> mutator) { T modified = mutator.apply(get()); set(modified); return modified; }
/** Shortcut for doing a set() on the result of a get(). */ default T modify(Function<? super T, ? extends T> mutator) { T modified = mutator.apply(get()); set(modified); return modified; }
/** * Performs a set() on the result of a get(). * * Some implementations may provide atomic semantics, * but it's not required. */ default T modify(Function<? super T, ? extends T> mutator) { T modified = mutator.apply(get()); set(modified); return modified; }
@Override public void set(CompletionStage<?> obj) { delegate.get().toCompletableFuture().cancel(true); delegate.set(obj); } };
@Override public void set(R value) { delegate.set(converter.revertNonNull(value)); }
@Override public void set(R value) { delegate.set(converter.revertNonNull(value)); }
/** Maps one {@code Box} to another {@code Box}. */ default <R> Box<R> map(Function<? super T, ? extends R> getMapper, Function<? super R, ? extends T> setMapper) { return Box.from(() -> getMapper.apply(get()), toSet -> set(setMapper.apply(toSet))); }
/** * Given a consumer of lines, creates a stateful consumer of strings * which will combine its input until it finds a newline, and * split its input when it contains multiple newlines. Examples * make this more clear: * <pre> * "some", "\n", "simple ", "lines", "\n" -> "some", "simple lines" * "some\nsimple lines\n" -> "some", "simple lines" * "no newline\nno output" -> "no newline" * </pre> * @param perLine a Consumer<String> which will receive strings which were terminated by newlines (but aren't anymore). * @return a Consumer<String> which accepts any strings, and will feed them to perLine. */ public static Consumer<String> stringsToLines(Consumer<String> perLine) { Box<String> leftover = Box.of(""); return rawString -> { rawString = leftover.get() + rawString.replace("\r", ""); int lastIdx = 0; int idx = 0; while ((idx = rawString.indexOf('\n', lastIdx)) > -1) { perLine.accept(rawString.substring(lastIdx, idx)); lastIdx = idx + 1; } leftover.set(rawString.substring(lastIdx)); }; }
/** * Given a consumer of lines, creates a stateful consumer of strings * which will combine its input until it finds a newline, and * split its input when it contains multiple newlines. Examples * make this more clear: * <pre> * "some", "\n", "simple ", "lines", "\n" -> "some", "simple lines" * "some\nsimple lines\n" -> "some", "simple lines" * "no newline\nno output" -> "no newline" * </pre> * @param perLine a Consumer<String> which will receive strings which were terminated by newlines (but aren't anymore). * @return a Consumer<String> which accepts any strings, and will feed them to perLine. */ public static Consumer<String> stringsToLines(Consumer<String> perLine) { Box<String> leftover = Box.of(""); return rawString -> { rawString = leftover.get() + rawString.replace("\r", ""); int lastIdx = 0; int idx = 0; while ((idx = rawString.indexOf('\n', lastIdx)) > -1) { perLine.accept(rawString.substring(lastIdx, idx)); lastIdx = idx + 1; } leftover.set(rawString.substring(lastIdx)); }; }
/** * Given a consumer of lines, creates a stateful consumer of strings * which will combine its input until it finds a newline, and * split its input when it contains multiple newlines. Examples * make this more clear: * * ``` * "some", "\n", "simple ", "lines", "\n" -> "some", "simple lines" * "some\nsimple lines\n" -> "some", "simple lines" * "no newline\nno output" -> "no newline" * ``` * * @param perLine a `Consumer<String>` which will receive strings which were terminated by newlines. * (the newlines are stripped when they are passed to the consumer) * @return a `Consumer<String>` which accepts any strings, and will feed them to perLine. */ public static Consumer<String> stringsToLines(Consumer<String> perLine) { requireNonNull(perLine); Box<String> leftover = Box.of(""); return rawString -> { rawString = leftover.get() + rawString.replace("\r", ""); int lastIdx = 0; int idx = 0; while ((idx = rawString.indexOf('\n', lastIdx)) > -1) { perLine.accept(rawString.substring(lastIdx, idx)); lastIdx = idx + 1; } leftover.set(rawString.substring(lastIdx)); }; }
private static void setResult(Control ctl, Optional<Throwable> result) { SwtExec.async().guardOn(ctl).execute(() -> { Shell shell = ctl.getShell(); Box<Optional<Throwable>> resultBox = shellToResult.remove(shell); Objects.requireNonNull(resultBox, "No test shell for control."); resultBox.set(result); shell.dispose(); }); }
result.set(Optional.empty()); }); });
btn.setText(isPass ? "PASS" : "FAIL"); btn.addListener(SWT.Selection, e -> { result.set(isPass ? Optional.empty() : Optional.of(new FailedByUser(instructions))); cmp.getShell().dispose(); });