T
- see Comparator
@FunctionalInterface public interface OptionalComparator<T>
Comparator
that returns OptionalInt
instead of the raw value. OptionalComparator
is typically obtained from ExceptionHandler.comparator(Comparator)
, in which case its return value is empty when the underlying Comparator
throws an exception. See noexception tutorial.
Modifier and Type | Method and Description |
---|---|
OptionalInt |
compare(T left, T right)
Variation of Comparator.compare(Object, Object) that returns OptionalInt .
|
default Comparator<T> |
orElse(int result)
Converts this OptionalComparator to plain Comparator using default value.
|
default Comparator<T> |
orElseGet(IntSupplier source)
|
OptionalInt compare(T left, T right)
Comparator.compare(Object, Object)
that returns OptionalInt
. If this OptionalComparator
is obtained from ExceptionHandler.comparator(Comparator)
, the OptionalInt
will be empty only if the underlying Comparator
throws. Otherwise the returned OptionalInt
just wraps the return value of underlying Comparator
.
left
- see Comparator.compare(Object, Object)
right
- see Comparator.compare(Object, Object)
OptionalInt
typically wrapping return value of Comparator.compare(Object, Object)
, or an empty OptionalInt
(typically signifying an exception)
ExceptionHandler.comparator(Comparator)
, Comparator.compare(Object, Object)
default Comparator<T> orElse(int result)
OptionalComparator
to plain Comparator
using default value. The returned Comparator
will unwrap present value from the OptionalInt
if possible, or return result
if the OptionalInt
is empty.
result
- default value to return instead of an empty OptionalInt
Comparator
that either unwraps OptionalInt
or returns default value
orElseGet(IntSupplier)
, OptionalInt.orElse(int)
default Comparator<T> orElseGet(IntSupplier source)
OptionalComparator
to plain Comparator
using fallback IntSupplier
. The returned Comparator
will unwrap present value from the OptionalInt
if possible, or fall back to calling source
if the OptionalInt
is empty.
source
- IntSupplier
to query for fallback value when OptionalInt
is empty
Comparator
that either unwraps OptionalInt
or falls back to source
orElse(int)
, OptionalInt.orElseGet(IntSupplier)
Copyright © 2017–2020 Robert Važan. All rights reserved.