- 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:- 1A
- 2A
- 10A
- 11A
- 11a
- 12
- B
- Author:
- AO Industries, Inc.
-
-
Field Summary
Fields Modifier and Type Field Description static SmartComparatorROOTThe smart comparator for the root locale.
-
Constructor Summary
Constructors Constructor Description SmartComparator()SmartComparator(Collator collator)SmartComparator(Locale locale)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(Object o1, Object o2)Compares two objects by theirObject.toString()values.intcompare(String s1, String s2)Compares two strings, supportingnull.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Field Detail
-
ROOT
public static final SmartComparator ROOT
The smart comparator for the root locale.
-
-
Method Detail
-
compare
public int compare(Object o1, Object o2)
Compares two objects by theirObject.toString()values.- Specified by:
comparein interfaceComparator<Object>- See Also:
Objects.toString(java.lang.Object, java.lang.String),compare(java.lang.Object, java.lang.Object)
-
compare
public int compare(String s1, String s2)
Compares two strings, supportingnull. Sorts nulls after non-nulls.This choice of nulls after non-nulls is selected to be consistent with PostgreSQL's default "NULLS LAST" ordering.
-
-