List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:org.rapidpm.microservice.optionals.service.ServiceWrapper.java
private static void startMicroservice(String[] args) { checkPortFileExists(); deploy(Optional.ofNullable(args)); writeRestPortToFile(); }
From source file:com.ikanow.aleph2.core.shared.utils.TimeSliceDirUtils.java
/** Given a pair of (optional) human readable strings (which are assumed to refer to the past) * returns a pair of optional dates/*from w w w.jav a 2s. com*/ * @param input_config * @return */ public static Tuple2<Optional<Date>, Optional<Date>> getQueryTimeRange( final AnalyticThreadJobInputConfigBean input_config, final Date now) { Function<Optional<String>, Optional<Date>> parseDate = maybe_date -> maybe_date .map(datestr -> TimeUtils.getSchedule(datestr, Optional.of(now))).filter(res -> res.isSuccess()) .map(res -> res.success()) // OK so this wants to be backwards in time always... .map(date -> { if (date.getTime() > now.getTime()) { final long diff = date.getTime() - now.getTime(); return Date.from(now.toInstant().minusMillis(diff)); } else return date; }); final Optional<Date> tmin = parseDate.apply(Optional.ofNullable(input_config.time_min())); final Optional<Date> tmax = parseDate.apply(Optional.ofNullable(input_config.time_max())); return Tuples._2T(tmin, tmax); }
From source file:me.ferrybig.javacoding.webmapper.requests.JSONSessionProvider.java
@Override public EndpointResult<?> handleHttpRequest(WebServerRequest req) throws RouteException { Optional<JSONObject> data = req.getDataAs(JSONObject.class); LazySessionSupplier s = new LazySessionSupplier(() -> sessions.findOrCreateSession( Optional.ofNullable(data.orElseGet(JSONObject::new).optString("session", null)))); req.setSessionSupplier(s);//from www . j a va 2 s . c o m EndpointResult<?> upper = upstream.handleHttpRequest(req); if (upper.getContentType() == JSON) { JSONObject obj = (JSONObject) upper.getData(); obj.put("session", s.getSession().getKey()); return new EndpointResult<>(upper.getResult(), obj, JSON); } return upper; }
From source file:com.tesobe.obp.transport.json.RequestDecoder.java
@Override public Optional<Transport.Target> target() { return Optional.ofNullable(json.optEnum(Transport.Target.class, "target", null)); }
From source file:com.kazuki43zoo.jpetstore.service.CatalogService.java
public Category getCategory(String categoryId) { return Optional.ofNullable(categoryMapper.getCategory(categoryId)) .orElseThrow(() -> new ResourceNotFoundException("Category", categoryId)); }
From source file:org.zalando.riptide.Actions.java
/** * Normalizes the {@code Location} and {@code Content-Location} headers of any given response by resolving them * against the given {@code uri}./* w w w .j av a2 s. c o m*/ * * @param uri the base uri to resolve against * @return a function that normalizes responses */ public static ThrowingFunction<ClientHttpResponse, ClientHttpResponse, IOException> normalize(final URI uri) { return response -> { final HttpHeaders headers = new HttpHeaders(); headers.putAll(response.getHeaders()); Optional.ofNullable(headers.getLocation()).map(uri::resolve).ifPresent(headers::setLocation); Optional.ofNullable(headers.getFirst(CONTENT_LOCATION)).map(uri::resolve) .ifPresent(location -> headers.set(CONTENT_LOCATION, location.toASCIIString())); return new ForwardingClientHttpResponse() { @Override protected ClientHttpResponse delegate() { return response; } @Override public HttpHeaders getHeaders() { return headers; } }; }; }
From source file:com.speedment.examples.social.JSONUser.java
private static String mapToString(JSONObject user, String key) { return Optional.ofNullable(user.get(key)).map(Object::toString).orElse(""); }
From source file:io.smalldata.ohmageomh.data.domain.EndUser.java
public Optional<InternetAddress> getEmailAddress() { return Optional.ofNullable(emailAddress); }
From source file:org.ow2.proactive.connector.iaas.service.ImageService.java
public Set<Image> getAllImages(String infrastructureId) { return Optional.ofNullable(infrastructureService.getInfrastructure(infrastructureId)) .map(infrastructure -> cloudManager.getAllImages(infrastructure)) .orElseThrow(() -> new NotFoundException( "infrastructure id : " + infrastructureId + " does not exists")); }
From source file:io.mapzone.arena.csw.catalog.CswMetadataDCMI.java
@Override public Optional<String> getDescription() { return Optional.ofNullable(record().description); }