Class CollatorComparator

All Implemented Interfaces:
Direct Known Subclasses:

public class CollatorComparator
extends java.lang.Object
implements java.util.Comparator<java.lang.String>
A comparator that sorts Strings using a Collator. This class is needed because, even though Collator implements Comparator<Object> and the required compare(String, String) method, you can't safely cast Collator to Comparator<String>.
  • Field Summary

    Modifier and Type Field Description
    static java.util.Comparator<java.lang.String> DEFAULT_LOCALE_COMPARATOR  
    protected java.text.Collator m_collator  
  • Constructor Summary

    Constructor Description
    Default constructor uses the current locale's collator.
    CollatorComparator​(java.text.Collator collator)
    Construct with a specific collator.
  • Method Summary

    Modifier and Type Method Description
    int compare​(java.lang.String str1, java.lang.String str2)  
    void setCollator​(java.text.Collator collator)
    Specify a new collator.

    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 Details

  • Constructor Details

    • CollatorComparator

      Default constructor uses the current locale's collator.
    • CollatorComparator

      public CollatorComparator​(java.text.Collator collator)
      Construct with a specific collator.
      collator - the collator to be used for comparisons
  • Method Details

    • compare

      public int compare​(java.lang.String str1, java.lang.String str2)
      Specified by:
      compare in interface java.util.Comparator<java.lang.String>
    • setCollator

      public void setCollator​(java.text.Collator collator)
      Specify a new collator.
      collator - the collator to be used from now on