Example usage for java.util.function Consumer accept

List of usage examples for java.util.function Consumer accept

Introduction

In this page you can find the example usage for java.util.function Consumer accept.

Prototype

void accept(T t);

Source Link

Document

Performs this operation on the given argument.

Usage

From source file:io.github.jeddict.jcode.parser.ejs.EJSUtil.java

public static void copyDynamicFile(Consumer<FileTypeStream> parserManager, String inputResource,
        FileObject webRoot, String targetFile, ProgressHandler handler) throws IOException {
    try {//w ww .  j a  v  a2s  .c om
        handler.progress(targetFile);
        FileObject target = org.openide.filesystems.FileUtil.createData(webRoot, targetFile);
        FileLock lock = target.lock();
        try {
            InputStream inputStream = loadResource(inputResource);
            OutputStream outputStream = target.getOutputStream(lock);
            parserManager.accept(new FileTypeStream(inputResource, inputStream, outputStream));
        } finally {
            lock.releaseLock();
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.keycloak.testsuite.adapter.AbstractExampleAdapterTest.java

protected static WebArchive exampleDeployment(String name, String contextPath,
        Consumer<WebArchive> additionalResources) throws IOException {
    URL webXML = Paths.get(EXAMPLES_WEB_XML).toUri().toURL();
    String webXmlContent = IOUtils.toString(webXML.openStream(), "UTF-8").replace("%CONTEXT_PATH%",
            contextPath);/*  w  ww.  j  a v a  2 s  .  c  o m*/
    WebArchive webArchive = ShrinkWrap.create(ZipImporter.class, name + ".war")
            .importFrom(new File(EXAMPLES_HOME + "/" + name + "-" + EXAMPLES_VERSION_SUFFIX + ".war"))
            .as(WebArchive.class).addAsWebInfResource(jbossDeploymentStructure, JBOSS_DEPLOYMENT_STRUCTURE_XML)
            .add(new StringAsset(webXmlContent), "/WEB-INF/web.xml");

    additionalResources.accept(webArchive);

    modifyOIDCAdapterConfig(webArchive);

    return webArchive;
}

From source file:com.puppycrawl.tools.checkstyle.JavadocPropertiesGenerator.java

/**
 * Walks over the type members and push the first javadoc sentence of every
 * {@code public} {@code static} {@code int} field to the consumer.
 * @param objBlock the OBJBLOCK of a class to iterate over its members
 * @param consumer first javadoc sentence consumer
 * @throws CheckstyleException if failed to parse a javadoc comment
 *//* w w w  . j ava2  s  . co  m*/
private static void iteratePublicStaticIntFields(DetailAST objBlock, Consumer<String> consumer)
        throws CheckstyleException {
    for (DetailAST member = objBlock.getFirstChild(); member != null; member = member.getNextSibling()) {
        if (isPublicStaticFinalIntField(member)) {
            final DetailAST modifiers = member.findFirstToken(TokenTypes.MODIFIERS);
            final String firstJavadocSentence = getFirstJavadocSentence(modifiers);
            if (firstJavadocSentence != null) {
                consumer.accept(getName(member) + "=" + firstJavadocSentence.trim());
            }
        }
    }
}

From source file:org.commonjava.indy.bind.jaxrs.util.ResponseUtils.java

public static Response formatOkResponseWithJsonEntity(final Object dto, final ObjectMapper objectMapper,
        final Consumer<ResponseBuilder> builderModifier) {
    if (dto == null) {
        return Response.noContent().build();
    }//from ww w  . j  a v a  2s .c  o m

    try {
        ResponseBuilder builder = Response.ok(objectMapper.writeValueAsString(dto),
                ApplicationContent.application_json);

        if (builderModifier != null) {
            builderModifier.accept(builder);
        }

        return builder.build();
    } catch (final JsonProcessingException e) {
        return formatResponse(e, "Failed to serialize DTO to JSON: " + dto, builderModifier);
    }
}

From source file:com.evolveum.midpoint.schema.SelectorOptions.java

public static <T> Collection<SelectorOptions<T>> set(Collection<SelectorOptions<T>> options, ItemPath path,
        Supplier<T> constructor, Consumer<T> setter) {
    if (options == null) {
        options = new ArrayList<>();
    }//from  w  w w.j a  v  a  2  s. co  m
    Collection<T> optionsForPath = findOptionsForPath(options, path);
    T option;
    if (optionsForPath.isEmpty()) {
        option = constructor.get();
        options.add(SelectorOptions.create(path, option));
    } else {
        option = optionsForPath.iterator().next();
    }
    setter.accept(option);
    return options;
}

From source file:de.ks.text.AsciiDocEditor.java

public static CompletableFuture<DefaultLoader<Node, AsciiDocEditor>> load(Consumer<StackPane> viewConsumer,
        Consumer<AsciiDocEditor> controllerConsumer) {
    ActivityInitialization initialization = CDI.current().select(ActivityInitialization.class).get();
    return initialization.loadAdditionalControllerWithFuture(AsciiDocEditor.class)//
            .thenApply(loader -> {/*w ww  .  j  ava  2  s.c  o  m*/
                viewConsumer.accept((StackPane) loader.getView());
                controllerConsumer.accept(loader.getController());
                return loader;
            });
}

From source file:com.kellerkindt.scs.utilities.Utilities.java

/**
 *
 * @param player {@link Player} to get the {@link ItemStack} for
 * @param arg Either {@link #ITEM_NAME_ITEM_IN_HAND} indicating to return the current item in hand / on cursor,
 *            or {@link #ITEM_NAME_ITEM_LATER} to return the item in hand / on cursor later on, or a valid item name
 * @param consumer {@link Consumer} that is going to receive the {@link ItemStack} that has been identified
 * @param runLaterConsumer {@link Consumer} to register a {@link RunLater} instance which will only be needed for {@link #ITEM_NAME_ITEM_LATER}
 * @throws MissingOrIncorrectArgumentException
 *//*from  w w w . j a  v a  2s  . com*/
public static void getItemStack(Player player, String arg, Consumer<ItemStack> consumer,
        Consumer<TriggerableRunLater> runLaterConsumer) throws MissingOrIncorrectArgumentException {
    // replace bukkits ItemStack with the generic one, this will get rid of various errors later on
    TriggerableRunLater runLater = new TriggerableRunLater() {
        @Override
        public void trigger() {
            consumer.accept(new ItemStack(player.getItemOnCursor()));
        }

        @Override
        public void abort(Player player) {
            // nothing to do
        }
    };

    if (ITEM_NAME_ITEM_LATER.equalsIgnoreCase(arg)) {
        // trigger later
        runLaterConsumer.accept(runLater);

    } else if (ITEM_NAME_ITEM_IN_HAND.equalsIgnoreCase(arg)) {
        // trigger now
        runLater.trigger();
    }

    else {
        try {
            // try to parse the string
            consumer.accept(Utilities.getItemStackFromString(arg.toUpperCase()));
        } catch (Exception e) {
            throw new MissingOrIncorrectArgumentException();
        }
    }
}

From source file:com.evolveum.midpoint.schema.util.PolicyRuleTypeUtil.java

public static void visit(List<EvaluatedPolicyRuleTriggerType> triggers,
        Consumer<EvaluatedPolicyRuleTriggerType> visitor) {
    for (EvaluatedPolicyRuleTriggerType trigger : triggers) {
        visitor.accept(trigger);
        if (trigger instanceof EvaluatedSituationTriggerType) {
            EvaluatedSituationTriggerType situationTrigger = (EvaluatedSituationTriggerType) trigger;
            for (EvaluatedPolicyRuleType sourceRule : situationTrigger.getSourceRule()) {
                visit(sourceRule.getTrigger(), visitor);
            }//from  w  ww  . j a v a2  s .c om
        }
    }
}

From source file:cz.lbenda.gui.controls.TextAreaFrmController.java

/** Create button which can open text editor */
public static Button createOpenButton(String windowTitle, @Nonnull Supplier<String> oldValueSupplier,
        @Nonnull Consumer<String> newValueConsumer) {
    String title = windowTitle == null ? msgDefaultWindowTitle : windowTitle;
    Button result = new Button(null, new ImageView(BUTTON_IMAGE));
    result.setTooltip(new Tooltip(msgBtnOpenInEditor_tooltip));
    BorderPane.setAlignment(result, Pos.TOP_RIGHT);
    result.setOnAction(event -> {/*w w w . j  av a  2 s.c  o  m*/
        Tuple2<Parent, TextAreaFrmController> tuple2 = TextAreaFrmController.createNewInstance();
        tuple2.get2().textProperty().setValue(oldValueSupplier.get());
        tuple2.get2().textProperty()
                .addListener((observable, oldValue, newValue) -> newValueConsumer.accept(newValue));
        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        DialogHelper.getInstance().openWindowInCenterOfStage(stage, tuple2.get2().getMainPane(), title);
    });
    return result;
}

From source file:org.opendaylight.controller.cluster.raft.AbstractRaftActorIntegrationTest.java

@SuppressWarnings("checkstyle:IllegalCatch")
static void verifyRaftState(final ActorRef raftActor, final Consumer<OnDemandRaftState> verifier) {
    Timeout timeout = new Timeout(500, TimeUnit.MILLISECONDS);
    AssertionError lastError = null;
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        try {/* w  w w .  j  a va  2  s  . c om*/
            OnDemandRaftState raftState = (OnDemandRaftState) Await
                    .result(ask(raftActor, GetOnDemandRaftState.INSTANCE, timeout), timeout.duration());
            verifier.accept(raftState);
            return;
        } catch (AssertionError e) {
            lastError = e;
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            lastError = new AssertionError("OnDemandRaftState failed", e);
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        }
    }

    throw lastError;
}