List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:org.openwms.common.HttpCommonGateway.java
@Override public Optional<Location> getLocation(String target) { return Optional.ofNullable(commonFeignClient.getLocation(target)); }
From source file:org.trustedanalytics.servicecatalog.service.rest.ServiceInstancesControllerHelpers.java
public void mergeInstances(Collection<Service> services, Collection<ServiceInstance> instances) { Map<UUID, List<ServiceInstance>> instancesIndex = createInstancesIndex(instances); services.stream().forEach(b -> b/*from ww w.j a v a2 s .co m*/ .setInstances(Optional.ofNullable(instancesIndex.get(b.getGuid())).orElse(new ArrayList<>()))); }
From source file:de.codesourcery.spring.contextrewrite.AnnotationParser.java
/** * Parse rewrite annotations.// w ww.j a v a 2 s . c o m * * @param clazz class whose annotations should be parsed. This method will also parse parent classes and merge any rewriting annotations it encounters * according to the rules described in {@link RewriteConfig#getRules()}. * * @return rewriting configuration * @throws NoSuchElementException if neither the input class nor any of its parents had a {@link ContextConfiguration} annotation. */ public RewriteConfig parse(Class<?> clazz) throws NoSuchElementException { Validate.notNull(clazz, "clazz must not be NULL"); RewriteConfig first = null; RewriteConfig previous = null; Class<?> currentClass = clazz; while (currentClass != Object.class) { final Optional<ContextConfiguration> ctxConfiguration = Optional .ofNullable(currentClass.getAnnotation(ContextConfiguration.class)); final RewriteConfig config = new RewriteConfig(currentClass); if (ctxConfiguration.isPresent()) { config.setContextPath(ctxConfiguration.get().value()); config.setDebug(ctxConfiguration.get().debug()); config.setDumpXML(ctxConfiguration.get().dumpRewrittenXML()); } config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(ReplaceRule.class))); config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(RemoveRule.class))); config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(InsertElementRule.class))); config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(InsertAttributeRule.class))); if (ctxConfiguration.isPresent() || config.hasRules()) { if (previous != null) { previous.setParent(config); } previous = config; if (first == null) { first = config; } } currentClass = currentClass.getSuperclass(); } if (first == null) { throw new NoSuchElementException("Found no @" + ContextConfiguration.class.getName() + " annotation on " + clazz.getName() + " or any of its super classes"); } return first; }
From source file:alfio.model.modification.AdminReservationModification.java
@JsonCreator public AdminReservationModification(@JsonProperty("expiration") DateTimeModification expiration, @JsonProperty("customerData") CustomerData customerData, @JsonProperty("ticketsInfo") List<TicketsInfo> ticketsInfo, @JsonProperty("language") String language, @JsonProperty("updateContactData") boolean updateContactData, @JsonProperty("notification") Notification notification) { this.expiration = expiration; this.customerData = customerData; this.ticketsInfo = ticketsInfo; this.language = language; this.updateContactData = Optional.ofNullable(updateContactData).orElse(false); this.notification = notification; }
From source file:de.is24.aws.instancemetadataserver.RemoteHostRoleNameProducer.java
private Optional<String> stripHostNr(String rawHostName) { Matcher matcher = Pattern.compile("^([a-zA-Z]+)[0-9]+$").matcher(rawHostName); if (!matcher.find()) { return Optional.empty(); }/* w ww . j a va 2 s . c o m*/ return Optional.ofNullable(matcher.group(1)); }
From source file:feign.ranger.client.ServiceDiscoveryClient.java
public Optional<ServiceNode<ShardInfo>> getNode() { return Optional.ofNullable(serviceFinder.get(criteria)); }
From source file:fi.helsinki.opintoni.security.authorization.portfolio.PortfolioRequestResolver.java
private Optional<PortfolioDto> getPortfolioDtoById(Map<String, String> templateVariables) { return Optional.ofNullable(portfolioService.findById(Long.valueOf(templateVariables.get("portfolioId")))); }
From source file:io.curly.advisor.command.ReviewHystrixCommands.java
@HystrixCommand public Observable<Optional<Review>> findByOwner(final User user, final String id) { return new ObservableResult<Optional<Review>>() { @Override/*from w w w . ja v a 2 s . c o m*/ public Optional<Review> invoke() { return Optional.ofNullable(repository.findByIdAndOwner(id, user.getId())); } }; }
From source file:com.ikanow.aleph2.example.flume_harvester.utils.FlumeUtils.java
/** Utility to get the list of spool dirs * @param bucket_config/*from w ww .java 2 s. c om*/ * @return */ public static Collection<SpoolDirConfig> getSpoolDirs(final FlumeBucketConfigBean bucket_config) { final Collection<SpoolDirConfig> dirs = Optional.ofNullable(bucket_config.input()) .map(i -> Optionals.ofNullable(i.spool_dirs())).orElse(Collections.emptyList()).stream() .filter(SpoolDirConfig::enabled) // (defaults to true) .collect(Collectors.toList()); return dirs; }
From source file:info.magnolia.vaadin.periscope.result.Result.java
public Optional<String> getIcon() { return Optional.ofNullable(icon); }