List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:com.vmware.admiral.request.compute.NetworkProfileQueryUtils.java
private static void getContextComputeNetworks(ServiceHost host, URI referer, String contextId, BiConsumer<Set<String>, Throwable> consumer, Consumer<HashMap<String, ComputeNetwork>> callbackFunction) { HashMap<String, ComputeNetwork> contextNetworks = new HashMap<>(); if (StringUtil.isNullOrEmpty(contextId)) { callbackFunction.accept(contextNetworks); return;// w w w. j a va 2 s . c o m } // Get all ComputeNetworks that have the same context id List<ComputeNetwork> computeNetworks = new ArrayList<>(); QueryTask.Query.Builder builder = QueryTask.Query.Builder.create().addKindFieldClause(ComputeNetwork.class); builder.addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, FIELD_NAME_CONTEXT_ID_KEY, contextId); QueryUtils.QueryByPages<ComputeNetwork> query = new QueryUtils.QueryByPages<>(host, builder.build(), ComputeNetwork.class, null); query.queryDocuments(ns -> computeNetworks.add(ns)).whenComplete((v, e) -> { if (e != null) { consumer.accept(null, e); return; } // Get ComputeNetworkDescription of every network List<DeferredResult<Pair<String, ComputeNetwork>>> list = computeNetworks.stream() .map(cn -> host.sendWithDeferredResult( Operation.createGet(host, cn.descriptionLink).setReferer(referer), ComputeNetworkDescription.class).thenCompose(cnd -> { DeferredResult<Pair<String, ComputeNetwork>> r = new DeferredResult<>(); r.complete(Pair.of(cnd.name, cn)); return r; })) .collect(Collectors.toList()); // Create a map of ComputeNetworkDescription.name to ComputeNetworkState DeferredResult.allOf(list).whenComplete((all, t) -> { all.forEach(p -> contextNetworks.put(p.getKey(), p.getValue())); callbackFunction.accept(contextNetworks); }); }); }
From source file:com.github.horrorho.inflatabledonkey.util.LZFSEExtInputStream.java
static void pipe(InputStream is, OutputStream os, Consumer<IOException> error) { logger.trace("<< pipe() - is: {} os: {} error: {}", is, os, error); try {//w ww .j a va 2s . c o m IOUtils.copy(is, os); } catch (IOException ex) { error.accept(ex); } finally { try { is.close(); } catch (IOException ex) { error.accept(ex); } try { os.close(); } catch (IOException ex) { error.accept(ex); } logger.trace(">> pipe()"); } }
From source file:at.gridtec.lambda4j.consumer.tri.TriConsumer.java
/** * Creates a {@link TriConsumer} which uses the {@code first} parameter of this one as argument for the given {@link * Consumer}./*from ww w.j av a 2s . 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 <V> The type of the third argument to the consumer * @param consumer The consumer which accepts the {@code first} parameter of this one * @return Creates a {@code TriConsumer} 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, V> TriConsumer<T, U, V> onlyFirst(@Nonnull final Consumer<? super T> consumer) { Objects.requireNonNull(consumer); return (t, u, v) -> consumer.accept(t); }
From source file:at.gridtec.lambda4j.consumer.tri.TriConsumer.java
/** * Creates a {@link TriConsumer} which uses the {@code second} parameter of this one as argument for the given * {@link Consumer}.// ww w . j a v a2s . 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 <V> The type of the third argument to the consumer * @param consumer The consumer which accepts the {@code second} parameter of this one * @return Creates a {@code TriConsumer} 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, V> TriConsumer<T, U, V> onlySecond(@Nonnull final Consumer<? super U> consumer) { Objects.requireNonNull(consumer); return (t, u, v) -> consumer.accept(u); }
From source file:at.gridtec.lambda4j.consumer.tri.TriConsumer.java
/** * Creates a {@link TriConsumer} which uses the {@code third} parameter of this one as argument for the given {@link * Consumer}.//from w w w . ja v a 2s . 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 <V> The type of the third argument to the consumer * @param consumer The consumer which accepts the {@code third} parameter of this one * @return Creates a {@code TriConsumer} which uses the {@code third} parameter of this one as argument for the * given {@code Consumer}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V> TriConsumer<T, U, V> onlyThird(@Nonnull final Consumer<? super V> consumer) { Objects.requireNonNull(consumer); return (t, u, v) -> consumer.accept(v); }
From source file:com.spleefleague.core.utils.DatabaseConnection.java
public static void find(final MongoCollection<Document> dbcoll, final Document query, Consumer<FindIterable<Document>> callback) { Bukkit.getScheduler().runTaskAsynchronously(SpleefLeague.getInstance(), () -> { callback.accept(dbcoll.find(query)); });/*www .j a va 2s .c o m*/ }
From source file:com.liferay.apio.architect.internal.body.MultipartToBodyConverter.java
private static void _storeFileItem(FileItem fileItem, Consumer<String> valueConsumer, Consumer<BinaryFile> fileConsumer) { try {/* ww w . j a v a 2 s .com*/ if (fileItem.isFormField()) { InputStream stream = fileItem.getInputStream(); valueConsumer.accept(Streams.asString(stream)); } else { BinaryFile binaryFile = new BinaryFile(fileItem.getInputStream(), fileItem.getSize(), fileItem.getContentType(), fileItem.getName()); fileConsumer.accept(binaryFile); } } catch (IOException ioe) { throw new BadRequestException("Invalid body", ioe); } }
From source file:org.apache.metron.common.stellar.benchmark.Microbenchmark.java
private static void run(int numTimes, StellarStatement statement, Consumer<Long> func) { StellarProcessor processor = new StellarProcessor(); for (int i = 0; i < numTimes; ++i) { long start = System.nanoTime(); processor.parse(statement.expression, statement.variableResolver, statement.functionResolver, statement.context);/*from w ww .j a va 2 s. c o m*/ func.accept((System.nanoTime() - start) / 1000); } }
From source file:Main.java
/** * Returns a property that defines the state of the given worker. Once the worker is done the value of the * property will be set to true//from w w w . java 2 s. co m * @param worker the worker * @return the property */ public static ReadOnlyBooleanProperty createIsDoneProperty(Worker<?> worker) { final BooleanProperty property = new SimpleBooleanProperty(); Consumer<Worker.State> stateChecker = (s) -> { if (s.equals(Worker.State.CANCELLED) || s.equals(Worker.State.FAILED) || s.equals(Worker.State.SUCCEEDED)) { property.setValue(true); } else { property.setValue(false); } }; worker.stateProperty().addListener((o, oldValue, newValue) -> stateChecker.accept(newValue)); stateChecker.accept(worker.getState()); return property; }
From source file:org.apache.jena.fuseki.embedded.TestEmbeddedFuseki.java
static void query(String URL, String query, Consumer<QueryExecution> body) { try (QueryExecution qExec = QueryExecutionFactory.sparqlService(URL, query)) { body.accept(qExec); }/* www .j av a 2 s . c o m*/ }