List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:org.onlab.netty.NettyMessaging.java
private void dispatchLocally(InternalMessage message) throws IOException { String type = message.type(); if (REPLY_MESSAGE_TYPE.equals(type)) { try {//from www. ja v a 2s .c o m CompletableFuture<byte[]> futureResponse = responseFutures.getIfPresent(message.id()); if (futureResponse != null) { futureResponse.complete(message.payload()); } else { log.warn("Received a reply for message id:[{}]. " + " from {}. But was unable to locate the" + " request handle", message.id(), message.sender()); } } finally { responseFutures.invalidate(message.id()); } return; } Consumer<InternalMessage> handler = handlers.get(type); if (handler != null) { handler.accept(message); } else { log.debug("No handler registered for {}", type); } }
From source file:com.yahoo.bard.webservice.config.ConfigurationGraph.java
/** * Take a configuration and if it is a valid module, load it into the moduleConfigurations map and load it's * dependency moduleDependencies./*from www. jav a2 s. co m*/ * * @param configuration A configuration which may be a module * @param configName The resource name for that configuration * @param nameValidator A function which throws exceptions on module names which are not valid. */ @SuppressWarnings("unchecked") private void addVertex(Configuration configuration, String configName, Consumer<String> nameValidator) { if (!configuration.containsKey(MODULE_NAME_KEY)) { // This may be the result of another library using one of our configuration names LOG.warn(MODULE_NAME_MISSING.logFormat(configName)); return; } String moduleName = configuration.getString(MODULE_NAME_KEY); nameValidator.accept(moduleName); LOG.debug(MODULE_FOUND_MESSAGE.logFormat(moduleName, configName)); if (moduleConfigurations.containsKey(moduleName)) { LOG.error(MODULE_NAME_DUPLICATION.format(configName, moduleName)); throw new SystemConfigException(MODULE_NAME_DUPLICATION.format(configName, moduleName)); } moduleConfigurations.put(moduleName, configuration); List<String> dependencies = new ArrayList<>( configuration.getList(DEPENDENT_MODULE_KEY, Collections.<String>emptyList())); // later dependencies have higher precedence. Store moduleDependencies in precedence order descending Collections.reverse(dependencies); moduleDependencies.put(moduleName, dependencies); }
From source file:org.opencb.cellbase.lib.impl.GeneMongoDBAdaptor.java
@Override public void forEach(Query query, Consumer<? super Object> action, QueryOptions options) { Objects.requireNonNull(action); Iterator iterator = nativeIterator(query, options); while (iterator.hasNext()) { action.accept(iterator.next()); }//from ww w .j av a 2 s .co m }
From source file:nu.yona.server.analysis.service.InactivityManagementService.java
private <T> T createInactivity(UUID userAnonymizedId, UUID goalId, Supplier<T> existingActivityFinder, BiFunction<UserAnonymized, Goal, T> creator, Consumer<T> storer) { T existingActivity = existingActivityFinder.get(); if (existingActivity != null) { return existingActivity; }//from ww w .j a v a 2s .c o m UserAnonymized userAnonymized = userAnonymizedService.getUserAnonymizedEntity(userAnonymizedId); Goal goal = goalService.getGoalEntityForUserAnonymizedId(userAnonymizedId, goalId); T inactivityEntity = creator.apply(userAnonymized, goal); storer.accept(inactivityEntity); return inactivityEntity; }
From source file:local.laer.app.knapsack.support.OffsetIntMatrix.java
public void consume(Consumer<Cell<Integer>> callback) { SimpleCell<Integer> cell = new SimpleCell<>(); for (int row = 0; row < rows(); row++) { for (int col = 0; col < cols(); col++) { cell.col = col + colOffset;/*from w ww . java2s . c o m*/ cell.row = row + rowOffset; cell.value = value[row][col]; callback.accept(cell); } } }
From source file:org.jsweet.transpiler.util.AbstractTreePrinter.java
/** * Prints a comma-separated list of subtrees. *//*from w w w. j a v a 2s . c o m*/ public AbstractTreePrinter printArgList(List<? extends JCTree> args, Consumer<JCTree> printer) { for (JCTree arg : args) { if (printer != null) { printer.accept(arg); } else { print(arg); } print(", "); inArgListTail = true; } inArgListTail = false; if (!args.isEmpty()) { removeLastChars(2); } return this; }
From source file:at.ac.tuwien.qse.sepm.service.impl.PhotoServiceImpl.java
@Override public void subscribeCreate(Consumer<Photo> callback) { photoRepository.addListener(new PhotoRepository.Listener() { @Override/*from ww w .j a va 2 s . co m*/ public void onCreate(PhotoRepository repository, Path file) { LOGGER.info("created {}", file); try { Photo photo = repository.read(file); callback.accept(photo); } catch (DAOException ex) { LOGGER.error("Failed to read photo {}", file); } } }); }
From source file:at.ac.tuwien.qse.sepm.service.impl.PhotoServiceImpl.java
@Override public void subscribeUpdate(Consumer<Photo> callback) { photoRepository.addListener(new PhotoRepository.Listener() { @Override/* ww w .j a v a 2 s .c o m*/ public void onUpdate(PhotoRepository repository, Path file) { LOGGER.info("updated {}", file); try { Photo photo = repository.read(file); callback.accept(photo); } catch (DAOException ex) { LOGGER.error("Failed to read photo {}", file); } } }); }
From source file:com.diversityarrays.kdxplore.curate.TrialDataEditorServiceImpl.java
@Override public void createUserInterface(BackgroundRunner backgroundRunner, CurationParams params, Consumer<Either<InitError, TrialDataEditorResult>> onComplete) { BackgroundTask<CurationData, Void> task = new BackgroundTask<CurationData, Void>("Collecting Trial Data...", false) {/*from www. ja v a2s. c o m*/ @Override public void onTaskComplete(CurationData cd) { PlotIdentSummary pis = cd.getTrial().getPlotIdentSummary(); if (pis == null) { onComplete.accept(Either.left(InitError.NO_PLOTIDENT_SUMMARY)); return; } if (!pis.hasXandY() && pis.plotIdentRange.isEmpty()) { onComplete.accept(Either.left(InitError.NO_ID_X_OR_Y)); return; } if (PlotIdentOption.NO_X_Y_OR_PLOT_ID == cd.getTrial().getPlotIdentOption()) { onComplete.accept(Either.left(InitError.NO_IDENT_SPECIFIED)); return; } try { TrialDataEditor editor = TrialDataEditor.createTrialDataEditor(params.offlineData, cd, params.windowOpener, params.messageLogger); TrialDataEditorResult result = new TrialDataEditorResult(); result.curationData = cd; result.frame = params.windowOpener.addDesktopObject(editor); result.onFrameClosed = new Closure<Void>() { @Override public void execute(Void arg0) { editor.pushDownAllGraphAndPlotFrames(); } }; onComplete.accept(Either.right(result)); } catch (IOException e) { onComplete.accept(Either.left(InitError.error(e))); } } @Override public void onException(Throwable error) { onComplete.accept(Either.left(InitError.error(error))); } @Override public void onCancel(CancellationException ce) { onComplete.accept(Either.left(InitError.error(ce))); } @Override public CurationData generateResult(Closure<Void> arg0) throws Exception { CurationData curationData = CurationData.create(params.trial, CurationData.FULL_DETAILS, params.offlineData.getKdxploreDatabase()); return curationData; } }; backgroundRunner.runBackgroundTask(task); }
From source file:org.trustedanalytics.cloud.cc.CcClientTest.java
private void verifyWithDelete(Consumer<UUID> consumer, String apiUrl) { UUID guid = UUID.randomUUID(); consumer.accept(guid); verify(template).delete(eq(apiUrl), anyMapOf(String.class, Object.class)); }