Package de.xima.fc.utils
Class XComparisonUtils
java.lang.Object
de.xima.fc.utils.XComparisonUtils
Utilities for
Comparator
and Comparable
.- Since:
- 2.1.0
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Comparator<T>
comparingInStages
(Comparator<T>... stages) Creates a comparator that compares items in stages.static <T extends Comparable<T>>
TconstrainToRange
(T value, T min, T max) Constrains a comparable value to a range.static <T extends Comparable<T>>
TconstrainToRange
(T value, T min, T max, T defaultValue) Constrains a comparable value to a range.
-
Method Details
-
comparingInStages
Creates a comparator that compares items in stages. Compared to building the comparator viaComparator.thenComparing(Comparator)
, this method better support type parameter inference.- Type Parameters:
T
- Type of the items.- Parameters:
stages
- Stages by which to compare.- Returns:
- A comparator that compares first by the first comparator, then by the second comparator if they are equal, then by the third comparator etc.
-
constrainToRange
Constrains a comparable value to a range.- Type Parameters:
T
- Type of the value.- Parameters:
value
- Value to constrain.min
- Minimum value.max
- Maximum value.- Returns:
- The value if it is within the range, the minimum value if it is below the range, the maximum value if it is above the range.
-
constrainToRange
Constrains a comparable value to a range.- Type Parameters:
T
- Type of the value.- Parameters:
value
- Value to constrain.min
- Minimum value.max
- Maximum value.defaultValue
- Default value if the value is null.- Returns:
- The value if it is within the range, the minimum value if it is below the range, the maximum value if it is above the range, and the default value if the value is null.
-