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.jeanchampemont.notedown.utils.UserLocaleResolver.java

@Override
public Locale resolveLocale(HttpServletRequest request) {
    if (SecurityContextHolder.getContext().getAuthentication() == null) {
        return acceptHeaderLocaleResolver.resolveLocale(request);
    }//  w w  w.  ja va2s .c o m
    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:org.trustedanalytics.serviceinfo.MqttServiceInfoCreator.java

@Override
public boolean accept(Map<String, Object> serviceData) {
    Optional<String> label = Optional.ofNullable((String) serviceData.get("label"));
    if (label.isPresent()) {
        return label.get().equals(MQTT_ID);
    }/*  w w  w.  j  ava  2  s.  com*/
    return false;
}

From source file:com.devicehive.dao.rdbms.RdbmsGenericDao.java

public void cacheQuery(Query query, Optional<CacheConfig> cacheConfig) {
    if (cacheConfig.isPresent()) {
        query.setHint(CACHEABLE, true);/*  w w  w .j  a va 2 s. c om*/
        query.setHint(RETRIEVE_MODE, cacheConfig.get().getRetrieveMode());
        query.setHint(STORE_MODE, cacheConfig.get().getStoreMode());
    }
}

From source file:org.obiba.mica.micaConfig.rest.DataAccessFormResource.java

@GET
public Mica.DataAccessFormDto get() {
    Optional<DataAccessForm> d = dataAccessFormService.find();

    if (!d.isPresent())
        throw NoSuchDataAccessFormException.withDefaultMessage();

    return dtos.asDto(d.get());
}

From source file:org.openwms.tms.redirection.TargetRedirector.java

/**
 * The implementation has to vote for a certain vote on particular rules that are implemented by the voter.
 *
 * @param vote The vote to vote for/*ww w  . j av a 2s  .co  m*/
 * @throws DeniedException is thrown when the voter cannot vote for the action
 */
@Override
public void voteFor(RedirectVote vote) throws DeniedException {
    Optional<T> optionalTarget = resolveTarget(vote);
    if (optionalTarget.isPresent()) {
        if (isTargetAvailable(optionalTarget.get())) {
            assignTarget(vote);
            vote.complete();
        } else {
            String msg = translator.translate(TMSMessageCodes.TARGET_BLOCKED_MSG, vote.getTarget(),
                    vote.getTransportOrder().getPersistentKey());
            vote.addMessage(new Message.Builder().withMessage(msg)
                    .withMessageNo(TMSMessageCodes.TARGET_BLOCKED_MSG).build());
            LOGGER.debug(msg);
        }
    }
}

From source file:com.wms.multitenant.tenant.interceptor.TenantIdentifierInterceptorAdapter.java

@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {

    Map<String, Object> pathVars = (Map<String, Object>) req
            .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
    if (pathVars.containsKey("tenantId")) {
        String tenantId = pathVars.get("tenantId").toString();
        Optional<Tenant> thisTenant = tenantRepo.findByTenantKey(tenantId);
        if (thisTenant.isPresent()) {
            req.setAttribute("Current_Tenant", thisTenant.get().getTenantKey());
            return true;
        } else {/*  ww w . j av a  2 s  .com*/
            res.sendRedirect(req.getContextPath() + "/signUp");
            return false;
        }
    } else {
        return true;
    }

}

From source file:de.is24.aws.instancemetadataserver.RemoteHostRoleNameProducer.java

@Override
public Optional<String> getRoleName(HttpServletRequest request) {
    String hostName = request.getRemoteHost();
    Optional<String> roleName = toRoleName(hostName);
    if (!roleName.isPresent()) {
        LOG.info("Unable to generate a role name for host {}.", hostName);
    }//from   www  . j ava  2s.c o  m
    return roleName;
}

From source file:org.openmhealth.shim.jawbone.mapper.JawboneBodyWeightDataPointMapper.java

@Override
protected Optional<Measure.Builder<BodyWeight, ?>> newMeasureBuilder(JsonNode listEntryNode) {

    Optional<Double> optionalWeight = asOptionalDouble(listEntryNode, "weight");

    if (!optionalWeight.isPresent()) {
        return Optional.empty();
    }/*from   www .  j ava2 s  .c  om*/

    return Optional.of(new BodyWeight.Builder(new MassUnitValue(KILOGRAM, optionalWeight.get())));
}

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

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

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

    if (!value.isPresent()) {
        return empty();
    }/* w ww  . ja  v  a  2  s  .  c  om*/

    return Optional.of(new BodyHeight.Builder(new LengthUnitValue(METER, value.get())));
}

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

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

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

    if (!value.isPresent()) {
        return empty();
    }/*  ww w. ja  v  a 2s . c om*/

    return Optional.of(new BodyWeight.Builder(new MassUnitValue(KILOGRAM, value.get())));
}