public static < T > Comparator < T > arrayComparator ( Class < T > arrayType , boolean unsigned ) { if ( ! arrayType . isArray ( ) ) { throw new IllegalArgumentException ( ) ; } Comparator c ; TypeDesc componentType = TypeDesc . forClass ( arrayType . getComponentType ( ) ) ; switch ( componentType . getTypeCode ( ) ) { case TypeDesc . BYTE_CODE : c = unsigned ? UnsignedByteArray : SignedByteArray ; break ; case TypeDesc . SHORT_CODE : c = unsigned ? UnsignedShortArray : SignedShortArray ; break ; case TypeDesc . INT_CODE : c = unsigned ? UnsignedIntArray : SignedIntArray ; break ; case TypeDesc . LONG_CODE : c = unsigned ? UnsignedLongArray : SignedLongArray ; break ; case TypeDesc . BOOLEAN_CODE : c = BooleanArray ; break ; case TypeDesc . CHAR_CODE : c = CharArray ; break ; case TypeDesc . FLOAT_CODE : c = FloatArray ; break ; case TypeDesc . DOUBLE_CODE : c = DoubleArray ; break ; case TypeDesc . OBJECT_CODE : default : if ( componentType . isArray ( ) ) { c = new ComparatorArray ( arrayComparator ( componentType . toClass ( ) , unsigned ) ) ; } else if ( Comparable . class . isAssignableFrom ( componentType . toClass ( ) ) ) { c = ComparableArray ; } else { c = null ; } break ; } return ( Comparator < T > ) c ; }
Returns a comparator which can sort single or multi - dimensional arrays of primitves or Comparables .