List of usage examples for java.util Optional orElse
public T orElse(T other)
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java
@ExtDirectMethod(value = ExtDirectMethodType.STORE_READ, group = "optional") public ExtDirectStoreResult<Row> storeRead2(ExtDirectStoreReadRequest request, @CookieValue Optional<String> cookie, @RequestHeader Optional<String> requestHeader) { return RemoteProviderStoreRead.createExtDirectStoreResult(request, ":" + cookie.orElse("defaultCookie") + ":" + requestHeader.orElse("defaultHeader")); }
From source file:gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO.java
@JsonIgnore public PhoneDTO getPreferredPhoneNumber() { Optional<PhoneDTO> preferredPhoneNumber = this.phones.stream() .filter(phone -> phone.isPreferred() == null ? false : phone.isPreferred()).findAny(); return preferredPhoneNumber.orElse(phones.get(0)); }
From source file:com.ikanow.aleph2.search_service.elasticsearch.services.ElasticsearchIndexService.java
/** Low level utility - Performs some initializations used in a few different places * @return/* w ww . ja v a 2 s . c om*/ */ protected static Tuple3<ElasticsearchIndexServiceConfigBean, String, Optional<String>> getSchemaConfigAndIndexAndType( final DataBucketBean bucket, final ElasticsearchIndexServiceConfigBean config) { final ElasticsearchIndexServiceConfigBean schema_config = ElasticsearchIndexConfigUtils .buildConfigBeanFromSchema(bucket, config, _mapper); final Optional<String> type = Optional.ofNullable(schema_config.search_technology_override()) .map(t -> t.type_name_or_prefix()); final String index_type = CollidePolicy.new_type == Optional .ofNullable(schema_config.search_technology_override()).map(t -> t.collide_policy()) .orElse(CollidePolicy.new_type) ? "_default_" : type.orElse(ElasticsearchIndexServiceConfigBean.DEFAULT_FIXED_TYPE_NAME); return Tuples._3T(schema_config, index_type, type); }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java
@ExtDirectMethod(value = ExtDirectMethodType.SSE, group = "optional") public SSEvent sse3(@RequestParam(value = "id") Optional<Integer> id, @RequestHeader Optional<String> requestHeader) { SSEvent event = new SSEvent(); event.setId("3"); event.setData(id.orElse(-1) + ";" + requestHeader.orElse("defaultRequestHeaderValue")); return event; }
From source file:cc.arduino.LoadVIDPIDSpecificPreferences.java
private int findVIDPIDIndex(PreferencesMap preferences, String vid, String pid) { Optional<Integer> vidPid = preferences.subTree("vid").entrySet().stream() .filter(keyValue -> !keyValue.getKey().contains(".")) .filter(keyValue -> vid.equals(keyValue.getValue().toUpperCase()) && pid.equals(preferences.get("pid." + keyValue.getKey()).toUpperCase())) .map(Map.Entry::getKey).map(Integer::valueOf).findFirst(); return vidPid.orElse(-1); }
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java
/** Utility to build the "_meta" field * @param to_merge/*from w ww .j a v a 2 s . co m*/ * @param bucket * @param is_primary * @param secondary_buffer * @return */ protected static JsonNode createMergedMeta(Either<JsonNode, ObjectMapper> to_merge, DataBucketBean bucket, boolean is_primary, Optional<String> secondary_buffer) { final ObjectNode ret_val = to_merge.either(j -> (ObjectNode) j, om -> om.createObjectNode()); ret_val.put(CUSTOM_META_BUCKET, bucket.full_name()) .put(CUSTOM_META_IS_PRIMARY, Boolean.toString(is_primary)) .put(CUSTOM_META_SECONDARY, secondary_buffer.orElse("")); return ret_val; }
From source file:org.thingsboard.server.dao.device.DeviceServiceImpl.java
@Cacheable(cacheNames = DEVICE_CACHE, key = "{#tenantId, #name}") @Override/*from w w w . j a v a2s.c om*/ public Device findDeviceByTenantIdAndName(TenantId tenantId, String name) { log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name); validateId(tenantId, INCORRECT_TENANT_ID + tenantId); Optional<Device> deviceOpt = deviceDao.findDeviceByTenantIdAndName(tenantId.getId(), name); return deviceOpt.orElse(null); }
From source file:org.thingsboard.server.dao.entityview.EntityViewServiceImpl.java
@Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #name}") @Override/* ww w .j a va 2 s.c o m*/ public EntityView findEntityViewByTenantIdAndName(TenantId tenantId, String name) { log.trace("Executing findEntityViewByTenantIdAndName [{}][{}]", tenantId, name); validateId(tenantId, INCORRECT_TENANT_ID + tenantId); Optional<EntityView> entityViewOpt = entityViewDao.findEntityViewByTenantIdAndName(tenantId.getId(), name); return entityViewOpt.orElse(null); }
From source file:org.ow2.proactive.workflow_catalog.rest.service.WorkflowRevisionServiceTest.java
private void createWorkflow(String name, String projectName, String fileName, Optional<Long> wId, Optional<String> layout) throws IOException { String layoutStr = layout.orElse(""); when(bucketRepository.findOne(anyLong())).thenReturn(mock(Bucket.class)); when(genericInformationRepository.save(any(List.class))).thenReturn(Lists.newArrayList()); when(variableRepository.save(any(List.class))).thenReturn(Lists.newArrayList()); when(workflowRevisionRepository.save(any(WorkflowRevision.class))) .thenReturn(new WorkflowRevision(EXISTING_ID, EXISTING_ID, name, projectName, LocalDateTime.now(), layoutStr, Lists.newArrayList(), Lists.newArrayList(), getWorkflowAsByteArray(fileName))); if (wId.isPresent()) { when(workflowRepository.findOne(anyLong())) .thenReturn(new Workflow(mock(Bucket.class), Lists.newArrayList())); }// w ww.ja v a 2 s. c o m WorkflowMetadata actualWFMetadata = workflowRevisionService.createWorkflowRevision(DUMMY_ID, wId, getWorkflowAsByteArray(fileName), layout); verify(workflowRevisionRepository, times(1)).save(any(WorkflowRevision.class)); assertEquals(name, actualWFMetadata.name); assertEquals(projectName, actualWFMetadata.projectName); assertEquals(EXISTING_ID, actualWFMetadata.bucketId); assertEquals(EXISTING_ID, actualWFMetadata.revisionId); if (layout.isPresent()) { assertEquals(layout.get(), actualWFMetadata.layout); } }
From source file:org.jspare.jsdbc.JsdbcTransportImpl.java
/** * Gets the url connection.//from w ww . j a v a 2s .c o m * * @param datasource * the datasource * @param operation * the operation * @param domain * the domain * @return the url connection */ private String getUrlConnection(DataSource datasource, String operation, Optional<String> domain) { StringBuilder url = new StringBuilder(); url.append(datasource.getHost()); url.append(":"); url.append(datasource.getPort()); url.append(operation); return url.toString().replace(":instance", datasource.getInstance()).replace(":domain", domain.orElse(StringUtils.EMPTY)); }