Package org.n52.janmayen
Class Optionals
- java.lang.Object
-
- org.n52.janmayen.Optionals
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanany(Iterable<Optional<?>> optionals)Checks if any of the optionals is present.static booleanany(Optional<?>... optionals)Checks if any of the optionals is present.static booleanany(Stream<Optional<?>> optionals)Checks if any of the optionals is present.static <U> Optional<U>ifPresentOrElse(Optional<U> optional, Consumer<U> consumer, Runnable ifNotPresent)Feeds {code optional}'s value toconsumerif it is present or else runsifNotPresent.static <U,T>
Optional<U>mapOrElse(Optional<T> optional, Function<? super T,? extends U> mapper, Runnable ifNotPresent)Maps theoptionalusingmapperif it is present or runsifNotPresent.static <U extends Comparable<? super U>>
Comparator<Optional<U>>nullsFirst()Creates a comparator to sort by the optional's value,nulls first.static <U> Comparator<Optional<U>>nullsFirst(Comparator<? super U> comparator)Creates a comparator wrappingcomparatorto sort by the optional's value,nulls first.static <U extends Comparable<? super U>>
Comparator<Optional<U>>nullsLast()Creates a comparator to sort by the optional's value,nulls last.static <U> Comparator<Optional<U>>nullsLast(Comparator<? super U> comparator)Creates a comparator wrappingcomparatorto sort by the optional's value,nulls last.static <U> Optional<U>or(Supplier<Optional<U>>... optionals)Gets the first value of the first optional that is present.static <U> Optional<U>or(Optional<U>... optionals)Gets the first value of the first optional that is present.static <U> Optional<U>or(Optional<U> a, Supplier<Optional<U>> b)Gets the value ofaif it is present or else the value ofb.static <U> Optional<U>or(Optional<U> a, Optional<U> b)Gets the value ofaif it is present or else the value ofb.static <U> Optional<U>or(Stream<Supplier<Optional<U>>> optionals)Gets the first value of the first optional that is present.static <U> UorElseNull(Optional<U> optional)Gets the value ofoptionalif it is present,nullotherwise.
-
-
-
Method Detail
-
any
public static boolean any(Optional<?>... optionals)
Checks if any of the optionals is present.- Parameters:
optionals- the optionals- Returns:
- if at least one is present
-
any
public static boolean any(Iterable<Optional<?>> optionals)
Checks if any of the optionals is present.- Parameters:
optionals- the optionals- Returns:
- if at least one is present
-
any
public static boolean any(Stream<Optional<?>> optionals)
Checks if any of the optionals is present.- Parameters:
optionals- the optionals- Returns:
- if at least one is present
-
nullsLast
public static <U> Comparator<Optional<U>> nullsLast(Comparator<? super U> comparator)
Creates a comparator wrappingcomparatorto sort by the optional's value,nulls last.- Type Parameters:
U- the optional's type- Parameters:
comparator- the comparator- Returns:
- the new comparator
-
nullsLast
public static <U extends Comparable<? super U>> Comparator<Optional<U>> nullsLast()
Creates a comparator to sort by the optional's value,nulls last.- Type Parameters:
U- the optional's type- Returns:
- the new comparator
-
nullsFirst
public static <U> Comparator<Optional<U>> nullsFirst(Comparator<? super U> comparator)
Creates a comparator wrappingcomparatorto sort by the optional's value,nulls first.- Type Parameters:
U- the optional's type- Parameters:
comparator- the comparator- Returns:
- the new comparator
-
nullsFirst
public static <U extends Comparable<? super U>> Comparator<Optional<U>> nullsFirst()
Creates a comparator to sort by the optional's value,nulls first.- Type Parameters:
U- the optional's type- Returns:
- the new comparator
-
orElseNull
public static <U> U orElseNull(Optional<U> optional)
Gets the value ofoptionalif it is present,nullotherwise.- Type Parameters:
U- the optional's type- Parameters:
optional- the optional- Returns:
- the optional's value or
null
-
ifPresentOrElse
public static <U> Optional<U> ifPresentOrElse(Optional<U> optional, Consumer<U> consumer, Runnable ifNotPresent)
Feeds {code optional}'s value toconsumerif it is present or else runsifNotPresent.- Type Parameters:
U- the optional's type- Parameters:
optional- the optionalconsumer- the consumerifNotPresent- the runnable- Returns:
- the optional
-
mapOrElse
public static <U,T> Optional<U> mapOrElse(Optional<T> optional, Function<? super T,? extends U> mapper, Runnable ifNotPresent)
Maps theoptionalusingmapperif it is present or runsifNotPresent.- Type Parameters:
T- the resulting optional's typeU- the optional's type- Parameters:
optional- the optinalmapper- the mapperifNotPresent- the runnable- Returns:
- the new optional
-
or
public static <U> Optional<U> or(Optional<U> a, Supplier<Optional<U>> b)
Gets the value ofaif it is present or else the value ofb.- Type Parameters:
U- the optional's type- Parameters:
a- the first optionalb- a supplier for the second optional- Returns:
- the value
-
or
public static <U> Optional<U> or(Optional<U> a, Optional<U> b)
Gets the value ofaif it is present or else the value ofb.- Type Parameters:
U- the optional's type- Parameters:
a- the first optionalb- a the second optional- Returns:
- the value
-
or
@SafeVarargs public static <U> Optional<U> or(Optional<U>... optionals)
Gets the first value of the first optional that is present.- Type Parameters:
U- the optional's type- Parameters:
optionals- the optionals- Returns:
- the first present value
-
or
@SafeVarargs public static <U> Optional<U> or(Supplier<Optional<U>>... optionals)
Gets the first value of the first optional that is present.- Type Parameters:
U- the optional's type- Parameters:
optionals- the optionals- Returns:
- the first present value
-
-