public static Integer compareTo(Object left, Object right) { int answer = DefaultTypeTransformation.compareTo(left, right); if (answer == 0) { return ZERO; } else { return answer > 0 ? ONE : MINUS_ONE; } }
public int compare(T o1, T o2) { try { return DefaultTypeTransformation.compareTo(o1, o2); } catch (ClassCastException | IllegalArgumentException | GroovyRuntimeException cce) { /* ignore */ } // since the object does not have a valid compareTo method // we compare using the hashcodes. null cases are handled by // DefaultTypeTransformation.compareTo // This is not exactly a mathematical valid approach, since we compare object // that cannot be compared. To avoid strange side effects we do a pseudo order // using hashcodes, but without equality. Since then an x and y with the same // hashcodes will behave different depending on if we compare x with y or // x with y, the result might be unstable as well. Setting x and y to equal // may mean the removal of x or y in a sorting operation, which we don't want. int x1 = o1.hashCode(); int x2 = o2.hashCode(); if (x1 == x2 && o1.equals(o2)) return 0; if (x1 > x2) return 1; return -1; } }
public static Integer compareTo(Object left, Object right) { int answer = DefaultTypeTransformation.compareTo(left, right); if (answer == 0) { return ZERO; } else { return answer > 0 ? ONE : MINUS_ONE; } }
public static Integer compareTo(Object left, Object right) { int answer = DefaultTypeTransformation.compareTo(left, right); if (answer == 0) { return ZERO; } else { return answer > 0 ? ONE : MINUS_ONE; } }
public static Integer compareTo(Object left, Object right) { int answer = DefaultTypeTransformation.compareTo(left, right); if (answer == 0) { return ZERO; } else { return answer > 0 ? ONE : MINUS_ONE; } }
public static Integer compareTo(Object left, Object right) { int answer = DefaultTypeTransformation.compareTo(left, right); if (answer == 0) { return ZERO; } else { return answer > 0 ? ONE : MINUS_ONE; } }
public int compare(Object o1, Object o2) { try { return DefaultTypeTransformation.compareTo(o1, o2); } catch (ClassCastException cce) { } catch (GroovyRuntimeException gre) {} int x1 = o1.hashCode(); int x2 = o2.hashCode(); return (x1 - x2); }
public int compare(Object o1, Object o2) { try { return DefaultTypeTransformation.compareTo(o1, o2); } catch (ClassCastException cce) { } catch (GroovyRuntimeException gre) {} // since the object does not have a valid compareTo method // we compare using the hashcodes. null cases are handled by // DefaultTypeTransformation.compareTo int x1 = o1.hashCode(); int x2 = o2.hashCode(); if (x1==x2) return 0; if (x1<x2) return -1; return 1; }
public int compare(T o1, T o2) { try { return DefaultTypeTransformation.compareTo(o1, o2); } catch (ClassCastException cce) { } catch (GroovyRuntimeException gre) {} // since the object does not have a valid compareTo method // we compare using the hashcodes. null cases are handled by // DefaultTypeTransformation.compareTo int x1 = o1.hashCode(); int x2 = o2.hashCode(); if (x1==x2) return 0; if (x1<x2) return -1; return 1; } }
public int compare(T o1, T o2) { try { return DefaultTypeTransformation.compareTo(o1, o2); } catch (ClassCastException cce) { /* ignore */ } catch (GroovyRuntimeException gre) { /* ignore */ } // since the object does not have a valid compareTo method // we compare using the hashcodes. null cases are handled by // DefaultTypeTransformation.compareTo int x1 = o1.hashCode(); int x2 = o2.hashCode(); if (x1 == x2) return 0; if (x1 < x2) return -1; return 1; } }