Class OptionalComparator
Object
OptionalComparator
Creates a
Comparator that can work with Optionals.
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 aComparatorfor elements of typeTwhere empty-values are first.static <T extends Comparable<T>>
Comparator<Optional<T>> Creates aComparatorfor elements of typeTwhere empty-values are last.
-
Method Details
-
emptyFirstComparator
Creates aComparatorfor elements of typeTwhere empty-values are first.Inspired by this Stack Overflow post by Anderson Vieira.
- Type Parameters:
T- element-type (withoutOptional.- Returns:
- the comparator.
-
emptyLastComparator
Creates aComparatorfor elements of typeTwhere empty-values are last.- Type Parameters:
T- element-type (withoutOptional.- Returns:
- the comparator.
-