List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:org.trustedanalytics.metricsprovider.cloudadapter.api.CfSpace.java
@JsonIgnore public String getName() { Optional<CfSpace> space = Optional.of(this); return space.map(CfSpace::getEntity).map(CfSpaceEntity::getName).orElse(null); }
From source file:org.openwms.common.HttpCommonGateway.java
@Override public Optional<LocationGroup> getLocationGroup(String target) { try {/*from w w w . ja va2 s .c o m*/ return Optional.of(commonFeignClient.getLocationGroup(target)); } catch (Exception ex) { int code = translate(ex); if (code == 404) { return Optional.empty(); } else { LOGGER.error(ex.getMessage(), ex); throw new ServiceLayerException(ex.getMessage()); } } }
From source file:com.juliuskrah.multipart.repository.impl.HibernateAccountRepository.java
@Override public Optional<Account> findByUsername(String username) { CriteriaBuilder qb = this.em.getCriteriaBuilder(); CriteriaQuery<Account> query = qb.createQuery(Account.class); Root<Account> root = query.from(Account.class); Predicate predicate = qb.like(root.get(Account_.username), username); query.where(predicate);/* ww w. jav a2 s . c o m*/ Query q = this.em.createQuery(query); return Optional.of((Account) q.getSingleResult()); }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthHeartRateDataPointMapper.java
@Override protected Optional<DataPoint<HeartRate>> asDataPoint(JsonNode listEntryNode, Integer measureUnitMagicNumber) { double heartRateValue = asRequiredDouble(listEntryNode, "HR"); if (heartRateValue == 0) { return Optional.empty(); }/*from ww w.j a v a2s . co m*/ HeartRate.Builder heartRateBuilder = new HeartRate.Builder(heartRateValue); getEffectiveTimeFrameAsDateTime(listEntryNode).ifPresent(heartRateBuilder::setEffectiveTimeFrame); getUserNoteIfExists(listEntryNode).ifPresent(heartRateBuilder::setUserNotes); HeartRate heartRate = heartRateBuilder.build(); return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, heartRate), heartRate)); }
From source file:io.gravitee.gateway.env.GatewayConfiguration.java
private void initShardingTags() { String systemPropertyTags = System.getProperty(SHARDING_TAGS_SYSTEM_PROPERTY); String tags = systemPropertyTags == null ? environment.getProperty(SHARDING_TAGS_SYSTEM_PROPERTY) : systemPropertyTags;/*from w w w. j a v a 2 s .c o m*/ if (tags != null && !tags.isEmpty()) { shardingTags = Optional.of(Arrays.asList(tags.split(SHARDING_TAGS_SEPARATOR))); } else { shardingTags = Optional.empty(); } }
From source file:org.openmhealth.shim.googlefit.mapper.GoogleFitHeartRateDataPointMapper.java
@Override protected Optional<DataPoint<HeartRate>> asDataPoint(JsonNode listNode) { JsonNode valueListNode = asRequiredNode(listNode, "value"); double heartRateValue = asRequiredDouble(valueListNode.get(0), "fpVal"); if (heartRateValue == 0) { return Optional.empty(); }// w ww . j a v a2s . com HeartRate.Builder heartRateBuilder = new HeartRate.Builder(heartRateValue); setEffectiveTimeFrameIfPresent(heartRateBuilder, listNode); HeartRate heartRate = heartRateBuilder.build(); Optional<String> originDataSourceId = asOptionalString(listNode, "originDataSourceId"); return Optional.of(newDataPoint(heartRate, originDataSourceId.orElse(null))); }
From source file:org.openmhealth.shim.googlefit.mapper.GoogleFitStepCountDataPointMapper.java
@Override protected Optional<DataPoint<StepCount>> asDataPoint(JsonNode listNode) { JsonNode listValueNode = asRequiredNode(listNode, "value"); long stepCountValue = asRequiredLong(listValueNode.get(0), "intVal"); if (stepCountValue == 0) { return Optional.empty(); }/* w w w .jav a 2 s . c o m*/ StepCount.Builder stepCountBuilder = new StepCount.Builder(stepCountValue); setEffectiveTimeFrameIfPresent(stepCountBuilder, listNode); StepCount stepCount = stepCountBuilder.build(); Optional<String> originSourceId = asOptionalString(listNode, "originDataSourceId"); return Optional.of(newDataPoint(stepCount, originSourceId.orElse(null))); }
From source file:co.runrightfast.vertx.core.eventbus.MessageHeader.java
public static Optional<Failure> getFailure(@NonNull final Message message) { final String failureJson = message.headers().get(FAILURE.header); if (StringUtils.isNotBlank(failureJson)) { return Optional.of(new Failure(JsonUtils.parse(failureJson))); }//from w w w. j av a 2 s.c o m return Optional.empty(); }
From source file:com.formkiq.core.form.FormFinder.java
/** * Find {@link FormJSONField} by field id. * @param form {@link FormJSON}/*from w w w . j a va 2 s . c o m*/ * @param id int * @return {@link Optional} of {@link FormJSONField} */ public static Optional<FormJSONField> findField(final FormJSON form, final int id) { Optional<Pair<FormJSONSection, FormJSONField>> op = findSectionAndField(form, id); return op.isPresent() ? Optional.of(op.get().getRight()) : Optional.empty(); }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthBloodGlucoseDataPointMapper.java
@Override protected Optional<String> getMeasureUnitNodeName() { return Optional.of("BGUnit"); }