Example usage for java.util Optional ofNullable

List of usage examples for java.util Optional ofNullable

Introduction

In this page you can find the example usage for java.util Optional ofNullable.

Prototype

@SuppressWarnings("unchecked")
public static <T> Optional<T> ofNullable(T value) 

Source Link

Document

Returns an Optional describing the given value, if non- null , otherwise returns an empty Optional .

Usage

From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalSummaryRepositoryImpl.java

@Override
public Optional<EnzymePortalSummary> findDiseaseEvidence(String accession) {
    EntityGraph eGraph = entityManager.getEntityGraph("summary.graph");
    JPAQuery query = new JPAQuery(entityManager);
    query.setHint("javax.persistence.fetchgraph", eGraph);
    String commentType = "DISEASE";
    EnzymePortalSummary summary = query.from($).where($.commentType.equalsIgnoreCase(commentType)
            .and($.uniprotAccession.accession.equalsIgnoreCase(accession))).singleResult($);

    return Optional.ofNullable(summary);
}

From source file:org.openmhealth.shimmer.common.configuration.DefaultEndpointSettings.java

@Override
public Optional<DateTimeQuerySettings> getCreationDateTimeQuerySettings() {
    return Optional.ofNullable(creationDateTimeQuerySettings);
}

From source file:alfio.manager.system.MockMailer.java

@Override
public void send(Event event, String to, String subject, String text, Optional<String> html,
        Attachment... attachments) {/*from w ww.  j av  a2  s . c  om*/

    String printedAttachments = Optional.ofNullable(attachments).map(Arrays::asList)
            .orElse(Collections.emptyList()).stream()
            .map(a -> "{filename:" + a.getFilename() + ", contentType: " + a.getContentType() + "}")
            .collect(Collectors.joining(", "));

    log.info("Email: from: {}, replyTo: {}, to: {}, subject: {}, text: {}, html: {}, attachments: {}",
            event.getDisplayName(),
            configurationManager.getStringConfigValue(
                    Configuration.from(event.getOrganizationId(), event.getId(), MAIL_REPLY_TO), ""),
            to, subject, text, html.orElse("no html"), printedAttachments);
}

From source file:com.github.dmyersturnbull.transformations.ExtendedCommandLine.java

@Nonnull
public Optional<String> get(@Nonnull String opt) {
    return Optional.ofNullable(m_commandLine.getOptionValue(opt));
}

From source file:org.homiefund.web.controllers.DashboardController.java

private String dashBoardNested(Integer page, Model model) {
    PaginatedRequest<TransactionPreviewDTO> request = new PaginatedRequest<>();
    Page p = new Page();
    p.setPage(Optional.ofNullable(page).orElse(1));

    request.setPage(p);/*from   w  ww.  j a v  a2 s . c o  m*/
    model.addAttribute("transactionResponse", transactionService.getTransactions(request));
    return "dashboard";
}

From source file:com.github.wxiaoqi.gate.ratelimit.config.properties.RateLimitProperties.java

public Optional<Policy> getPolicy(String key) {
    return Optional.ofNullable(policies.getOrDefault(key, defaultPolicy));
}

From source file:org.obiba.mica.micaConfig.service.EntityConfigService.java

public Optional<T> findComplete() {

    T form = findOrCreateDefaultForm();
    form = mergedRepositoryAndMandatoryConfiguration(form);

    return Optional.ofNullable(form);
}

From source file:io.apiman.common.es.util.ApimanEmbeddedElastic.java

public static String getEsBuildVersion() {
    URL url = ApimanEmbeddedElastic.class.getResource("apiman-embedded-elastic.properties");
    if (url == null) {
        throw new RuntimeException("embedded-elastic.properties missing.");
    } else {//from w  w  w .  j  ava 2 s  .c  o  m
        Properties allProperties = new Properties();
        try (InputStream is = url.openStream()) {
            allProperties.load(is);
            return Optional.ofNullable(allProperties.getProperty("apiman.embedded-es-version"))
                    .orElseThrow(() -> new RuntimeException("apiman.embedded-es-version"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.versioning.JcrEntityVersion.java

public JcrEntityVersion(Version version, E entity) {
    if (version != null) {
        this.version = version;
        this.id = new VersionId(JcrPropertyUtil.getIdentifier(JcrUtil.getNode(version, "jcr:frozenNode")));
        //        this.id = new VersionId(JcrPropertyUtil.getIdentifier(version));
    }//from   w  ww  . j a  va  2  s .  co m
    this.entity = Optional.ofNullable(entity);
}

From source file:com.github.yongchristophertang.engine.web.http.MultipartBodyFormBuilder.java

/**
 * Add a request parameter to body in {@link HttpRequestBuilders}
 *
 * @param name  parameter name//from   www.j  a  v  a  2s  . c om
 * @param value parameter value
 * @return {@link MultipartBodyFormBuilder}
 */
public MultipartBodyFormBuilder param(String name, String value) {
    AssertUtils.notNull(name, "Parameter name must not be null.");
    Optional.ofNullable(value).ifPresent(v -> builder.addTextBody(name, v, ContentType.TEXT_PLAIN));
    return this;
}