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.knotx.mocks.adapter.MockActionAdapterHandler.java

private AdapterResponse replyTransition(ClientRequest request, JsonObject transitions) {
    final Pair<Optional<String>, JsonObject> result = getTransitionResult(request, transitions);

    final JsonObject resultBody = result.getRight().put("form", toJsonObject(request.getFormAttributes()));

    final String data = resultBody.toString();
    final ClientResponse clientResponse = new ClientResponse().setHeaders(headers(request, data))
            .setStatusCode(HttpResponseStatus.OK.code()).setBody(Buffer.buffer(data));

    final AdapterResponse response = new AdapterResponse().setResponse(clientResponse);

    final Optional<String> transition = result.getLeft();
    if (transition.isPresent()) {
        response.setSignal(transition.get());
    }//from www  .  j  a  va  2 s.co  m
    return response;
}

From source file:se.uu.it.cs.recsys.semantic.ComputingDomainReasonerTest.java

/**
 * Test of getPrefLabel method, of class ComputingDomainReasoner.
 *//*from  w  w  w .  j  ava  2 s .c o m*/
@Test
public void testGetPrefLabel() throws Exception {

    final String domainId = "10003350";
    final String expResult = "Recommender systems";
    final Optional<String> result = this.reasoner.getPrefLabel(domainId);
    assertEquals(expResult, result.get());

}

From source file:com.adobe.ags.curly.controller.ActionGroupRunner.java

private Optional<Exception> withClient(Function<CloseableHttpClient, Optional<Exception>> process) {
    if (client == null) {
        client = clientSupplier.apply(false);
    }/*from   w w  w . jav  a  2 s  .  c om*/
    Optional<Exception> ex = process.apply(client);
    if (ex.isPresent() && ex.get() instanceof IllegalStateException) {
        System.err.println("Error in HTTP request - RETRYING: " + ex.get().getMessage());
        ex.get().printStackTrace();
        client = clientSupplier.apply(true);
        ex = process.apply(client);
    }
    if (ex.isPresent()) {
        System.err.println("Error in HTTP request, abandoning client: " + ex.get().getMessage());
        ex.get().printStackTrace();
        client = null;
    }
    return ex;
}

From source file:com.pablinchapin.anacleto.mongodb.service.UserServiceBean.java

@Override
public User findByUserId(String userId) {
    Optional<User> user = userRepository.findOne(userId);

    if (user.isPresent()) {
        log.debug(String.format("Read userId '{}'", userId));
        return user.get();
    } else {/*from w  w  w .ja v  a 2 s.  c o m*/
        throw new UserNotFoundException(userId);
    }
}

From source file:io.github.retz.db.Jobs.java

public void doRetry(List<Integer> ids) {
    try {//w  w w .  j  a v  a 2 s . co m
        for (int id : ids) {
            Optional<Job> maybeJob = getJob(id);
            if (maybeJob.isPresent()) {
                Job job = maybeJob.get();
                job.doRetry();
                updateJob(job);
            }
        }
    } catch (SQLException e) {
        LOG.error(e.toString());
    } catch (IOException e) {
        LOG.error(e.toString()); // TODO: do we fail?
    }
}

From source file:com.dickthedeployer.dick.web.service.ProjectServiceTest.java

@Test
public void shouldCreateProject()
        throws NameTakenException, RepositoryUnavailableException, RepositoryParsingException {
    ProjectModel model = getProjectModel("test-namespace", "some-semi-random-name");

    projectService.createProject(model);
    Optional<Project> project = projectDao.findByNamespaceNameAndName("test-namespace",
            "some-semi-random-name");
    assertThat(project.get().getRef()).isEqualTo("master");
    assertThat(project.get().getCreationDate()).isNotNull();

}

From source file:com.siemens.sw360.fossology.ssh.JSchSessionProvider.java

public Session getSession(int connectionTimeout) throws SW360Exception {
    Optional<Session> session = pollCachedSession();
    if (session.isPresent()) {
        return session.get();
    } else {/*ww w .  j  a va  2  s. c om*/
        return doGetSession(connectionTimeout);
    }
}

From source file:fi.hsl.parkandride.back.LockDao.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.SERIALIZABLE)
public Lock acquireLock(String lockName, Duration lockDuration) {
    Optional<Lock> lock = selectLockIfExists(lockName);
    if (lock.isPresent()) {
        Lock existingLock = lock.get();
        if (!existingLock.validUntil.isAfter(DateTime.now())) {
            return claimExpiredLock(existingLock, lockDuration);
        } else {/*  w ww.j  a  v  a2s.c om*/
            throw new LockAcquireFailedException("Existing lock " + existingLock + " is still valid");
        }
    }
    return insertLock(lockName, lockDuration);
}

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

private boolean validateIfEnoughCash(Transaction transaction) {
    Optional<User> userDao = userService.getUserById(transaction.getUserId());
    if (userDao.isPresent()) {
        return userDao.get().getCash().compareTo(transaction.getTotal()) > 0;
    }//w  w  w.  ja  v  a2s.c  o m
    return false;
}

From source file:ch.sportchef.business.authentication.boundary.AuthenticationResource.java

@POST
@Consumes({ MediaType.APPLICATION_JSON })
public Response authenticate(final DefaultLoginCredentials credential) {
    final Optional<String> token = authenticationService.validateChallenge(identity, credential);

    return token.isPresent() ? Response.ok(Entity.text(token.get())).build()
            : Response.status(Status.FORBIDDEN).build();
}