
org.mapfish.print.OptionalUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of print-lib Show documentation
Show all versions of print-lib Show documentation
Library for generating PDFs and images from online webmapping services
package org.mapfish.print;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Supplier;
/**
* Utilities for Java's Optional class.
*/
public final class OptionalUtils {
private OptionalUtils() {
}
/**
* Return the first optional to be defined.
*
* @param a The first
* @param b The second
* @param The type
* @return a or b or empty
*/
@SuppressWarnings("unchecked")
public static Optional or(final Optional a, final Optional extends T> b) {
return a.isPresent() ? a : (Optional) b;
}
/**
* Return the first optional to be defined.
*
* @param optionals the lambdas returning the optionals
* @param The type
* @return the first non-empty or empty
*/
@SuppressWarnings("unchecked")
@SafeVarargs
public static Optional or(final Supplier>... optionals) {
return (Optional) Arrays.stream(optionals)
.map(Supplier::get)
.filter(Optional::isPresent)
.findFirst()
.orElseGet(Optional::empty);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy