Example usage for java.util Optional get

List of usage examples for java.util Optional get

Introduction

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

Prototype

public T get() 

Source Link

Document

If a value is present, returns the value, otherwise throws NoSuchElementException .

Usage

From source file:io.fluo.webindex.data.fluo.UriCountExport.java

@Override
protected Map<RowColumn, Bytes> generateData(String pageID, Optional<UriInfo> val) {
    if (val.orElse(UriInfo.ZERO).equals(UriInfo.ZERO)) {
        return Collections.emptyMap();
    }//from  w w w.ja  v  a  2  s  .  c  om

    UriInfo uriInfo = val.get();

    Map<RowColumn, Bytes> rcMap = new HashMap<>();
    Bytes linksTo = Bytes.of("" + uriInfo.linksTo);
    rcMap.put(new RowColumn(createTotalRow(pageID, uriInfo.linksTo), Column.EMPTY), linksTo);
    String domain = URL.fromPageID(pageID).getReverseDomain();
    String domainRow = encodeDomainRankPageId(domain, uriInfo.linksTo, pageID);
    rcMap.put(new RowColumn(domainRow, new Column(Constants.RANK, "")), linksTo);
    rcMap.put(new RowColumn("p:" + pageID, FluoConstants.PAGE_INCOUNT_COL), linksTo);
    return rcMap;
}

From source file:com.github.jrh3k5.habitat4j.rest.CachingAccessTokenProvider.java

@Override
public AccessToken getAccessToken() {
    final Optional<AccessToken> currentAccessToken = getCurrentAccessToken();
    if (!currentAccessToken.isPresent() || needsRefresh(currentAccessToken.get())) {
        return getNewAccessToken();
    }/*from   w ww  .j a v  a2s. c om*/

    return currentAccessToken.get();
}

From source file:io.gravitee.management.idp.repository.lookup.RepositoryIdentityLookup.java

@Override
public io.gravitee.management.idp.api.identity.User retrieve(String id) {
    try {/*from w  w  w.  j a v a 2s  .co m*/
        Optional<io.gravitee.repository.management.model.User> optUser = userRepository.findByUsername(id);

        if (optUser.isPresent()) {
            return convert(optUser.get());
        }
    } catch (TechnicalException te) {
        LOGGER.error("Unexpected error while looking for a user with id " + id, te);
    }
    return null;
}

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

public void run(@Nonnull String... args) throws Exception {
    m_helper.addOptions(new Option("i", "input", true, "The input file"),
            new Option("o", "output", true, "The output file"));

    Optional<ExtendedCommandLine> response = m_helper.parse(args);
    if (response.isPresent()) {

        ExtendedCommandLine cli = response.get();

        Optional<File> input = cli.getFile("i");
        Optional<File> output = cli.getFile("o");

        if (input.isPresent() ^ output.isPresent()) {
            m_helper.printHelp();/*w  w w.  j a  va  2 s .  co  m*/
        } else if (!input.isPresent()) {
            m_constructor.construct(cli).pipe();
        } else {
            m_constructor.construct(cli).apply(input.get(), output.get());
        }
    }

}

From source file:org.openmhealth.shim.withings.mapper.WithingsHeartRateDataPointMapper.java

@Override
public Optional<Measure.Builder<HeartRate, ?>> newMeasureBuilder(JsonNode measuresNode) {

    Optional<BigDecimal> value = getValueForMeasureType(measuresNode, HEART_RATE);

    if (!value.isPresent()) {
        return empty();
    }//www  .j a  va  2 s  .  com

    return Optional.of(new HeartRate.Builder(value.get()));
}

From source file:it.unibo.alchemist.model.implementations.conditions.BiomolPresentInEnv.java

private double getTotalQuantity() {
    double quantityInEnvNodes = 0;
    if (!getEnviromentNodesSurrounding().isEmpty()) {
        quantityInEnvNodes = getEnviromentNodesSurrounding().stream().parallel()
                .mapToDouble(n -> n.getConcentration(getBiomolecule())).sum();
    }/*from   w  w  w.  j  av  a2 s. com*/
    double quantityInLayers = 0;
    final Optional<Layer<Double>> layer = environment.getLayer(getBiomolecule());
    if (layer.isPresent()) {
        quantityInLayers = layer.get().getValue(environment.getPosition(getNode()));
    }
    return quantityInEnvNodes + quantityInLayers;
}

From source file:com.gtp.tradeapp.rest.UserController.java

@RequestMapping(value = "/password/reset", method = RequestMethod.POST)
public Status resetPassword(@RequestParam("email") String email) {
    LOGGER.debug("Resetting password for username={}" + email);
    Optional<User> user = userService.getUserByEmail(email);
    if (user.isPresent()) {
        return updatePasswordAndSendTo(user.get());
    }/*www.ja  v a 2  s . c  o  m*/
    return new Status(0, "Unable to reset password for " + email);
}

From source file:com.javaeeeee.repositories.UsersRepositoryTest.java

/**
 * A method to test that findByUsername returns a user.
 */// w  w  w  .  j a va2 s  .c om
@Test
public void findByUsernameShouldReturnAUser() {
    final String name = "Phil";
    entityManager.persist(new User(name, "1"));
    Optional<User> optional = usersRepository.findByUsername(name);

    Assert.assertTrue(optional.isPresent());
    User user = optional.get();

    Assert.assertEquals(name, user.getUsername());
}

From source file:com.teradata.tempto.internal.hadoop.hdfs.HdfsModuleProvider.java

@Override
public Module getModule(Configuration configuration) {
    return new PrivateModule() {
        @Override/*from   ww w . jav a 2  s.  c om*/
        protected void configure() {
            install(httpRequestsExecutorModule());

            bind(HdfsClient.class).to(WebHdfsClient.class).in(Scopes.SINGLETON);
            bind(RevisionStorage.class).toProvider(RevisionStorageProvider.class).in(Scopes.SINGLETON);
            bind(HdfsDataSourceWriter.class).to(DefaultHdfsDataSourceWriter.class).in(Scopes.SINGLETON);

            expose(HdfsClient.class);
            expose(RevisionStorage.class);
            expose(HdfsDataSourceWriter.class);
        }

        private Module httpRequestsExecutorModule() {
            if (spnegoAuthenticationRequired()) {
                return new SpnegoHttpRequestsExecutor.Module();
            } else {
                return new SimpleHttpRequestsExecutor.Module();
            }
        }

        private boolean spnegoAuthenticationRequired() {
            Optional<String> authentication = configuration.getString("hdfs.webhdfs.authentication");
            return authentication.isPresent() && authentication.get().equalsIgnoreCase(AUTHENTICATION_SPNEGO);
        }

        @Inject
        @Provides
        @Singleton
        CloseableHttpClient createHttpClient() {
            HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
            httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(NUMBER_OF_HTTP_RETRIES, true));
            return httpClientBuilder.build();
        }
    };
}

From source file:org.openmhealth.dsu.repository.ClientDetailsRepositoryIntegrationTests.java

@Test
public void findOneShouldReturnSavedClientDetails() {

    SimpleClientDetails expected = clientDetailsRepository.save(newClientDetails());

    Optional<SimpleClientDetails> actual = clientDetailsRepository.findOne(TEST_CLIENT_ID);

    assertThat(actual.isPresent(), equalTo(true));
    assertThat(actual.get(), equalTo(expected));
}