Example usage for java.util Optional of

List of usage examples for java.util Optional of

Introduction

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

Prototype

public static <T> Optional<T> of(T value) 

Source Link

Document

Returns an Optional describing the given non- null value.

Usage

From source file:de.mas.wiiu.jnus.utils.FSTUtils.java

public static Optional<FSTEntry> getEntryByFullPath(FSTEntry root, String filePath) {
    for (FSTEntry cur : root.getFileChildren()) {
        if (cur.getFullPath().equals(filePath)) {
            return Optional.of(cur);
        }/*  w w  w.  j  av a  2s.c o  m*/
    }

    for (FSTEntry cur : root.getDirChildren()) {
        Optional<FSTEntry> res = getEntryByFullPath(cur, filePath);
        if (res.isPresent()) {
            return res;
        }
    }
    return Optional.empty();
}

From source file:org.openmhealth.shim.jawbone.mapper.JawboneSleepDurationDataPointMapper.java

@Override
protected Optional<SleepDuration> getMeasure(JsonNode listEntryNode) {

    Long totalSleepSessionDuration = asRequiredLong(listEntryNode, "details.duration");
    Long totalTimeAwake = asRequiredLong(listEntryNode, "details.awake");

    SleepDuration.Builder sleepDurationBuilder = new SleepDuration.Builder(
            new DurationUnitValue(DurationUnit.SECOND, totalSleepSessionDuration - totalTimeAwake));

    setEffectiveTimeFrame(sleepDurationBuilder, listEntryNode);

    SleepDuration sleepDuration = sleepDurationBuilder.build();
    asOptionalLong(listEntryNode, "details.awakenings")
            .ifPresent(wakeUpCount -> sleepDuration.setAdditionalProperty("wakeup_count", wakeUpCount));

    return Optional.of(sleepDuration);
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpringService.java

@Override
protected Optional<String> customProfileOutputPath(String profileName) {
    if (profileName.startsWith(getCanonicalName()) || profileName.startsWith("spinnaker")) {
        return Optional.of(OUTPUT_PATH + profileName);
    } else {//from w w w . j a  v a2s .  c o m
        return Optional.empty();
    }
}

From source file:org.trustedanalytics.metricsprovider.cloudadapter.api.CfSpace.java

@JsonIgnore
public UUID getOrgGuid() {
    Optional<CfSpace> space = Optional.of(this);
    return space.map(CfSpace::getEntity).map(CfSpaceEntity::getOrgGuid).orElse(null);
}

From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkClient.java

public static <T> Optional<T> fetch(HttpClient httpClient, ChunkServer.StorageHostChunkList chunkList,
        Function<ChunkServer.StorageHostChunkList, HttpUriRequest> chunkListRequestFactory,
        ResponseHandler<T> responseHandler) {

    try {/* w  w w .  j  a  v  a  2 s. c  om*/
        HttpUriRequest request = chunkListRequestFactory.apply(chunkList);
        T data = httpClient.execute(request, responseHandler);
        return Optional.of(data);

    } catch (IOException ex) {
        logger.warn("-- fetch() - IOException: {}", ex);
        return Optional.empty();
    }
}

From source file:com.github.robozonky.app.tenant.RefreshableStrategy.java

@Override
protected Optional<String> transform(final String source) {
    return Optional.of(source);
}

From source file:org.zalando.logbook.httpclient.Response.java

@Override
public String getContentType() {
    return Optional.of(response).map(request -> request.getFirstHeader("Content-Type")).map(Header::getValue)
            .orElse("");
}

From source file:net.pkhsolutions.pecsapp.control.ScalingPictureFileStorage.java

public void storeForAllLayouts(@NotNull PictureDescriptor descriptor, @NotNull BufferedImage original)
        throws IOException {
    for (PageLayout layout : PageLayout.values()) {
        LOGGER.debug("Storing image for descriptor {} and layout {}", descriptor, layout);
        pictureFileStorage.store(descriptor, Optional.of(layout),
                pictureTransformer.scaleIfNecessary(original, layout));
    }//from  www.j av a  2s.  c om
    // Finally, also store the raw image
    LOGGER.debug("Storing raw image for descriptor {}", descriptor);
    pictureFileStorage.store(descriptor, Optional.empty(), original);
}

From source file:com.teradata.benchto.service.EnvironmentService.java

@Retryable(value = { TransientDataAccessException.class, DataIntegrityViolationException.class })
@Transactional/*ww  w  .  j  a va2s.  c  o  m*/
public void storeEnvironment(String name, Map<String, String> attributes) {
    Optional<Environment> environmentOptional = tryFindEnvironment(name);
    if (!environmentOptional.isPresent()) {
        Environment environment = new Environment();
        environment.setName(name);
        environment.setAttributes(attributes);
        environment.setStarted(currentDateTime());
        environmentOptional = Optional.of(environmentRepo.save(environment));
    } else {
        environmentOptional.get().setAttributes(attributes);
    }
    LOG.debug("Starting environment - {}", environmentOptional.get());
}

From source file:com.greendot.db.jpa.core.AbstractSearchDao.java

@Transactional(readOnly = true)
public Optional<E> findById(final I id) {

    notNull(id, "Mandatory argument 'id' is missing.");
    return Optional.of(entityManager.find(entityType, id));
}