List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:co.runrightfast.core.utils.ConfigUtils.java
static Optional<Boolean> getBoolean(final Config config, final String path, final String... paths) { if (!hasPath(config, path, paths)) { return Optional.empty(); }/*from ww w . j a v a 2s. co m*/ return Optional.of(config.getBoolean(configPath(path, paths))); }
From source file:com.thinkbiganalytics.common.velocity.DefaultVelocityService.java
@Override public Optional<Template> getTemplate(String name) { try {/*from www . j ava 2 s . c om*/ Optional<Template> t = Optional.of(velocityEngine.getTemplate(name)); if (t.isPresent()) { registeredTemplates.add(t.get().getName()); } return t; } catch (ResourceNotFoundException e) { return Optional.empty(); } catch (ParseErrorException e) { //WARN!!! return Optional.empty(); } }
From source file:org.openmhealth.shim.fitbit.mapper.FitbitBodyMassIndexDataPointMapper.java
@Override protected Optional<DataPoint<BodyMassIndex>> asDataPoint(JsonNode node) { TypedUnitValue<BodyMassIndexUnit> bmiValue = new TypedUnitValue<>(KILOGRAMS_PER_SQUARE_METER, asRequiredDouble(node, "bmi")); BodyMassIndex.Builder builder = new BodyMassIndex.Builder(bmiValue); Optional<OffsetDateTime> dateTime = combineDateTimeAndTimezone(node); if (dateTime.isPresent()) { builder.setEffectiveTimeFrame(dateTime.get()); }//from ww w . jav a2 s .c o m Optional<Long> externalId = asOptionalLong(node, "logId"); return Optional.of(newDataPoint(builder.build(), externalId.orElse(null))); }
From source file:io.kamax.mxisd.util.GsonParser.java
public Optional<JsonObject> parseOptional(HttpResponse res) { try {/* w w w .ja v a 2 s.com*/ return Optional.of(parse(res.getEntity().getContent())); } catch (IOException e) { return Optional.empty(); } }
From source file:com.spotify.styx.model.deprecated.WorkflowConfiguration.java
public static com.spotify.styx.model.WorkflowConfiguration create(WorkflowConfiguration workflowConfiguration) { return com.spotify.styx.model.WorkflowConfiguration.create(workflowConfiguration.id(), workflowConfiguration.partitioning(), Optional.empty(), workflowConfiguration.dockerImage(), workflowConfiguration.dockerArgs(), Optional.of(workflowConfiguration.dockerTerminationLogging()), Secret.create(workflowConfiguration.secret()), workflowConfiguration.resources()); }
From source file:org.trustedanalytics.cloud.cc.api.CcServiceInstance.java
@JsonIgnore public String getServicePlanName() { Optional<CcServiceInstance> serviceInstance = Optional.of(this); return serviceInstance.map(CcServiceInstance::getServicePlan).map(CcServicePlan::getName).orElse(null); }
From source file:io.pravega.controller.store.stream.tables.HistoryRecord.java
/** * Read record from the history table at the specified offset. * * @param historyTable history table/*w ww.j av a 2 s. c om*/ * @param offset offset to read from * @param ignorePartial if set, ignore if the record is partial * @return */ public static Optional<HistoryRecord> readRecord(final byte[] historyTable, final int offset, boolean ignorePartial) { if (offset >= historyTable.length) { return Optional.empty(); } final int length = BitConverter.readInt(historyTable, offset); if (offset + length > historyTable.length) { // this is a partial record if (ignorePartial) { return Optional.empty(); } else { return Optional.of(parsePartial(historyTable, offset)); } } return Optional.of(parse(historyTable, offset)); }
From source file:tds.assessment.web.endpoints.SegmentControllerTest.java
@Test public void shouldReturnSegmentInformation() { SegmentItemInformation segmentItemInformation = new SegmentItemInformation.Builder().build(); when(mockSegmentService.findSegmentItemInformation("segmentKey")) .thenReturn(Optional.of(segmentItemInformation)); ResponseEntity<SegmentItemInformation> response = segmentController.getSegmentInformation("segmentKey"); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).isEqualTo(segmentItemInformation); }
From source file:com.ikanow.aleph2.security.db.AbstractDb.java
@SuppressWarnings("unchecked") protected void initDb() { if (_core_management_db == null) { _core_management_db = _context.getCoreManagementDbService(); }/*w ww . j a v a 2 s . com*/ if (_underlying_management_db == null) { _underlying_management_db = _context.getServiceProvider(IManagementDbService.class, Optional.empty()) .get().get(); } db = _underlying_management_db.getUnderlyingPlatformDriver(ICrudService.class, Optional.of(getDbOptions())) .get(); logger.debug("Opened DB:" + getDbOptions() + ":" + db); }
From source file:org.lendingclub.mercator.aws.RDSInstanceScanner.java
@Override public Optional<String> computeArn(JsonNode n) { String region = n.get(AWSScanner.AWS_REGION_ATTRIBUTE).asText(null); String account = n.get(AccountScanner.ACCOUNT_ATTRIBUTE).asText(null); String dbInstanceId = n.get("aws_dbinstanceIdentifier").asText(null); Preconditions.checkState(!Strings.isNullOrEmpty(region), "aws_region not set"); Preconditions.checkState(!Strings.isNullOrEmpty(account), "aws_account not set"); Preconditions.checkState(!Strings.isNullOrEmpty(dbInstanceId), "aws_dbinstanceIdentifier not set"); return Optional.of(String.format("arn:aws:rds:%s:%s:db:%s", region, account, dbInstanceId)); }