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: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());/* ww w  .j  a va  2  s  .c  om*/
    CollectionUtils.addAll(entity.getAliases(), user.getAliases().iterator());
    return entity;
}

From source file:org.openmhealth.dsu.service.EndUserUserDetailsServiceImpl.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

    Optional<EndUser> user = endUserService.findUser(username);

    if (!user.isPresent()) {
        throw new UsernameNotFoundException("A user with username '" + username + "' doesn't exist.");
    }/*from  ww  w  .  j  a v  a 2s .c om*/

    return new EndUserUserDetails(user.get().getUsername(), user.get().getPasswordHash());
}

From source file:cz.muni.fi.editor.database.dao.CmisObjectDAOImpl.java

@Override
public void deleteByCmisID(String objectID) {
    Optional<CmisObjectDB> result = getByCmisID(objectID);
    if (result.isPresent()) {
        getEntityManager().remove(result.get());
    }//from w w  w.j a va2 s .  c  o  m
}

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 {/*from  w ww  .  java2 s.co 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:com.antonjohansson.managementcenter.core.web.VaadinResourcesServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String name = getRequestURI(request);
    Optional<URL> resource = getResource(name);

    if (!resource.isPresent()) {
        response.sendError(SC_NOT_FOUND);
        return;//w  ww .ja v a  2  s  .c  o m
    }

    try (InputStream input = resource.get().openStream(); OutputStream output = response.getOutputStream()) {
        copy(input, output);
    }
}

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

@Override
public void populate(final FhSearchResponse source, final ProductSearchPageData<FhSearchQueryData, I> target) {
    final Optional<Universe> universe = getUniverse(source);
    if (universe.isPresent()) {
        final QueryAlternatives alternatives = universe.get().getQueryAlternatives();
        if (alternatives != null && alternatives.isWasExecuted()
                && CollectionUtils.isNotEmpty(alternatives.getQuerySuggestion())) {
            final QuerySuggestion querySuggestion = alternatives.getQuerySuggestion().get(0);
            final SpellingSuggestionData<FhSearchQueryData> spellingSuggestionData = new SpellingSuggestionData<>();
            spellingSuggestionData.setSuggestion(querySuggestion.getValue().getValue());

            final FhSearchQueryData correctedQuery = cloneSearchQueryData(target.getCurrentQuery());
            correctedQuery.setFreeTextSearch(querySuggestion.getValue().getValue());
            correctedQuery.setLocation(querySuggestion.getUrlParams());
            spellingSuggestionData.setQuery(correctedQuery);
            target.setSpellingSuggestion(spellingSuggestionData);
        }/*from www  .  j a  v  a2 s .  c  om*/
    }
}

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: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  ww .  ja  va2 s  . co m*/
        throw new UserNotFoundException(userId);
    }
}

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

public Result<User, UserFailure> getUserWith(final String username) {
    notBlank(username);//from   ww  w . j  ava2 s .  c  o m

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

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();
    }/*from w  w  w . j a  va 2 s  . c  o  m*/

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