Class SmartComparator

java.lang.Object
com.aoapps.lang.text.SmartComparator
All Implemented Interfaces:
Comparator<Object>

public class SmartComparator extends Object implements Comparator<Object>
Compares strings in a case-insensitive, locale-aware manner. Also supports integer ranges within the string so would be sorted in the following order:
  1. 1A
  2. 2A
  3. 10A
  4. 11A
  5. 11a
  6. 12
  7. B

Negative numbers are detected when at the beginning of the string or when preceded by any of:

  • Parenthetical: '(', '[', and '{'
  • Paths: '/' and '\\'
  • Lexical: ',', ';', and ':'
  • Comparisons: '=', '<', and '>'
  • Expressions: '|', '&', '^', '?', '+', '*', '%', '~', and '!'
  • Quotations: '\'', '"', '‘', '“', '«', and '‹'
  • Strings.isWhitespace(int)

Otherwise, the hyphen ('-') remains part of the string token.

Author:
AO Industries, Inc.