Example usage for java.util Optional isPresent

List of usage examples for java.util Optional isPresent

Introduction

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

Prototype

public boolean isPresent() 

Source Link

Document

If a value is present, returns true , otherwise false .

Usage

From source file:com.teradata.tempto.internal.configuration.ConfigurationVariableResolver.java

private Pair<String, Object> resolveConfigurationEntry(Configuration configuration, String prefix,
        StrSubstitutor strSubstitutor) {
    Optional<Object> optionalValue = configuration.get(prefix);
    if (optionalValue.isPresent()) {
        Object value = optionalValue.get();
        if (value instanceof String) {
            return Pair.of(prefix, strSubstitutor.replace(value));
        } else {//www . j  a  va  2 s.  c o m
            return Pair.of(prefix, value);
        }
    } else {
        return Pair.of(prefix, resolveVariables(configuration.getSubconfiguration(prefix), strSubstitutor));
    }
}

From source file:com.amazonaws.service.apigateway.importer.config.AwsConfig.java

public void load() {
    Optional<String> region = loadRegion();

    if (region.isPresent()) {
        this.region = region.get();
    } else {//from   ww w. ja va 2s  .c  o  m
        this.region = DEFAULT_REGION;
        LOG.warn("Could not load region configuration. Please ensure AWS CLI is "
                + "configured via 'aws configure'. Will use default region of " + this.region);
    }
}

From source file:com.fredhopper.connector.query.populators.response.SearchResponseResultsPopulator.java

@Override
public void populate(final FhSearchResponse source, final FacetSearchPageData<FhSearchQueryData, I> target) {
    final Optional<Universe> universe = getUniverse(source);
    if (universe.isPresent() && universe.get().getItemsSection() != null) {
        final Items items = universe.get().getItemsSection().getItems();
        final List<I> results = new ArrayList<>();
        for (final Item item : items.getItem()) {
            results.add(convertResultDocument(source.getPage().getSearchterms(), item));
        }/*from  www.j  a va  2s. com*/
        target.setResults(results);
    } else {
        target.setResults(Collections.emptyList());
    }
}

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

@Transactional(readOnly = true)
public Environment findEnvironment(String name) {
    Optional<Environment> environment = tryFindEnvironment(name);
    if (!environment.isPresent()) {
        throw new IllegalArgumentException("Could not find environment " + name);
    }//from   ww w .j ava 2 s .c om
    return environment.get();
}

From source file:de.bytefish.elasticutils.elasticsearch2.utils.JsonUtilitiesTest.java

@Test
public void json_is_generated_when_serialization_succeeds() throws Exception {

    TestEntity entity = new TestEntity();

    entity.val = "Test";

    Optional<byte[]> resultBytes = JsonUtilities.convertJsonToBytes(entity);

    Assert.assertEquals(true, resultBytes.isPresent());
    Assert.assertEquals("{\"val\":\"Test\"}", new String(resultBytes.get()));
}

From source file:org.homiefund.api.service.impl.UserServiceImpl.java

@Override
@Transactional(readOnly = true)/*w w w  .j  a  va  2s.c  om*/
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
    Optional<User> user = userDAO.getByUsername(s);
    if (!user.isPresent()) {
        throw new UsernameNotFoundException(s);
    } else {
        UserDTO result = mapper.map(user.get(), UserDTO.class);
        result.setHomes(homeDAO.getHomes(user.get()).stream().map(h -> {
            HomeDTO hdto = new HomeDTO();
            hdto.setId(h.getId());
            return hdto;
        }).collect(Collectors.toList()));

        return result;
    }
}

From source file:io.dfox.junit.example.NoteRepositoryTest.java

@Test
public void testSaveFind() throws IOException {

    final String name = "test-note";
    final String contents = "This is my note";

    assertFalse(repository.getNote(name).isPresent());

    try (InputStream contentsStream = IOUtils.toInputStream(contents)) {
        repository.saveNote(name, contentsStream);
    }// w  ww .jav  a 2  s . co m

    Optional<InputStream> note = repository.getNote(name);
    assertTrue(note.isPresent());
    try (InputStream stream = note.get()) {
        String savedContents = IOUtils.toString(stream);
        Assert.assertEquals(contents, savedContents);
    }
}

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 w w. j av a 2s.c  om*/

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

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

From source file:org.openmhealth.shim.runkeeper.mapper.RunkeeperCaloriesBurnedDataPointMapper.java

@Override
protected Optional<DataPoint<CaloriesBurned>> asDataPoint(JsonNode itemNode) {

    Optional<CaloriesBurned> caloriesBurned = getMeasure(itemNode);

    if (caloriesBurned.isPresent()) {
        return Optional
                .of(new DataPoint<>(getDataPointHeader(itemNode, caloriesBurned.get()), caloriesBurned.get()));
    } else {/*from  w ww  .  j  a v a2 s .c o m*/
        return Optional.empty(); // return empty if there was no calories information to generate a datapoint
    }

}

From source file:org.jhk.pulsing.web.service.prod.UserService.java

@Override
public Result<User> getUser(UserId userId) {
    Result<User> result = new Result<>(FAILURE, "Unable to find " + userId);

    Optional<User> user = mySqlUserDao.getUser(userId);
    if (user.isPresent()) {
        result = new Result<>(SUCCESS, user.get());
    }//from  ww  w .jav  a  2s .  c o  m

    return result;
}