A helper class for sorting objects via a closure to return the field or operation on which to sort.
| 33 | * or operation on which to sort. |
| 34 | */ |
| 35 | public class OrderBy<T> implements Comparator<T>, Serializable { |
| 36 | |
| 37 | @Serial private static final long serialVersionUID = 8385130064804116654L; |
| 38 | private final List<Closure> closures; |
| 39 | private boolean equalityCheck; |
| 40 | private final NumberAwareComparator<Object> numberAwareComparator = new NumberAwareComparator<Object>(); |
| 41 | |
| 42 | /** |
| 43 | * Creates an ordering with no comparison closures. |
| 44 | */ |
| 45 | public OrderBy() { |
| 46 | this(new ArrayList<Closure>(), false); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Creates an ordering with no comparison closures. |
| 51 | * |
| 52 | * @param equalityCheck whether equality-only comparison should be used for non-comparable values |
| 53 | */ |
| 54 | public OrderBy(boolean equalityCheck) { |
| 55 | this(new ArrayList<Closure>(), equalityCheck); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Creates an ordering using a single comparison closure. |
| 60 | * |
| 61 | * @param closure the comparison closure |
| 62 | */ |
| 63 | public OrderBy(Closure closure) { |
| 64 | this(closure, false); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates an ordering using a single comparison closure. |
| 69 | * |
| 70 | * @param closure the comparison closure |
| 71 | * @param equalityCheck whether equality-only comparison should be used for non-comparable values |
| 72 | */ |
| 73 | public OrderBy(Closure closure, boolean equalityCheck) { |
| 74 | this(new ArrayList<Closure>(), equalityCheck); |
| 75 | closures.add(closure); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Creates an ordering using the supplied comparison closures. |
| 80 | * |
| 81 | * @param closures the comparison closures |
| 82 | */ |
| 83 | public OrderBy(List<Closure> closures) { |
| 84 | this(closures, false); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Creates an ordering using the supplied comparison closures. |
| 89 | * |
| 90 | * @param closures the comparison closures |
| 91 | * @param equalityCheck whether equality-only comparison should be used for non-comparable values |
| 92 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…