/** * Provides a method that compares two comparables using Groovy's * default number aware comparator. * * @param self a Comparable * @param other another Comparable * @return a -ve number, 0 or a +ve number according to Groovy's compareTo contract * @since 1.6.0 */ public static int numberAwareCompareTo(Comparable self, Comparable other) { return COMPARABLE_NUMBER_AWARE_COMPARATOR.compare(self, other); }
public int compare(T object1, T object2) { for (Closure closure : closures) { Object value1 = closure.call(object1); Object value2 = closure.call(object2); int result; if (!equalityCheck || (value1 instanceof Comparable && value2 instanceof Comparable)) { result = numberAwareComparator.compare(value1, value2); } else { result = DefaultTypeTransformation.compareEqual(value1, value2) ? 0 : -1; } if (result == 0) continue; return result; } return 0; }
/** * Provides a method that compares two comparables using Groovy's * default number aware comparator. * * @param self a Comparable * @param other another Comparable * @return a -ve number, 0 or a +ve number according to Groovy's compareTo contract * @since 1.6.0 */ public static int numberAwareCompareTo(Comparable self, Comparable other) { NumberAwareComparator<Comparable> numberAwareComparator = new NumberAwareComparator<Comparable>(); return numberAwareComparator.compare(self, other); }
public int compare(T object1, T object2) { for (Closure closure : closures) { Object value1 = closure.call(object1); Object value2 = closure.call(object2); int result; if (!equalityCheck || (value1 instanceof Comparable && value2 instanceof Comparable)) { result = numberAwareComparator.compare(value1, value2); } else { result = DefaultTypeTransformation.compareEqual(value1, value2) ? 0 : -1; } if (result == 0) continue; return result; } return 0; }