boon/src/main/java/org/boon/sort/Sorting.java
public static int compare( Object value1, Object value2, boolean nullsLast ) {

        if ( value1 == null && value2 == null ) {
            return 0;
        } else if ( value1 == null && value2 != null ) {
            return nullsLast ? -1 : 1;
        } else if ( value1 != null && value2 == null ) {
            return nullsLast ? 1 : -1;
        }


        /** Objects are string like so compare using collator. */
        if ( value1 instanceof CharSequence ) {
            String str1 = Conversions.toString( value1 );
            String str2 = Conversions.toString( value2 );
            Collator collator = Collator.getInstance();
            return collator.compare( str1, str2 );

        /** Objects are comparable, yeah! */
        } else if ( Typ.isComparable( value1 ) && value1.getClass() == value2.getClass()) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        } else if (  value1 instanceof Integer && value2 instanceof Integer ) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        }
        else if (  value1 instanceof Double && value2 instanceof Double ) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        }
        else if (  value1 instanceof Long && value2 instanceof Long ) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        }
        else if (  value1 instanceof Number && value2 instanceof Number ) {
            Double c1 = Conversions.toDouble(value1);
            Double c2 = Conversions.toDouble(value2);
            return c1.compareTo( c2 );
        }
         else {
            /** Object are neither String like or comparable.
             * Ours it not to reason why, ours it to do or die.
             * Find the first sortable field and sort by that.
             * */
            String name = Fields.getSortableField( value1 );
            String sv1 = ( String ) BeanUtils.getPropByPath( value1, name );
            String sv2 = ( String ) BeanUtils.getPropByPath( value2, name );
            return Sorting.compare(sv1, sv2);

        }

    }
public static int compare( Object value1, Object value2, boolean nullsLast ) {

        if ( value1 == null && value2 == null ) {
            return 0;
        } else if ( value1 == null && value2 != null ) {
            return nullsLast ? -1 : 1;
        } else if ( value1 != null && value2 == null ) {
            return nullsLast ? 1 : -1;
        }


        /** Objects are string like so compare using collator. */
        if ( value1 instanceof CharSequence ) {
            String str1 = Conversions.toString( value1 );
            String str2 = Conversions.toString( value2 );
            Collator collator = Collator.getInstance();
            return collator.compare( str1, str2 );

        /** Objects are comparable, yeah! */
        } else if ( Typ.isComparable( value1 ) && value1.getClass() == value2.getClass()) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        } else if (  value1 instanceof Integer && value2 instanceof Integer ) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        }
        else if (  value1 instanceof Double && value2 instanceof Double ) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        }
        else if (  value1 instanceof Long && value2 instanceof Long ) {
            Comparable c1 = Conversions.comparable(value1);
            Comparable c2 = Conversions.comparable(value2);
            return c1.compareTo( c2 );
        }
        else if (  value1 instanceof Number && value2 instanceof Number ) {
            Double c1 = Conversions.toDouble(value1);
            Double c2 = Conversions.toDouble(value2);
            return c1.compareTo( c2 );
        }
         else {
            /** Object are neither String like or comparable.
             * Ours it not to reason why, ours it to do or die.
             * Find the first sortable field and sort by that.
             * */
            String name = Fields.getSortableField( value1 );
            String sv1 = ( String ) BeanUtils.getPropByPath( value1, name );
            String sv2 = ( String ) BeanUtils.getPropByPath( value2, name );
            return Sorting.compare(sv1, sv2);

        }

    }
public static int compare ( Object value1 , Object value2 , boolean nullsLast ) { if ( value1 == null && value2 == null ) { return 0 ; } else if ( value1 == null && value2 != null ) { return nullsLast ? - 1 : 1 ; } else if ( value1 != null && value2 == null ) { return nullsLast ? 1 : - 1 ; } /** Objects are string like so compare using collator. */ if ( value1 instanceof CharSequence ) { String str1 = Conversions . toString ( value1 ) ; String str2 = Conversions . toString ( value2 ) ; Collator collator = Collator . getInstance ( ) ; return collator . compare ( str1 , str2 ) ; /** Objects are comparable, yeah! */ } else if ( Typ . isComparable ( value1 ) && value1 . getClass ( ) == value2 . getClass ( ) ) { Comparable c1 = Conversions . comparable ( value1 ) ; Comparable c2 = Conversions . comparable ( value2 ) ; return c1 . compareTo ( c2 ) ; } else if ( value1 instanceof Integer && value2 instanceof Integer ) { Comparable c1 = Conversions . comparable ( value1 ) ; Comparable c2 = Conversions . comparable ( value2 ) ; return c1 . compareTo ( c2 ) ; } else if ( value1 instanceof Double && value2 instanceof Double ) { Comparable c1 = Conversions . comparable ( value1 ) ; Comparable c2 = Conversions . comparable ( value2 ) ; return c1 . compareTo ( c2 ) ; } else if ( value1 instanceof Long && value2 instanceof Long ) { Comparable c1 = Conversions . comparable ( value1 ) ; Comparable c2 = Conversions . comparable ( value2 ) ; return c1 . compareTo ( c2 ) ; } else if ( value1 instanceof Number && value2 instanceof Number ) { Double c1 = Conversions . toDouble ( value1 ) ; Double c2 = Conversions . toDouble ( value2 ) ; return c1 . compareTo ( c2 ) ; } else { /** Object are neither String like or comparable.
             * Ours it not to reason why, ours it to do or die.
             * Find the first sortable field and sort by that.
             * */ String name = Fields . getSortableField ( value1 ) ; String sv1 = ( String ) BeanUtils . getPropByPath ( value1 , name ) ; String sv2 = ( String ) BeanUtils . getPropByPath ( value2 , name ) ; return Sorting . compare ( sv1 , sv2 ) ; } }
This compares two values.
If the objects are strings (CharSequence) they are always compared lexicographically.
If the objects are comparable they are always compared using a natural order.

@param value1 value1
@param value2 value2
@param nullsLast put nulls last

@return
This compares two values . If the objects are strings ( CharSequence ) they are always compared lexicographically . If the objects are comparable they are always compared using a natural order .