List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:org.moe.gradle.utils.TaskUtils.java
@NotNull public static <T extends Task> Task create(@NotNull Project project, @NotNull String name, @NotNull Class<T> type, @NotNull Consumer<T> configure) { Require.nonNull(project);/*from www . ja v a 2s. c om*/ Require.nonNull(name); Require.nonNull(type); Require.nonNull(configure); return project.task(MapUtils.stringMap("type", type), name, new TaskClosure<T>(project) { @Override public void doCall(T task) { Require.nonNull(task); configure.accept(task); } }); }
From source file:de.se_rwth.langeditor.util.Misc.java
public static <T> void traverse(T root, Function<T, Collection<? extends T>> childGenerator, Consumer<? super T> enter, Consumer<? super T> exit) { Set<T> previouslyVisited = new HashSet<>(); Stack<T> yetToVisit = new Stack<>(); yetToVisit.push(root);// w w w . j ava 2 s . c om T nextElement; while (!yetToVisit.isEmpty()) { nextElement = yetToVisit.peek(); if (!previouslyVisited.contains(nextElement)) { enter.accept(nextElement); previouslyVisited.add(nextElement); yetToVisit.addAll(childGenerator.apply(nextElement)); } else { exit.accept(yetToVisit.pop()); } } }
From source file:Main.java
/** * Runs arbitrary code in the Event Dispatch Thread. * <p>// w ww. j ava 2 s . c o m * The first operation performed by this method is fetching the {@code Object} to return. If {@code supplier} is not {@code null}, its {@code get()} method will be called to fetch the {@code Object}. But if {@code supplier} is {@code null}, or it * produces a {@code null} "value" from its {@code get()} method, then {@code defaultObject}, which may also be {@code null}, will be used instead. * <p> * The second operation performed by this method is handling the {@code Object} to return. So if neither {@code consumer} nor the fetched {@code Object} are {@code null}, the fetched {@code Object} will be handed to {@code consumer}. * <p> * Returns the fetched {@code Object}, which may be {@code null}. * * @param <T> the type of the returned result * @param supplier the {@code Supplier}, which may be {@code null} * @param consumer the {@code Consumer}, which may be {@code null} * @param defaultObject the default {@code Object}, which may be {@code null} * @return the fetched {@code Object}, which may be {@code null} */ public static <T> T runInEDT(final Supplier<T> supplier, final Consumer<T> consumer, final T defaultObject) { final AtomicReference<T> atomicReference = new AtomicReference<>(); if (supplier != null) { runInEDT(() -> atomicReference.set(supplier.get())); } if (defaultObject != null) { atomicReference.compareAndSet(null, defaultObject); } if (atomicReference.get() != null && consumer != null) { runInEDT(() -> consumer.accept(atomicReference.get())); } return atomicReference.get(); }
From source file:org.commonjava.indy.bind.jaxrs.util.ResponseUtils.java
public static Response formatOkResponseWithEntity(final Object output, final String contentType, final Consumer<ResponseBuilder> builderModifier) { ResponseBuilder builder = Response.ok(output).type(contentType); if (builderModifier != null) { builderModifier.accept(builder); }//w ww. j a v a 2s . com return builder.build(); }
From source file:de.javagl.jgltf.model.io.JacksonUtils.java
/** * Create a DeserializationProblemHandler that may be added to an * ObjectMapper, and will handle unknown properties by forwarding * the error information to the given consumer, if it is not * <code>null</code>/* w ww . ja va 2 s . c o m*/ * * @param jsonErrorConsumer The consumer for {@link JsonError}s * @return The problem handler */ private static DeserializationProblemHandler createDeserializationProblemHandler( Consumer<? super JsonError> jsonErrorConsumer) { return new DeserializationProblemHandler() { @Override public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser jp, JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName) throws IOException, JsonProcessingException { if (jsonErrorConsumer != null) { jsonErrorConsumer.accept( new JsonError("Unknown property: " + propertyName, jp.getParsingContext(), null)); } return super.handleUnknownProperty(ctxt, jp, deserializer, beanOrClass, propertyName); } }; }
From source file:at.gridtec.lambda4j.consumer.tri.obj.BiObjBooleanConsumer.java
/** * Creates a {@link BiObjBooleanConsumer} which uses the {@code first} parameter of this one as argument for the * given {@link Consumer}./*from w w w . java 2s . com*/ * * @param <T> The type of the first argument to the consumer * @param <U> The type of the second argument to the consumer * @param consumer The consumer which accepts the {@code first} parameter of this one * @return Creates a {@code BiObjBooleanConsumer} which uses the {@code first} parameter of this one as argument for * the given {@code Consumer}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiObjBooleanConsumer<T, U> onlyFirst(@Nonnull final Consumer<? super T> consumer) { Objects.requireNonNull(consumer); return (t, u, value) -> consumer.accept(t); }
From source file:at.gridtec.lambda4j.consumer.tri.obj.BiObjBooleanConsumer.java
/** * Creates a {@link BiObjBooleanConsumer} which uses the {@code second} parameter of this one as argument for the * given {@link Consumer}.// w w w . j a va2s . c om * * @param <T> The type of the first argument to the consumer * @param <U> The type of the second argument to the consumer * @param consumer The consumer which accepts the {@code second} parameter of this one * @return Creates a {@code BiObjBooleanConsumer} which uses the {@code second} parameter of this one as argument * for the given {@code Consumer}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiObjBooleanConsumer<T, U> onlySecond(@Nonnull final Consumer<? super U> consumer) { Objects.requireNonNull(consumer); return (t, u, value) -> consumer.accept(u); }
From source file:at.gridtec.lambda4j.consumer.tri.obj.BiObjByteConsumer.java
/** * Creates a {@link BiObjByteConsumer} which uses the {@code first} parameter of this one as argument for the given * {@link Consumer}./*from ww w . j a v a2s.co m*/ * * @param <T> The type of the first argument to the consumer * @param <U> The type of the second argument to the consumer * @param consumer The consumer which accepts the {@code first} parameter of this one * @return Creates a {@code BiObjByteConsumer} which uses the {@code first} parameter of this one as argument for * the given {@code Consumer}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiObjByteConsumer<T, U> onlyFirst(@Nonnull final Consumer<? super T> consumer) { Objects.requireNonNull(consumer); return (t, u, value) -> consumer.accept(t); }
From source file:at.gridtec.lambda4j.consumer.tri.obj.BiObjByteConsumer.java
/** * Creates a {@link BiObjByteConsumer} which uses the {@code second} parameter of this one as argument for the given * {@link Consumer}./*www .ja v a2 s . co m*/ * * @param <T> The type of the first argument to the consumer * @param <U> The type of the second argument to the consumer * @param consumer The consumer which accepts the {@code second} parameter of this one * @return Creates a {@code BiObjByteConsumer} which uses the {@code second} parameter of this one as argument for * the given {@code Consumer}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiObjByteConsumer<T, U> onlySecond(@Nonnull final Consumer<? super U> consumer) { Objects.requireNonNull(consumer); return (t, u, value) -> consumer.accept(u); }
From source file:at.gridtec.lambda4j.consumer.tri.obj.BiObjCharConsumer.java
/** * Creates a {@link BiObjCharConsumer} which uses the {@code first} parameter of this one as argument for the given * {@link Consumer}./*w w w . j a v a2 s. c o m*/ * * @param <T> The type of the first argument to the consumer * @param <U> The type of the second argument to the consumer * @param consumer The consumer which accepts the {@code first} parameter of this one * @return Creates a {@code BiObjCharConsumer} which uses the {@code first} parameter of this one as argument for * the given {@code Consumer}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> BiObjCharConsumer<T, U> onlyFirst(@Nonnull final Consumer<? super T> consumer) { Objects.requireNonNull(consumer); return (t, u, value) -> consumer.accept(t); }