Class OptionalComparator
Object
OptionalComparator
Creates a
Comparator
that can work with Optional
s.
An Optional.empty()
value can be eithered first or last.
- Author:
- Owen Feehan
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
Comparator<Optional<T>> Creates aComparator
for elements of typeT
where empty-values are first.static <T extends Comparable<T>>
Comparator<Optional<T>> Creates aComparator
for elements of typeT
where empty-values are last.
-
Method Details
-
emptyFirstComparator
Creates aComparator
for elements of typeT
where empty-values are first.Inspired by this Stack Overflow post by Anderson Vieira.
- Type Parameters:
T
- element-type (withoutOptional
.- Returns:
- the comparator.
-
emptyLastComparator
Creates aComparator
for elements of typeT
where empty-values are last.- Type Parameters:
T
- element-type (withoutOptional
.- Returns:
- the comparator.
-