Java Code Examples for java.util.function.Consumer#accept()
The following examples show how to use
java.util.function.Consumer#accept() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FinalizeHalf.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
static void test(String algo, Provider provider, boolean priv, Consumer<Key> method) throws Exception { KeyPairGenerator generator; try { generator = KeyPairGenerator.getInstance(algo, provider); } catch (NoSuchAlgorithmException nsae) { return; } System.out.println("Checking " + provider.getName() + ", " + algo); KeyPair pair = generator.generateKeyPair(); Key key = priv ? pair.getPrivate() : pair.getPublic(); pair = null; for (int i = 0; i < 32; ++i) { System.gc(); } try { method.accept(key); } catch (ProviderException pe) { failures++; } }
Example 2
Source File: ConcurrentSkipListMap.java From hottub with GNU General Public License v2.0 | 6 votes |
public boolean tryAdvance(Consumer<? super K> action) { if (action == null) throw new NullPointerException(); Comparator<? super K> cmp = comparator; K f = fence; Node<K,V> e = current; for (; e != null; e = e.next) { K k; Object v; if ((k = e.key) != null && f != null && cpr(cmp, f, k) <= 0) { e = null; break; } if ((v = e.value) != null && v != e) { current = e.next; action.accept(k); return true; } } current = e; return false; }
Example 3
Source File: ClusterPair.java From metanome-algorithms with Apache License 2.0 | 6 votes |
public boolean fullCheck(List<Predicate> p, Consumer<ClusterPair> consumer) { TIntIterator iter = c1.iterator(); while (iter.hasNext()) { int line1 = iter.next(); Cluster newC = new Cluster(); TIntIterator iter2 = c2.iterator(); while (iter2.hasNext()) { int line2 = iter2.next(); if (line1 != line2 && p.stream().allMatch(pr -> pr.satisfies(line1, line2))) { newC.add(line2); } } ClusterPair newPair = new ClusterPair(new Cluster(line1), newC); if (newPair.containsLinePair()) consumer.accept(newPair); } return true; }
Example 4
Source File: TestShellExecEndpointCoprocessor.java From hbase with Apache License 2.0 | 6 votes |
private void testShellExecForeground(final Consumer<ShellExecRequest.Builder> consumer) { final AsyncConnection conn = connectionRule.getConnection(); final AsyncAdmin admin = conn.getAdmin(); final String command = "echo -n \"hello world\""; final ShellExecRequest.Builder builder = ShellExecRequest.newBuilder() .setCommand(command); consumer.accept(builder); final ShellExecResponse resp = admin .<ShellExecService.Stub, ShellExecResponse>coprocessorService( ShellExecService::newStub, (stub, controller, callback) -> stub.shellExec(controller, builder.build(), callback)) .join(); assertEquals(0, resp.getExitCode()); assertEquals("hello world", resp.getStdout()); }
Example 5
Source File: JpaPersistenceServiceImpl.java From genie with Apache License 2.0 | 5 votes |
private void setEntityResources( final ExecutionEnvironment resources, final Consumer<Set<FileEntity>> configsConsumer, final Consumer<Set<FileEntity>> dependenciesConsumer ) { // Save all the unowned entities first to avoid unintended flushes configsConsumer.accept(this.createOrGetFileEntities(resources.getConfigs())); dependenciesConsumer.accept(this.createOrGetFileEntities(resources.getDependencies())); }
Example 6
Source File: InstantColumn.java From tablesaw with Apache License 2.0 | 5 votes |
private InstantColumn fillWith( int count, Iterable<Instant> iterable, Consumer<Instant> acceptor) { Iterator<Instant> iterator = iterable.iterator(); for (int r = 0; r < count; r++) { if (!iterator.hasNext()) { iterator = iterable.iterator(); if (!iterator.hasNext()) { break; } } acceptor.accept(iterator.next()); } return this; }
Example 7
Source File: DevOpsCommandsActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
private void tryInterpretAsDirectPublication(final DevOpsCommand<?> command, final Consumer<Publish> onSuccess, final Consumer<DevOpsErrorResponse> onError) { if (command instanceof ExecutePiggybackCommand) { final ExecutePiggybackCommand executePiggyback = (ExecutePiggybackCommand) command; final DittoHeaders dittoHeaders = executePiggyback.getDittoHeaders(); deserializePiggybackCommand(executePiggyback, jsonifiable -> { final Optional<String> topic = Optional.ofNullable(dittoHeaders.get(TOPIC_HEADER)) .map(Optional::of) .orElseGet(() -> executePiggyback.getPiggybackCommand() .getValue(Command.JsonFields.TYPE)); if (topic.isPresent()) { if (isGroupTopic(dittoHeaders)) { onSuccess.accept(DistPubSubAccess.publishViaGroup(topic.get(), jsonifiable)); } else { onSuccess.accept(DistPubSubAccess.publish(topic.get(), jsonifiable)); } } else { onError.accept(getErrorResponse(command)); } }, dittoRuntimeException -> onError.accept(getErrorResponse(command, dittoRuntimeException.toJson()))); } else { // this should not happen final JsonObject error = GatewayInternalErrorException.newBuilder().dittoHeaders(command.getDittoHeaders()).build().toJson(); onError.accept(getErrorResponse(command, error)); } }
Example 8
Source File: ScheduledActionExecutor.java From titus-control-plane with Apache License 2.0 | 5 votes |
private ScheduledAction changeState(Consumer<SchedulingStatus.Builder> updater) { SchedulingStatus.Builder statusBuilder = SchedulingStatus.newBuilder() .withTimestamp(clock.wallTime()); updater.accept(statusBuilder); SchedulingStatus oldStatus = action.getStatus(); List<SchedulingStatus> statusHistory = CollectionsExt.copyAndAdd(action.getStatusHistory(), oldStatus); return action.toBuilder() .withStatus(statusBuilder.build()) .withStatusHistory(statusHistory) .build(); }
Example 9
Source File: ByteBufQueue.java From datakernel with Apache License 2.0 | 5 votes |
public int drainTo(@NotNull Consumer<ByteBuf> dest) { int size = 0; while (hasRemaining()) { ByteBuf buf = take(); dest.accept(buf); size += buf.readRemaining(); } return size; }
Example 10
Source File: GroupedStatefullySpliterator.java From cyclops with Apache License 2.0 | 5 votes |
@Override public boolean tryAdvance(Consumer<? super R> action) { if(closed) return false; boolean accepted[]= {true}; while (accepted[0]) { boolean canAdvance = source.tryAdvance(t -> { collection = (C)collection.plus(t); accepted[0]= predicate.test(collection,t); }); if (!canAdvance) { if(collection.size()>0) { action.accept(finalizer.apply(collection)); collection = factory.get(); } closed = true; return false; } } if(collection.size()>0) { action.accept(finalizer.apply(collection)); collection = factory.get(); } return true; }
Example 11
Source File: TupleConstructors.java From datakernel with Apache License 2.0 | 5 votes |
public static <T1, T2, R> TupleConstructor2<T1, T2, R> toPojo(Supplier<R> pojoSupplier, Consumer<T1> setter1, Consumer<T2> setter2) { return (value1, value2) -> { R pojo = pojoSupplier.get(); setter1.accept(value1); setter2.accept(value2); return pojo; }; }
Example 12
Source File: TableReference.java From sis with Apache License 2.0 | 5 votes |
/** * Formats a graphical representation of an object for debugging purpose. This representation * can be printed to the {@linkplain System#out standard output stream} (for example) * if the output device uses a monospaced font and supports Unicode. */ static String toString(final Object owner, final Consumer<TreeTable.Node> appender) { final DefaultTreeTable table = new DefaultTreeTable(TableColumn.NAME); final TreeTable.Node root = table.getRoot(); root.setValue(TableColumn.NAME, owner.getClass().getSimpleName()); appender.accept(root); return table.toString(); }
Example 13
Source File: Tree.java From java with MIT License | 5 votes |
private void inorder(Node node, Consumer<Character> emitter) { if (node == null) { return; } inorder(node.left, emitter); emitter.accept(node.value); inorder(node.right, emitter); }
Example 14
Source File: RawAsyncHBaseAdmin.java From hbase with Apache License 2.0 | 5 votes |
private <PREQ, PRESP> CompletableFuture<Void> procedureCall( Consumer<MasterRequestCallerBuilder<?>> prioritySetter, PREQ preq, MasterRpcCall<PRESP, PREQ> rpcCall, Converter<Long, PRESP> respConverter, ProcedureBiConsumer consumer) { MasterRequestCallerBuilder<Long> builder = this.<Long> newMasterCaller().action((controller, stub) -> this.<PREQ, PRESP, Long> call(controller, stub, preq, rpcCall, respConverter)); prioritySetter.accept(builder); CompletableFuture<Long> procFuture = builder.call(); CompletableFuture<Void> future = waitProcedureResult(procFuture); addListener(future, consumer); return future; }
Example 15
Source File: LinkedHashMap.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public final void forEach(Consumer<? super Map.Entry<K,V>> action) { if (action == null) throw new NullPointerException(); int mc = modCount; for (LinkedHashMap.Entry<K,V> e = head; e != null; e = e.after) action.accept(e); if (modCount != mc) throw new ConcurrentModificationException(); }
Example 16
Source File: Iterable.java From j4ts with Apache License 2.0 | 4 votes |
default void forEach(Consumer<? super T> action) { checkNotNull(action); for (T t : this) { action.accept(t); } }
Example 17
Source File: SSZ.java From incubator-tuweni with Apache License 2.0 | 4 votes |
static void encodeAddressListTo(Bytes[] elements, Consumer<Bytes> appender) { appender.accept(Bytes.wrap(listLengthPrefix(elements.length, 20))); for (Bytes bytes : elements) { appender.accept(encodeAddress(bytes)); } }
Example 18
Source File: JedisClientDelegate.java From kork with Apache License 2.0 | 4 votes |
@Override public void withScriptingClient(Consumer<ScriptingCommands> f) { try (Jedis jedis = jedisPool.getResource()) { f.accept(jedis); } }
Example 19
Source File: Functional.java From mldht with Mozilla Public License 2.0 | 4 votes |
public static <T> T tap(T obj, Consumer<T> c) { c.accept(obj); return obj; }
Example 20
Source File: WriteBatcherImpl.java From java-client-api with Apache License 2.0 | 4 votes |
@Override public void run() { try { Runnable onBeforeWrite = writeSet.getOnBeforeWrite(); if ( onBeforeWrite != null ) { onBeforeWrite.run(); } TransactionInfo transactionInfo = writeSet.getTransactionInfo(); if ( transactionInfo == null || transactionInfo.alive.get() == true ) { Transaction transaction = null; if ( transactionInfo != null ) { transaction = transactionInfo.transaction; transactionInfo.written.set(true); } logger.trace("begin write batch {} to forest on host \"{}\"", writeSet.getBatchNumber(), writeSet.getClient().getHost()); if ( writeSet.getTemporalCollection() == null ) { writeSet.getClient().newDocumentManager().write( writeSet.getWriteSet(), writeSet.getTransform(), transaction ); } else { // to get access to the TemporalDocumentManager write overload we need to instantiate // a JSONDocumentManager or XMLDocumentManager, but we don't want to make assumptions about content // format, so we'll set the default content format to unknown XMLDocumentManager docMgr = writeSet.getClient().newXMLDocumentManager(); docMgr.setContentFormat(Format.UNKNOWN); docMgr.write( writeSet.getWriteSet(), writeSet.getTransform(), transaction, writeSet.getTemporalCollection() ); } closeAllHandles(); Runnable onSuccess = writeSet.getOnSuccess(); if ( onSuccess != null ) { onSuccess.run(); } } else { throw new DataMovementException("Failed to write because transaction already underwent commit or rollback", null); } } catch (Throwable t) { logger.trace("failed batch sent to forest on host \"{}\"", writeSet.getClient().getHost()); Consumer<Throwable> onFailure = writeSet.getOnFailure(); if ( onFailure != null ) { onFailure.accept(t); } } }