List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:com.orange.cloud.servicebroker.filter.core.filters.ServiceInstanceBindingFilterRunner.java
/** * Run all filters that should be processed before a service instance instance binding has been deleted. * * @param request details of a request to delete a service instance binding. */// w w w . java 2 s . c o m public void preUnbind(DeleteServiceInstanceBindingRequest request) { Optional.ofNullable(deleteServiceInstanceBindingPreFilters) .ifPresent(serviceBrokerFilters -> serviceBrokerFilters.forEach(filter -> filter.run(request))); }
From source file:org.trustedanalytics.cloud.uaa.UaaClient.java
@Override public Optional<UserIdNamePair> findUserIdByName(String userName) { String query = "/Users?attributes=id,userName&filter=userName eq '{name}'"; Map<String, Object> pathVars = ImmutableMap.of("name", userName); UserIdNameList result = uaaRestTemplate.getForObject(uaaBaseUrl + query, UserIdNameList.class, pathVars); return Optional.ofNullable(Iterables.getFirst(result.getUsers(), null)); }
From source file:net.hamnaberg.json.Link.java
public Optional<String> getPrompt() { return Optional.ofNullable(getAsString("prompt")); }
From source file:org.ow2.proactive.connector.iaas.cloud.provider.azure.vm.AzureVMsProvider.java
@Override public Set<Instance> createInstance(Infrastructure infrastructure, Instance instance) { Azure azureService = azureServiceCache.getService(infrastructure); String instanceTag = Optional.ofNullable(instance.getTag()).orElseThrow( () -> new RuntimeException("ERROR missing instance tag/name from instance: '" + instance + "'")); // Check for Image by name first and then by id String imageNameOrId = Optional.ofNullable(instance.getImage()).orElseThrow( () -> new RuntimeException("ERROR missing Image name/id from instance: '" + instance + "'")); VirtualMachineCustomImage image = getImageByName(azureService, imageNameOrId) .orElseGet(() -> getImageById(azureService, imageNameOrId).orElseThrow(() -> new RuntimeException( "ERROR unable to find custom Image: '" + instance.getImage() + "'"))); // Get the options (Optional by design) Optional<Options> options = Optional.ofNullable(instance.getOptions()); // Try to retrieve the resourceGroup from provided name, otherwise get it from image ResourceGroup resourceGroup = azureProviderUtils .searchResourceGroupByName(azureService, options.map(Options::getResourceGroup).orElseGet(image::resourceGroupName)) .orElseThrow(() -> new RuntimeException( "ERROR unable to find a suitable resourceGroup from instance: '" + instance + "'")); // Try to get region from provided name, otherwise get it from image Region region = options.map(presentOptions -> Region.findByLabelOrName(presentOptions.getRegion())) .orElseGet(image::region);/*from w w w .j a v a2 s.com*/ // Prepare the VM(s) Optional<Boolean> optionalStaticPublicIP = options.map(Options::getStaticPublicIP); List<Creatable<VirtualMachine>> creatableVirtualMachines = prepareCreatableVirtualMachines(azureService, options, region, resourceGroup, instanceTag, instance, image, optionalStaticPublicIP); // Create all VMs in parallel and collect IDs return azureService.virtualMachines().create(creatableVirtualMachines).values().stream() .map(vm -> instance.withTag(vm.name()).withId(vm.vmId()).withNumber(SINGLE_INSTANCE_NUMBER)) .collect(Collectors.toSet()); }
From source file:com.cognifide.qa.bb.aem.ui.DialogFieldProvider.java
/** * Looks for DialogField annotation, reads locator data from the annotation instance * and asks AemDialogFieldResolver to produce a dialog field instance for the class field. */// w ww . ja v a 2 s . c o m @Override public Optional<Object> provideValue(Object pageObject, Field field, PageObjectContext context) { AemDialogFieldResolver aemDialogFieldResolver = fieldResolverProvider.get(); DialogField dialogFieldAnnotation = field.getAnnotation(DialogField.class); String searchBy; Class<?> type = field.getType(); Object dialogField = null; if (StringUtils.isNotEmpty(dialogFieldAnnotation.label())) { searchBy = dialogFieldAnnotation.label(); dialogField = aemDialogFieldResolver.getField(searchBy, type); } else if (StringUtils.isNotEmpty(dialogFieldAnnotation.css())) { searchBy = dialogFieldAnnotation.css(); dialogField = aemDialogFieldResolver.getFieldByCss(searchBy, type); } else if (StringUtils.isNotEmpty(dialogFieldAnnotation.name())) { searchBy = dialogFieldAnnotation.name(); dialogField = aemDialogFieldResolver.getFieldByName(searchBy, type); } else if (StringUtils.isNotEmpty(dialogFieldAnnotation.xpath())) { searchBy = dialogFieldAnnotation.xpath(); dialogField = aemDialogFieldResolver.getFieldByXpath(searchBy, type); } return Optional.ofNullable(dialogField); }
From source file:alfio.controller.api.admin.CheckInApiController.java
@RequestMapping(value = "/check-in/event/{eventName}/ticket/{ticketIdentifier}", method = GET) public TicketAndCheckInResult findTicketWithUUID(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, @RequestParam("qrCode") String qrCode) { return checkInManager.evaluateTicketStatus(eventName, ticketIdentifier, Optional.ofNullable(qrCode)); }
From source file:curly.artifact.ArtifactServiceImpl.java
@Loggable @Override//from ww w . ja v a2 s . co m @HystrixCommand(fallbackMethod = "defaultFindOne") public Observable<Optional<Artifact>> findOne(String id) { log.trace("Finding for {}", id); return new ObservableResult<Optional<Artifact>>() { @Override public Optional<Artifact> invoke() { return Optional.ofNullable(repository.findOne(id)); } }; }
From source file:com.example.app.profile.ui.user.UserPositionValueEditor.java
@Nullable @Override/*www .ja v a 2 s . co m*/ public UserPosition commitValue() throws MIWTException { UserPosition result = Optional.ofNullable(super.commitValue()) .orElseThrow(() -> new IllegalStateException("UserPosition was null. This should not happen.")); result.setUser(getUser()); return result; }
From source file:com.ibm.watson.catalyst.jumpqa.matcher.EntryPatterns.java
/** * Instantiates a new StringRegexMatcher * @param aTitlePattern the pattern to check the PAU Title for * @param aAnswerPattern the pattern to check the answer for * @param aTextPattern the pattern to check the candidate for * // w ww .j a v a2 s . c o m */ public EntryPatterns(final Pattern aTitlePattern, final Pattern aAnswerPattern, final Pattern aTextPattern) { _titlePattern = Optional.ofNullable(aTitlePattern); _answerPattern = Optional.ofNullable(aAnswerPattern); _textPattern = Optional.ofNullable(aTextPattern); }