List of usage examples for java.util.function Consumer accept
void accept(T t);
From source file:org.alfresco.rest.api.tests.TestDownloads.java
private void assertExpectedStatus(DownloadStatus.Status expectedStatus, Download download, String failMessage, Consumer<Download> assertionsToDo, DownloadStatus.Status alternateExpectedStatus, Consumer<Download> alternateAssertionsToDo) throws Exception { for (int i = 0; i <= NUMBER_OF_TIMES_TO_CHECK_STATUS; i++) { if (i == NUMBER_OF_TIMES_TO_CHECK_STATUS) { fail(failMessage);/*from ww w. j ava 2s . c om*/ } Download downloadStatus = getDownload(download.getId()); if (alternateExpectedStatus != null && downloadStatus.getStatus().equals(alternateExpectedStatus)) { alternateAssertionsToDo.accept(downloadStatus); break; } else if (!downloadStatus.getStatus().equals(expectedStatus)) { Thread.sleep(STATUS_CHECK_SLEEP_TIME); } else { assertionsToDo.accept(downloadStatus); break; } } }
From source file:me.ryanhamshire.griefprevention.command.CommandHelper.java
public static Consumer<CommandSource> createCommandConsumer(CommandSource src, String command, String arguments, Consumer<CommandSource> postConsumerTask) { return consumer -> { try {//from www . j av a 2s . co m Sponge.getCommandManager().get(command).get().getCallable().process(src, arguments); } catch (CommandException e) { src.sendMessage(e.getText()); } if (postConsumerTask != null) { postConsumerTask.accept(src); } }; }
From source file:org.opencb.opencga.catalog.db.mongodb.UserMongoDBAdaptor.java
@Override public void forEach(Query query, Consumer<? super Object> action, QueryOptions options) throws CatalogDBException { Objects.requireNonNull(action); DBIterator<User> catalogDBIterator = iterator(query, options); while (catalogDBIterator.hasNext()) { action.accept(catalogDBIterator.next()); }/*from w ww . j a v a 2 s . c o m*/ catalogDBIterator.close(); }
From source file:de.pixida.logtest.designer.automaton.AutomatonEdge.java
protected void createTextAreaInput(final int numLines, final ConfigFrame cf, final String propertyName, final String initialValue, final Consumer<String> applyValue, final Monospace monospace) { final TextArea inputField = new TextArea(initialValue); this.setMonospaceIfDesired(monospace, inputField); inputField.setPrefRowCount(numLines); inputField.setWrapText(true);//from w w w. j a va2s . c om inputField.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> { applyValue.accept(newValue); this.getGraph().handleChange(); }); cf.addOption(propertyName, inputField); }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoUserDBAdaptor.java
@Override public void forEach(Query query, Consumer<? super Object> action, QueryOptions options) throws CatalogDBException { Objects.requireNonNull(action); CatalogDBIterator<User> catalogDBIterator = iterator(query, options); while (catalogDBIterator.hasNext()) { action.accept(catalogDBIterator.next()); }/* w ww . j a v a 2s . com*/ catalogDBIterator.close(); }
From source file:org.opensingular.form.SType.java
@SafeVarargs public final <T extends SView> SType<I> withView(T mView, Consumer<T>... initializers) { for (Consumer<T> initializer : initializers) { initializer.accept(mView); }//from ww w .j a v a 2s . c o m setView(mView); return this; }
From source file:org.jboss.pnc.buildagent.client.BuildAgentClient.java
private Client connectStatusListenerClient(String webSocketBaseUrl, Consumer<TaskStatusUpdateEvent> onStatusUpdate, String commandContext) { Client client = initializeDefault(); Consumer<String> responseConsumer = (text) -> { log.trace("Decoding response: {}", text); ObjectMapper mapper = new ObjectMapper(); JsonNode jsonObject = null;/* ww w.j ava2 s .c o m*/ try { jsonObject = mapper.readTree(text); } catch (IOException e) { log.error("Cannot read JSON string: " + text, e); } try { TaskStatusUpdateEvent taskStatusUpdateEvent = TaskStatusUpdateEvent .fromJson(jsonObject.get("event").toString()); onStatusUpdate.accept(taskStatusUpdateEvent); } catch (IOException e) { log.error("Cannot deserialize TaskStatusUpdateEvent.", e); } }; client.onStringMessage(responseConsumer); client.onClose(closeReason -> { }); commandContext = formatCommandContext(commandContext); try { client.connect(stripEndingSlash(webSocketBaseUrl) + Client.WEB_SOCKET_LISTENER_PATH + commandContext); } catch (Exception e) { throw new AssertionError("Failed to connect to remote client.", e); } return client; }
From source file:org.nuxeo.ecm.directory.DirectoryCSVLoader.java
/** * Loads the CSV data file based on the provided schema, and creates the corresponding entries using the provided * loader.//from w w w . j a v a2s . co m * * @param dataFileName the file name containing CSV data * @param delimiter the CSV column separator * @param schema the data schema * @param loader the actual consumer of loaded rows * @since 8.4 */ public static void loadData(String dataFileName, char delimiter, Schema schema, Consumer<Map<String, Object>> loader) throws DirectoryException { try (InputStream in = getResource(dataFileName); // CSVParser csvParser = new CSVParser(new InputStreamReader(in, "UTF-8"), CSVFormat.DEFAULT.withDelimiter(delimiter).withHeader())) { Map<String, Integer> header = csvParser.getHeaderMap(); List<Field> fields = new ArrayList<>(); for (String columnName : header.keySet()) { Field field = schema.getField(columnName.trim()); if (field == null) { throw new DirectoryException( "Column not found: " + columnName + " in schema: " + schema.getName()); } fields.add(field); } int lineno = 1; // header was first line for (CSVRecord record : csvParser) { lineno++; if (record.size() == 0 || record.size() == 1 && StringUtils.isBlank(record.get(0))) { // NXP-2538: allow columns with only one value but skip empty lines continue; } if (!record.isConsistent()) { log.error("Invalid column count while reading CSV file: " + dataFileName + ", line: " + lineno + ", values: " + record); continue; } Map<String, Object> map = new HashMap<String, Object>(); for (int i = 0; i < header.size(); i++) { Field field = fields.get(i); String value = record.get(i); Object v = CSV_NULL_MARKER.equals(value) ? null : decode(field, value); map.put(field.getName().getPrefixedName(), v); } loader.accept(map); } } catch (IOException e) { throw new DirectoryException("Read error while reading data file: " + dataFileName, e); } }
From source file:cz.lbenda.dataman.db.sql.SQLEditorController.java
@SuppressWarnings("unchecked") public SQLEditorController(Consumer<Object> menuItemConsumer, Scene scene, ObjectProperty<DbConfig> dbConfigProperty, NodeShower nodeShower) { node.setMaxHeight(Double.MAX_VALUE); node.setMaxHeight(Double.MAX_VALUE); this.nodeShower = nodeShower; textEditor.setScene(scene);//from w w w . j a v a 2 s . co m textEditor.changeHighlighter(new HighlighterSQL()); nodeShower.addNode(webView, msgConsoleTitle, false); CodeArea ca = textEditor.createCodeArea(); ca.setMaxHeight(Double.MAX_VALUE); ca.setMaxWidth(Double.MAX_VALUE); AnchorPane.setTopAnchor(ca, 0.0); AnchorPane.setBottomAnchor(ca, 0.0); AnchorPane.setLeftAnchor(ca, 0.0); AnchorPane.setRightAnchor(ca, 0.0); node.getChildren().add(ca); menuItemConsumer .accept(new SQLRunHandler(dbConfigProperty, this, handler -> nodeShower.focusNode(webView))); menuItemConsumer .accept(new SQLRunAllHandler(dbConfigProperty, this, handler -> nodeShower.focusNode(webView))); menuItemConsumer.accept(new OpenFileHandler(this)); menuItemConsumer.accept(new SaveFileHandler(this)); menuItemConsumer.accept(new SaveAsFileHandler(this)); menuItemConsumer.accept(new StopOnFirstErrorOptions(stopOnFirstError)); }
From source file:de.fosd.jdime.artifact.Artifact.java
/** * Applies the given {@code action} to the children of this {@link Artifact} and invalidates the tree hash as * necessary./*from w ww. j a va 2 s . c o m*/ * * @param action * the action to apply to the list of {@link #children} */ protected void modifyChildren(Consumer<List<T>> action) { int hashBefore = children.hashCode(); action.accept(children); if (children.hashCode() != hashBefore) { invalidateHash(); } }