List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:Main.java
/** * @param collectionOfCollection/*w w w . j a va2 s . co m*/ * a Collection<Collection<T>> * * @return a Set<T> containing all values of all Collections<T> * without any duplicates */ public static <T> Set<T> unionOfListOfLists( Collection<? extends Collection<? extends T>> collectionOfCollection) { return Optional.ofNullable(collectionOfCollection).map(Collection::stream).orElseGet(Stream::empty) .filter(Objects::nonNull).flatMap(x -> x.stream()).filter(Objects::nonNull).collect(toSet()); }
From source file:de.perdian.commons.lang.conversion.support.DelegatingConverter.java
protected DelegatingConverter(Converter<? super A, ? extends B> delegee) { this.setDelegee(Optional.ofNullable(delegee) .orElseThrow(() -> new IllegalArgumentException("Parameter 'delegee' must not be null"))); }
From source file:net.hamnaberg.json.Link.java
public static Link create(URI href, String rel, Optional<String> prompt, Optional<String> name, Optional<Render> render) { ObjectNode node = JsonNodeFactory.instance.objectNode(); node.put("href", Optional.ofNullable(href) .orElseThrow(() -> new IllegalArgumentException("Href may not be null")).toString()); node.put("rel", Optional.ofNullable(rel) .orElseThrow(() -> new IllegalArgumentException("Relation may not be null"))); prompt.ifPresent(value -> node.put("prompt", value)); render.ifPresent(value -> node.put("render", value.getName())); name.ifPresent(value -> node.put("name", value)); return new Link(node); }
From source file:com.asakusafw.runtime.stage.launcher.Util.java
private static List<File> list(File file) { return Optional.ofNullable(file.listFiles()).map(Arrays::asList).orElse(Collections.emptyList()); }
From source file:co.runrightfast.vertx.core.eventbus.MessageHeader.java
public static Optional<String> getCorrelationId(@NonNull final Message message) { return Optional.ofNullable(message.headers().get(MESSAGE_CORRELATION_ID.header)); }
From source file:com.teradata.benchto.service.rest.requests.GetTagsRequest.java
public Optional<ZonedDateTime> getEnd() { return Optional.ofNullable(end); }
From source file:org.trustedanalytics.serviceinfo.MqttServiceInfoCreator.java
@Override public boolean accept(Map<String, Object> serviceData) { Optional<String> label = Optional.ofNullable((String) serviceData.get("label")); if (label.isPresent()) { return label.get().equals(MQTT_ID); }/* w w w.j a va 2 s . c o m*/ return false; }
From source file:alfio.controller.support.SessionUtil.java
public static Optional<String> retrievePromotionCodeDiscount(HttpServletRequest request) { return Optional.ofNullable((String) request.getSession().getAttribute(PROMOTIONAL_CODE_DISCOUNT)); }
From source file:de.perdian.commons.lang.conversion.support.DefaultWhenNullConverter.java
@Override public B convert(A source) { return Optional.ofNullable(super.convert(source)).orElseGet(this::getDefaultResult); }
From source file:com.teradata.benchto.service.rest.requests.GetTagsRequest.java
public Optional<ZonedDateTime> getStart() { return Optional.ofNullable(start); }