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.tu_dortmund.ub.data.util.TPUUtil.java

public static Optional<Boolean> getBooleanConfigValue(final String configKey, final Properties config) {

    final String configValue = config.getProperty(configKey);

    final Optional<Boolean> optionalConfigValue;

    if (configValue != null && !configValue.trim().isEmpty()) {

        optionalConfigValue = Optional.of(Boolean.valueOf(configValue));
    } else {// w  w  w.j  a v  a  2 s  .c o m

        optionalConfigValue = Optional.empty();
    }

    return optionalConfigValue;
}

From source file:org.openmhealth.shim.googlefit.mapper.GoogleFitBodyWeightDataPointMapper.java

@Override
public Optional<DataPoint<BodyWeight>> asDataPoint(JsonNode listNode) {

    JsonNode valueList = asRequiredNode(listNode, getValueListNodeName());

    Double bodyWeightValue = asRequiredDouble(valueList.get(0), "fpVal");
    if (bodyWeightValue == 0) {
        return Optional.empty();
    }//  w w w.  j a v  a2 s  . c  om

    BodyWeight.Builder bodyWeightBuilder = new BodyWeight.Builder(new MassUnitValue(KILOGRAM, bodyWeightValue));
    setEffectiveTimeFrameIfPresent(bodyWeightBuilder, listNode);

    Optional<String> originDataSourceId = asOptionalString(listNode, "originDataSourceId");

    BodyWeight bodyWeight = bodyWeightBuilder.build();
    return Optional.of(newDataPoint(bodyWeight, originDataSourceId.orElse(null)));
}

From source file:io.dfox.junit.http.api.Path.java

/**
 * Parse a String into a RunPath. The path is expected to be in the format 
 * &lt;grouping&gt;[/&lt;name&gt;].
 * /*  w w w  .ja va 2s  .com*/
 * @param path The string path
 * @return The test path or an empty Optional if the path is not valid or could not be parsed
 */
public static Optional<Path> parse(final String path) {
    final ImmutableList<String> parts = Arrays.stream(path.split("/")).map(s -> s.trim())
            .filter(s -> !s.isEmpty()).collect(Collectors.toImmutableList());

    switch (parts.size()) {
    case 1:
        return Optional.of(new Path(parts.get(0), Optional.empty()));
    case 2:
        return Optional.of(new Path(parts.get(0), Optional.of(parts.get(1))));
    default:
        return Optional.empty();
    }
}

From source file:org.openmhealth.shim.fitbit.mapper.FitbitBodyWeightDataPointMapper.java

@Override
protected Optional<DataPoint<BodyWeight>> asDataPoint(JsonNode node) {

    MassUnitValue bodyWeight = new MassUnitValue(KILOGRAM, asRequiredDouble(node, "weight"));
    BodyWeight.Builder builder = new BodyWeight.Builder(bodyWeight);

    Optional<OffsetDateTime> dateTime = combineDateTimeAndTimezone(node);

    if (dateTime.isPresent()) {
        builder.setEffectiveTimeFrame(dateTime.get());
    }//from  w ww  .ja  v a 2 s.c  om

    Optional<Long> externalId = asOptionalLong(node, "logId");

    return Optional.of(newDataPoint(builder.build(), externalId.orElse(null)));
}

From source file:org.openmhealth.shim.googlefit.mapper.GoogleFitBodyHeightDataPointMapper.java

@Override
public Optional<DataPoint<BodyHeight>> asDataPoint(JsonNode listNode) {

    JsonNode valueListNode = asRequiredNode(listNode, getValueListNodeName());
    double bodyHeightValue = asRequiredDouble(valueListNode.get(0), "fpVal");

    if (bodyHeightValue == 0) {
        return Optional.empty();
    }/*  w ww  .  j a v  a  2s .c o  m*/

    BodyHeight.Builder bodyHeightBuilder = new BodyHeight.Builder(new LengthUnitValue(METER, bodyHeightValue));

    setEffectiveTimeFrameIfPresent(bodyHeightBuilder, listNode);

    BodyHeight bodyHeight = bodyHeightBuilder.build();
    Optional<String> originDataSourceId = asOptionalString(listNode, "originDataSourceId");

    return Optional.of(newDataPoint(bodyHeight, originDataSourceId.orElse(null)));
}

From source file:io.github.retz.scheduler.MesosHTTPFetcher.java

public static Optional<String> sandboxUri(String t, String master, String slaveId, String frameworkId,
        String executorId) {//from   w ww  . java2 s . com

    Optional<String> slaveAddr = fetchSlaveAddr(master, slaveId); // get master:5050/slaves with slaves/pid, cut with '@'
    LOG.debug("Agent address of executor {}: {}", executorId, slaveAddr);

    if (!slaveAddr.isPresent()) {
        return Optional.empty();
    }

    Optional<String> dir = fetchDirectory(slaveAddr.get(), frameworkId, executorId);
    if (!dir.isPresent()) {
        return Optional.empty();
    }

    try {
        return Optional.of(String.format("http://%s/files/%s?path=%s", slaveAddr.get(), t,
                java.net.URLEncoder.encode(dir.get(), //builder.toString(),
                        java.nio.charset.StandardCharsets.UTF_8.toString())));
    } catch (UnsupportedEncodingException e) {
        return Optional.empty();
    }
}

From source file:ms.dew.devops.kernel.plugin.appkind.frontend_node.FrontendNodePrepareFlow.java

@Override
protected Optional<String> getPackageCmd(FinalProjectConfig config, String currentPath) {
    String cmd = config.getApp().getPackageCmd();
    if (cmd == null || cmd.trim().isEmpty()) {
        // //ww w  .  ja v a2s. com
        cmd = "npm run build:" + config.getProfile();
    }
    cmd = "cd " + currentPath + " && " + cmd;
    return Optional.of(cmd);
}

From source file:fi.helsinki.opintoni.service.CourseServiceTest.java

@Test
public void thatTeacherCourseDtosAreFetched() {
    expectTeacherCourses();/*from w  w  w . j a va  2 s. co m*/

    Set<CourseDto> courseDtos = courseService.getCourses(Optional.empty(),
            Optional.of(TestConstants.TEACHER_NUMBER), Locale.ENGLISH);

    assertThat(courseDtos).hasSize(2);
    assertThat(courseDtos, hasCourseWithRealisationId(TestConstants.TEACHER_COURSE_REALISATION_ID));
    assertThat(courseDtos, hasCourseWithRealisationId(TestConstants.EXAM_TEACHER_COURSE_REALISATION_ID));
}

From source file:io.github.retz.web.feign.ErrorResponseDecoder.java

private static Optional<String> extract(String message) {
    int idx = message.indexOf(SEPARATOR);
    if (idx >= 0) {
        return Optional.of(message.substring(idx + SEPARATOR.length()));
    } else {/*from w w w.  ja  v a  2  s  . co  m*/
        return Optional.empty();
    }
}

From source file:blusunrize.immersiveengineering.client.models.ModelItemDynamicOverride.java

public ModelItemDynamicOverride(IBakedModel itemModel, @Nullable List<ResourceLocation> textures) {
    this.itemModel = itemModel;
    if (textures != null) {
        ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
        Optional<TRSRTransformation> transform = Optional.of(TRSRTransformation.identity());
        for (int i = 0; i < textures.size(); i++)
            builder.addAll(ItemLayerModel.getQuadsForSprite(i, ClientUtils.getSprite(textures.get(i)),
                    DefaultVertexFormats.ITEM, transform));
        quads = builder.build();//from   w  w w . j a  v a  2 s . co m
        guiModel = new BakedGuiItemModel(this);
    } else {
        guiModel = itemModel;
    }
}