List of usage examples for java.util.function BiConsumer accept
void accept(T t, U u);
From source file:org.diorite.impl.world.chunk.ChunkManagerImpl.java
public void loadChunkAsync(final int x, final int z, final boolean generate, final BiConsumer<ChunkImpl, Boolean> onEnd) { final ChunkImpl chunk = this.getChunk(x, z); if (chunk.isLoaded()) { onEnd.accept(chunk, false); return;//from w ww. ja v a 2 s. c o m } final ChunkLoadRequest chunkLoadRequest = new ChunkLoadRequest(ChunkIOService.INSTANT_PRIORITY, chunk, x, z); chunkLoadRequest.addOnEnd(r -> { ChunkImpl loadedChunk = r.get(); if (generate && (loadedChunk == null)) { this.core.sync(() -> { final ChunkGenerateEvent genEvt = new ChunkGenerateEvent(chunk); EventType.callEvent(genEvt); }); loadedChunk = chunk; } else if (loadedChunk == null) { loadedChunk = chunk; } onEnd.accept(loadedChunk, true); }); this.service.queue(chunkLoadRequest); }
From source file:org.exist.launcher.Launcher.java
protected static void run(List<String> args, BiConsumer<Integer, String> consumer) { final ProcessBuilder pb = new ProcessBuilder(args); final Optional<Path> home = ConfigurationHelper.getExistHome(); if (home.isPresent()) { pb.directory(home.get().toFile()); }//from ww w .j a v a2 s. co m pb.redirectErrorStream(true); try { final Process process = pb.start(); if (consumer != null) { final StringBuilder output = new StringBuilder(); try (final BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream(), "UTF-8"))) { String line; while ((line = reader.readLine()) != null) { output.append('\n').append(line); } } final int exitValue = process.waitFor(); consumer.accept(exitValue, output.toString()); } } catch (IOException | InterruptedException e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Error Running Process", JOptionPane.ERROR_MESSAGE); } }
From source file:org.exist.launcher.ServiceManager.java
private void runWrapperCmd(final String cmd, final BiConsumer<Integer, String> consumer) { final Path executable = wrapperDir.resolve("bin/" + getShellCmd(cmd)); final List<String> args = new ArrayList<>(1); args.add(executable.toString());//from w w w. jav a2s . c o m run(args, (code, output) -> { if (LOG.isDebugEnabled()) { LOG.debug(output); } consumer.accept(code, output); }); }
From source file:org.exist.launcher.ServiceManager.java
static void run(List<String> args, BiConsumer<Integer, String> consumer) { final ProcessBuilder pb = new ProcessBuilder(args); final Optional<Path> home = ConfigurationHelper.getExistHome(); pb.directory(home.orElse(Paths.get(".")).toFile()); pb.redirectErrorStream(true);/* w w w . ja va2 s.c o m*/ if (consumer == null) { pb.inheritIO(); } try { final Process process = pb.start(); if (consumer != null) { final StringBuilder output = new StringBuilder(); try (final BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream(), "UTF-8"))) { String line; while ((line = reader.readLine()) != null) { output.append('\n').append(line); } } final int exitValue = process.waitFor(); consumer.accept(exitValue, output.toString()); } } catch (IOException | InterruptedException e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Error Running Process", JOptionPane.ERROR_MESSAGE); } }
From source file:org.hawkular.inventory.impl.tinkerpop.sql.SqlGraphProvider.java
@Override public void ensureIndices(TransactionalGraph graph, IndexSpec... indexSpecs) { try {/*w w w .ja v a 2 s . c o m*/ SqlGraph sqlg = (SqlGraph) graph; sqlg.createSchemaIfNeeded(); Set<String> vertexIndices = sqlg.getIndexedKeys(Vertex.class); Set<String> edgeIndices = sqlg.getIndexedKeys(Edge.class); ArrayList<IndexSpec> specs = new ArrayList<>(Arrays.asList(indexSpecs)); BiConsumer<IndexSpec, Consumer<IndexSpec.Property>> indexChecker = (is, indexMutator) -> { IndexSpec.Property prop = is.getProperties().iterator().next(); if (!prop.isUnique()) { return; } Set<String> indices = is.getElementType().equals(Edge.class) ? edgeIndices : vertexIndices; if (indices.contains(prop.getName())) { return; } indexMutator.accept(prop); }; Iterator<IndexSpec> it = specs.iterator(); while (it.hasNext()) { IndexSpec is = it.next(); if (is.getProperties().stream().filter(IndexSpec.Property::isUnique).count() > 1) { throw new IllegalArgumentException( "SQL Graph doesn't support unique indices over multiple " + "properties"); } it.remove(); indexChecker.accept(is, prop -> sqlg.createKeyIndex(prop.getName(), is.getElementType(), (Parameter[]) null)); } //now remove those that are defined but no longer needed specs.forEach( is -> indexChecker.accept(is, prop -> sqlg.dropKeyIndex(prop.getName(), is.getElementType()))); sqlg.commit(); } catch (SQLException | IOException e) { throw new IllegalStateException("Could not create the database schema and indices.", e); } }
From source file:org.jboss.set.aphrodite.issue.trackers.jira.IssueWrapper.java
private void setIssueUser(BiConsumer<Issue, com.atlassian.jira.rest.client.api.domain.User> function, Issue issue, com.atlassian.jira.rest.client.api.domain.User user) { if (user != null && user.getName() != null && user.getEmailAddress() != null) function.accept(issue, user); }
From source file:org.jsweet.input.typescriptdef.ast.Scanner.java
private void applyToSuperMethod(TypeDeclaration declaringType, FunctionDeclaration childFunction, TypeDeclaration parentType, BiConsumer<TypeDeclaration, FunctionDeclaration> apply) { int index = -1; if (declaringType != parentType) { index = ArrayUtils.indexOf(parentType.getMembers(), childFunction); }//from ww w . j a va 2 s . c om if (index != -1) { apply.accept(parentType, (FunctionDeclaration) parentType.getMembers()[index]); } else { if (parentType.getSuperTypes() != null && parentType.getSuperTypes().length > 0) { for (TypeReference ref : parentType.getSuperTypes()) { Type decl = lookupType(ref, null); if (decl instanceof TypeDeclaration) { applyToSuperMethod(declaringType, childFunction, (TypeDeclaration) decl, apply); } } } else if (!JSweetDefTranslatorConfig.getObjectClassName().equals(context.getTypeName(parentType))) { TypeDeclaration decl = context.getTypeDeclaration(JSweetDefTranslatorConfig.getObjectClassName()); if (decl != null) { applyToSuperMethod(declaringType, childFunction, (TypeDeclaration) decl, apply); } } } }
From source file:org.jsweet.input.typescriptdef.TypescriptDef2Java.java
private static void scan(BiConsumer<CompilationUnit, Scanner> onScannedCallback, List<CompilationUnit> compilationUnits, Scanner... scanners) { for (Scanner scanner : scanners) { scanner.onScanStart();/*from www. j a v a 2s .c om*/ } for (CompilationUnit compilationUnit : compilationUnits) { for (Scanner scanner : scanners) { scan(compilationUnit, scanner); if (onScannedCallback != null) { onScannedCallback.accept(compilationUnit, scanner); } } } for (Scanner scanner : scanners) { scanner.onScanEnded(); } }
From source file:org.jsweet.test.transpiler.AbstractTest.java
protected void eval(ModuleKind moduleKind, boolean testBundle, BiConsumer<TestTranspilationHandler, EvaluationResult> assertions, SourceFile... files) { ModuleKind initialModuleKind = transpiler.getModuleKind(); File initialOutputDir = transpiler.getTsOutputDir(); try {//from w ww . jav a 2s . c o m logger.info( "*** module kind: " + moduleKind + (transpiler.isBundle() ? " (with bundle)" : "") + " ***"); TestTranspilationHandler logHandler = new TestTranspilationHandler(); EvaluationResult res = null; transpiler.setModuleKind(moduleKind); // touch will force the transpilation even if the files were // already // transpiled SourceFile.touch(files); initOutputDir(); res = transpiler.eval(logHandler, files); if (assertions != null) { assertions.accept(logHandler, res); } } catch (Exception e) { e.printStackTrace(); fail("exception occured while running test " + getCurrentTestName() + " with module kind " + moduleKind); } finally { transpiler.setModuleKind(initialModuleKind); transpiler.setTsOutputDir(initialOutputDir); } if (testBundle && moduleKind == ModuleKind.none && !transpiler.isBundle() && files.length > 1) { ArrayUtils.reverse(files); transpiler.setBundle(true); try { eval(moduleKind, assertions, files); } finally { transpiler.setBundle(false); ArrayUtils.reverse(files); } } }
From source file:org.keycloak.testsuite.adapter.AbstractSAMLAdapterClusteredTest.java
private void testLogoutViaSessionIndex(URL employeeUrl, boolean forceRefreshAtOtherNode, BiConsumer<SamlClientBuilder, String> logoutFunction) { setPasswordFor(bburkeUser, CredentialRepresentation.PASSWORD); final String employeeUrlString; try {// w w w. j a v a 2s . com URL employeeUrlAtRevProxy = new URL(employeeUrl.getProtocol(), employeeUrl.getHost(), HTTP_PORT_NODE_REVPROXY, employeeUrl.getFile()); employeeUrlString = employeeUrlAtRevProxy.toString(); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } SamlClientBuilder builder = new SamlClientBuilder() // Go to employee URL at reverse proxy which is set to forward to first node .navigateTo(employeeUrlString) // process redirection to login page .processSamlResponse(Binding.POST).build().login().user(bburkeUser).build() .processSamlResponse(Binding.POST).build() // Returned to the page .assertResponse(Matchers.bodyHC(containsString("principal=bburke"))) // Update the proxy to forward to the second node. .addStep(() -> updateProxy(NODE_2_NAME, NODE_2_URI, NODE_1_URI)); if (forceRefreshAtOtherNode) { // Go to employee URL at reverse proxy which is set to forward to _second_ node now builder.navigateTo(employeeUrlString).doNotFollowRedirects() .assertResponse(Matchers.bodyHC(containsString("principal=bburke"))); } // Logout at the _second_ node logoutFunction.accept(builder, employeeUrlString); SamlClient samlClient = builder.execute(); delayedCheckLoggedOut(samlClient, employeeUrlString); // Update the proxy to forward to the first node. updateProxy(NODE_1_NAME, NODE_1_URI, NODE_2_URI); delayedCheckLoggedOut(samlClient, employeeUrlString); }