Example usage for java.util.function Supplier get

List of usage examples for java.util.function Supplier get

Introduction

In this page you can find the example usage for java.util.function Supplier get.

Prototype

T get();

Source Link

Document

Gets a result.

Usage

From source file:org.n52.iceland.convert.ConverterRepository.java

@SuppressWarnings("unchecked")
public <T, F> Converter<T, F> getConverter(final ConverterKey key) {
    Supplier<Converter<?, ?>> producer = converter.get(key);
    if (producer == null) {
        return null;
    }// w w  w . ja v a2s  . c o m
    return (Converter<T, F>) producer.get();
}

From source file:org.shredzone.cilla.view.MediaView.java

@Override
public String resolveLocalLink(String url, boolean image, Supplier<LinkBuilder> linkBuilderSupplier) {
    String[] parts = url.split("/", 2);

    if (image && parts.length == 1) {
        return linkBuilderSupplier.get().param("name", parts[0]).toString();

    } else if (image && parts.length == 2) {
        return linkBuilderSupplier.get().param("type", parts[0]).param("name", parts[1]).toString();

    } else if (!image && parts.length == 2) {
        if ("show".equals(parts[0])) {
            return linkBuilderSupplier.get().view("showPreview").param("name", parts[1]).toString();
        }//from ww  w.j  ava2  s. co  m
    }

    return null;
}

From source file:com.qwazr.search.bench.test.Merging.MergingTest.java

void addRecords(LuceneCommonIndex index, int count, Supplier<LuceneRecord.Indexable> recordSupplier)
        throws IOException {
    while (count-- > 0) {
        index.updateDocument(null, recordSupplier.get());
    }//  w w w  .  java 2 s .  c  o  m
}

From source file:ru.mera.samples.infrastructure.aop.AroundCacheValidationAdvice.java

protected Object getCachedObject(ProceedingJoinPoint pjp, String key, Supplier<Optional<ImageEntity>> suplier) {
    String funcName = pjp.getSignature().getName();
    logger.info("Around method: " + funcName);
    Optional<ImageEntity> image = suplier.get();
    ImageEntity bufferedImage = image.orElseGet(() -> {
        try {//from   ww w  . j a va 2s  . c o m
            logger.info("Around method: not found cached image " + key);
            return (ImageEntity) pjp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return null;
        }
    });
    return bufferedImage;
}

From source file:jp.gr.java_conf.kazsharp.lambda_logging.jcl.LambdaLog4jLog.java

private void logIfEnabled(Level level, Supplier<String> message) {
    if (logger.isEnabled(level)) {
        logger.logIfEnabled(FQCN, level, null, message.get());
    }/*from w ww  .  j  a v a2 s  . c  om*/
}

From source file:com.simiacryptus.mindseye.labs.encoding.FindPCAFeatures.java

/**
 * Find feature space tensor [ ].//w  w w.j  a v a2s. c o m
 *
 * @param log            the log
 * @param featureVectors the feature vectors
 * @param components     the components
 * @return the tensor [ ]
 */
protected Tensor[] findFeatureSpace(@Nonnull final NotebookOutput log,
        @Nonnull final Supplier<Stream<Tensor[]>> featureVectors, final int components) {
    return log.eval(() -> {
        final int column = 1;
        @Nonnull
        final Tensor[] prototype = featureVectors.get().findAny().get();
        @Nonnull
        final int[] dimensions = prototype[column].getDimensions();
        RealMatrix covariance = PCAUtil.getCovariance(() -> featureVectors.get().map(x -> x[column].getData()));
        return PCAUtil.pcaFeatures(covariance, components, dimensions, -1);
    });
}

From source file:jp.gr.java_conf.kazsharp.lambda_logging.jcl.LambdaLog4jLog.java

private void logIfEnabled(Level level, Supplier<String> message, Throwable t) {
    if (logger.isEnabled(level)) {
        logger.logIfEnabled(FQCN, level, null, message.get(), t);
    }//  w  w w.  j  a  v  a2  s . co  m
}

From source file:com.netflix.spinnaker.halyard.deploy.deployment.v1.OrcaRunner.java

private String getTaskEndpoint(Supplier<String> submitter) {
    return submitter.get().substring(1);
}

From source file:org.graylog2.indexer.cluster.jest.JestUtils.java

private static ElasticsearchException specificException(Supplier<String> errorMessage, JsonObject jsonObject) {
    final List<JsonObject> rootCauses = extractRootCauses(jsonObject);
    final List<String> reasons = extractReasons(rootCauses);

    for (JsonObject rootCause : rootCauses) {
        final String type = asString(rootCause.get("type"));
        if (type == null) {
            continue;
        }//from  ww w  . j  a  v  a  2s.  c o  m
        switch (type) {
        case "query_parsing_exception":
            return buildQueryParsingException(errorMessage, rootCause, reasons);
        case "index_not_found_exception":
            final String indexName = asString(rootCause.get("resource.id"));
            return buildIndexNotFoundException(errorMessage, indexName);
        case "illegal_argument_exception":
            final String reason = asString(rootCause.get("reason"));
            if (reason != null && reason.startsWith("Expected numeric type on field")) {
                return buildFieldTypeException(errorMessage, reason);
            }
            break;
        }
    }

    if (reasons.isEmpty()) {
        return new ElasticsearchException(errorMessage.get(), Collections.singletonList(jsonObject.toString()));
    }

    return new ElasticsearchException(errorMessage.get(), reasons);
}

From source file:nu.yona.server.DOSProtectionService.java

public <T> T executeAttempt(URI uri, HttpServletRequest request, int expectedAttempts, Supplier<T> attempt) {
    if (yonaProperties.getSecurity().isDosProtectionEnabled()) {
        int attempts = increaseAttempts(uri, request);
        delayIfBeyondExpectedAttempts(expectedAttempts, attempts);
    }//from  w  ww .ja va  2s .  c o  m

    return attempt.get();
}