A Comparator which uses a closure to compare 2 values being equal
| 29 | * A Comparator which uses a closure to compare 2 values being equal |
| 30 | */ |
| 31 | public class ClosureComparator<T> implements Comparator<T>, Serializable { |
| 32 | |
| 33 | @Serial private static final long serialVersionUID = -4593521535656429522L; |
| 34 | |
| 35 | /** |
| 36 | * Closure used to compare two values. |
| 37 | */ |
| 38 | Closure closure; |
| 39 | |
| 40 | /** |
| 41 | * Creates a comparator backed by the supplied closure. |
| 42 | * |
| 43 | * @param closure the comparison closure |
| 44 | */ |
| 45 | public ClosureComparator(Closure closure) { |
| 46 | this.closure = closure; |
| 47 | } |
| 48 | |
| 49 | /** {@inheritDoc} */ |
| 50 | @Override |
| 51 | public int compare(T object1, T object2) { |
| 52 | Object value = closure.call(object1, object2); |
| 53 | return DefaultTypeTransformation.intUnbox(value); |
| 54 | } |
| 55 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…