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:ee.ria.xroad.opmonitordaemon.HealthDataRequestHandler.java

@Override
public void handle(SoapMessageImpl requestSoap, OutputStream out, Consumer<String> contentTypeCallback)
        throws Exception {
    log.trace("handle()");

    ClientId clientId = requestSoap.getClient();
    GetSecurityServerHealthDataType requestData = getRequestData(requestSoap,
            GetSecurityServerHealthDataType.class);

    Optional<ClientId> provider = Optional.ofNullable(requestData.getFilterCriteria())
            .map(FilterCriteriaType::getClient);

    log.debug("Handle getSecurityServerHealthData: clientId: {}, " + "filterCriteria.client: {}", clientId,
            provider.orElse(null));//  w  ww.  j a  va2s .com

    SoapMessageImpl response = createResponse(requestSoap, buildHealthDataResponse(provider));

    contentTypeCallback.accept(response.getContentType());
    out.write(response.getBytes());
}

From source file:com.diversityarrays.kdxplore.curate.CurationTableModel.java

public void addTraitInstance(TraitInstance ti) {
    int count = valueRetrievers.size();
    addTraitInstanceImpl(ti, true);//  www.ja v a 2s.c  o m
    int newCount = valueRetrievers.size();
    if (newCount != count) {
        propertyChangeSupport.firePropertyChange(PROPERTY_TRAIT_INSTANCES, count, newCount);
    }

    for (Consumer<Void> consumer : traitChangeListeners) {
        consumer.accept(null);
    }
}

From source file:com.epam.catgenome.manager.bam.BamManagerTest.java

private void assertTrackLoading(BamFile bamFile, Consumer<BamQueryOption> optionsSetter,
        Consumer<BamTrack<Read>> trackAsserter) throws IOException {
    Track<Read> fullTrackQ = getBaseReadTrack(bamFile);

    BamQueryOption option = getBaseBamQueryOption();

    optionsSetter.accept(option);

    ResponseEmitterMock emitterMock = new ResponseEmitterMock();
    bamManager.sendBamTrackToEmitter(fullTrackQ, option, emitterMock);
    BamTrack<Read> fullTrack = emitterMock.getBamTrack();

    trackAsserter.accept(fullTrack);//from w ww  . j a  v  a  2  s.c om
}

From source file:org.apache.openmeetings.web.room.wb.WbPanel.java

private JSONObject addFileUrl(Client cl, String ruid, JSONObject _file, Consumer<BaseFileItem> consumer) {
    try {/*from   w w  w  . j  a  v a 2s. c o m*/
        final long fid = _file.optLong(ATTR_FILE_ID, -1);
        if (fid > 0) {
            BaseFileItem fi = fileDao.getAny(fid);
            if (fi != null) {
                if (consumer != null) {
                    consumer.accept(fi);
                }
                return WbWebSocketHelper.addFileUrl(ruid, _file, fi, cl);
            }
        }
    } catch (Exception e) {
        //no-op, non-file object
    }
    return _file;
}

From source file:com.spotify.heroic.metadata.elasticsearch.MetadataBackendKV.java

private <T, O> AsyncObservable<O> entriesStream(final OptionalLimit limit, final Filter f,
        final DateRange range, final Function<SearchHit, T> converter, final Function<Set<T>, O> collector,
        final Consumer<SearchRequestBuilder> modifier) {
    final QueryBuilder filter = filter(f);

    return observer -> connection.doto(c -> {
        final SearchRequestBuilder builder = c.search(TYPE_METADATA).setScroll(SCROLL_TIME);

        builder.setSize(limit.asMaxInteger(SCROLL_SIZE));
        builder.setQuery(new BoolQueryBuilder().must(filter));

        modifier.accept(builder);

        final ScrollTransformStream<T> scrollTransform = new ScrollTransformStream<>(limit,
                set -> observer.observe(collector.apply(set)), converter, scrollId -> {
                    // Function<> that returns a Supplier
                    return () -> {
                        final ListenableActionFuture<SearchResponse> execute = c.prepareSearchScroll(scrollId)
                                .setScroll(SCROLL_TIME).execute();
                        return bind(execute);
                    };/*from w  w w.j  a  v a  2s.  c o m*/
                });

        return bind(builder.execute()).lazyTransform(scrollTransform);
    }).onDone(observer.onDone());
}

From source file:org.opencb.opencga.catalog.db.mongodb.ProjectMongoDBAdaptor.java

@Override
public void forEach(Query query, Consumer<? super Object> action, QueryOptions options)
        throws CatalogDBException {
    Objects.requireNonNull(action);
    DBIterator<Project> catalogDBIterator = iterator(query, options);
    while (catalogDBIterator.hasNext()) {
        action.accept(catalogDBIterator.next());
    }/*from  w ww. j  a  va  2  s .  c  om*/
    catalogDBIterator.close();
}

From source file:org.eclipse.hono.client.impl.HonoClientImpl.java

/**
 * {@inheritDoc}//  w ww.j av  a 2  s . co  m
 */
@Override
public final Future<MessageConsumer> createEventConsumer(final String tenantId,
        final Consumer<Message> eventConsumer, final Handler<Void> closeHandler) {

    return createEventConsumer(tenantId, (delivery, message) -> eventConsumer.accept(message), closeHandler);
}

From source file:com.haulmont.cuba.core.jmx.PersistenceManager.java

@Authenticated
@Override//from  w w  w.  j  a  v a  2  s  . co m
public String refreshStatistics(String entityName) {
    if (StringUtils.isBlank(entityName))
        return "Pass an entity name (MetaClass name, e.g. sec$User) or 'all' to refresh statistics for all entities.\n"
                + "Be careful, it can take very long time.";

    try {
        log.info("Refreshing statistics for " + entityName);

        Consumer<MetaClass> refreshStatisticsForEntity = mc -> {
            MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalOrThisMetaClass(mc);
            Class javaClass = originalMetaClass.getJavaClass();
            Table annotation = (Table) javaClass.getAnnotation(Table.class);
            if (annotation != null) {
                persistenceManager.refreshStatisticsForEntity(originalMetaClass.getName());
            }
        };

        if ("all".equals(entityName)) {
            for (MetaClass metaClass : metadata.getSession().getClasses()) {
                refreshStatisticsForEntity.accept(metaClass);
            }
        } else {
            MetaClass metaClass = metadata.getSession().getClass(entityName);
            if (metaClass == null)
                return "MetaClass not found: " + entityName;
            refreshStatisticsForEntity.accept(metaClass);
        }
        return "Done";
    } catch (Exception e) {
        log.error("refreshStatistics error", e);
        return ExceptionUtils.getStackTrace(e);
    }
}

From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java

private TextField createIntegerInputField(final TextField textInput, final Supplier<Integer> getter,
        final Consumer<Integer> setter) {
    final TextField integerInput = new TextField(getter.get() == null ? "" : String.valueOf(getter.get()));
    integerInput.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
        if (!newValue.matches("\\d*")) {
            integerInput.setText(newValue.replaceAll("[^\\d]", ""));
            newValue = textInput.getText();
        }/*from ww  w. j a  va 2  s .c  o  m*/
        if (StringUtils.isNotBlank(newValue)) {
            try {
                setter.accept(Integer.parseInt(newValue));
            } catch (final NumberFormatException nfe) {
                // This can only happen if the value is "too long" / too high for "int"
                integerInput.setText(String.valueOf(Integer.MAX_VALUE));
                setter.accept(Integer.MAX_VALUE);
            }
        } else {
            setter.accept(null);
        }
        this.setChanged(true);
    });
    final double maxWidthOfIntegerInput = 80d;
    integerInput.setMaxWidth(maxWidthOfIntegerInput);
    return integerInput;
}

From source file:com.bekwam.resignator.commands.SignCommand.java

public void signJAR(Path jarFilePath, Path keystore, String storepass, String alias, String keypass,
        Consumer<String> observer) throws CommandExecutionException {

    if (StringUtils.isEmpty(storepass)) {
        throw new CommandExecutionException("storepass is required");
    }/*from w w w  .j  av a 2  s . c  o m*/

    if (StringUtils.isEmpty(keypass)) {
        throw new CommandExecutionException("keypass is required");
    }

    if (StringUtils.isEmpty(alias)) {
        throw new CommandExecutionException("alias is required");
    }

    if (keystore == null) {
        throw new CommandExecutionException("keystore is required");
    }

    if (jarFilePath == null) {
        throw new CommandExecutionException("jarFilePath is required");
    }

    if (!jarFilePath.toFile().exists()) {
        throw new CommandExecutionException(String.format("jar file %s not found", jarFilePath.toString()));
    }

    Preconditions.checkNotNull(activeConfiguration.getJarsignerCommand());

    observer.accept("Running jarsigner command on '" + jarFilePath.toString() + "'");

    String[] cmdAndArgs = { activeConfiguration.getJarsignerCommand().toString(), "-keystore",
            keystore.toString(), "-storepass", storepass, "-keypass", keypass, "-tsa",
            "http://timestamp.digicert.com", jarFilePath.toString(), alias };

    CommandExecutor cmd = new CommandExecutor();
    cmd.exec(cmdAndArgs);

    observer.accept("Finished");
}