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:com.pablinchapin.anacleto.mongodb.service.UserServiceBean.java

@Override
public List<User> findAll() {
    Optional<List<User>> users = userRepository.findAll();

    return users.get();
}

From source file:net.docare.bookmarks.AccountRepositoryIntegrationTests.java

@Test
public void findsFirstPageOfCities() {
    Optional<Member> optional = memberRepository.findByUsername(userName);
    Member a1 = optional.get();
    assertThat(a1.getPassword(), is("password"));
}

From source file:me.adaptive.core.data.api.UserEntityService.java

public UserEntity toUserEntity(User user, Optional<UserEntity> userEntity) {
    UserEntity entity = userEntity.isPresent() ? userEntity.get() : new UserEntity();
    entity.getAliases().add(user.getEmail());
    entity.setUserId(user.getId());/*  w  w w .  ja  v a2 s  .c om*/
    CollectionUtils.addAll(entity.getAliases(), user.getAliases().iterator());
    return entity;
}

From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java

private static boolean killProcess(final String pid, final Optional<Integer> kill_signal) throws IOException {
    //      kill -15 the process, wait a few cycles to let it die            
    final ProcessBuilder pb = new ProcessBuilder(Arrays.asList("kill", "-" + kill_signal.orElse(15), pid));
    logger.debug("trying to kill -" + kill_signal.orElse(15) + " pid: " + pid);
    final Process px = pb.start();
    for (int i = 0; i < 5; ++i) {
        try {/* ww w. jav  a2  s  . c o m*/
            Thread.sleep(1000L);
        } catch (Exception e) {
        }
        if (!isProcessRunning(pid)) {
            break;
        }
    }
    if (!isProcessRunning(pid)) {
        return 0 == px.exitValue();
    } else {
        //we are still alive, so send a harder kill signal if we haven't already sent a 9
        if (kill_signal.isPresent() && kill_signal.get() == 9) {
            return false;
        } else {
            logger.debug("Timed out trying to kill: " + pid + " sending kill -9 to force kill");
            return killProcess(pid, Optional.of(9));
        }

    }
}

From source file:org.trustedanalytics.servicebroker.hdfs.plans.HdfsPlanGetUserDirectory.java

private boolean isMapNotNullAndNotEmpty(Optional<Map<String, Object>> map) {
    return map.isPresent() && !map.get().isEmpty();
}

From source file:io.smalldata.ohmageomh.dsu.controller.AccountController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Authentication auth, Model model) {
    Optional<EndUser> user = endUserRepo.findOne(auth.getName());
    model.addAttribute("user", user.get());
    List<Study> studies = studyService.getStudiesByUsername(user.get().getUsername());
    model.addAttribute("studies", studies);
    return "home";
}

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));
        }//  w  ww .  j a v  a  2 s  .c o  m
        target.setResults(results);
    } else {
        target.setResults(Collections.emptyList());
    }
}

From source file:se.omegapoint.facepalm.application.UserService.java

public Result<User, UserFailure> getUserWith(final String username) {
    notBlank(username);/* w  w w . j a va2  s  .co m*/

    final Optional<User> user = getUser(username);
    return user.isPresent() ? Result.success(user.get()) : Result.failure(USER_DOES_NOT_EXIST);
}

From source file:com.jeanchampemont.notedown.utils.UserLocaleResolver.java

@Override
public Locale resolveLocale(HttpServletRequest request) {
    if (SecurityContextHolder.getContext().getAuthentication() == null) {
        return acceptHeaderLocaleResolver.resolveLocale(request);
    }//w  w w.  j  av  a 2s  . c  om
    String email = SecurityContextHolder.getContext().getAuthentication().getName();
    Optional<User> user = userService.getUserByEmail(email);
    if (!user.isPresent() || StringUtils.isEmpty(user.get().getLocale())) {
        return acceptHeaderLocaleResolver.resolveLocale(request);
    }
    return user.map(u -> Locale.forLanguageTag(u.getLocale())).get();
}

From source file:fi.helsinki.opintoni.integration.unisport.UnisportRestClientTest.java

@Test
public void thatUnisportUserIsReturned() {
    unisportServer.expectAuthorization();
    Optional<UnisportUser> userByPrincipal = unisportRestClient.getUnisportUserByPrincipal(STUDENT_PRINCIPAL);
    assertThat(userByPrincipal.get().user).isEqualTo(UNISPORT_USER_ID);
}