Class StringComparator

  • All Implemented Interfaces:
    java.util.Comparator

    public class StringComparator
    extends java.lang.Object
    implements java.util.Comparator
    A concrete implementation of Comparator that compares two strings. If a locale is specified then the comparison will be performed using the locale specific collating sequences. If the locale is not specified then a binary comparison will be performed.
    Version:
    $Revision: 1.3 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.text.Collator collator_  
      private boolean isAscending_  
      private java.util.Locale locale_  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringComparator​(java.util.Locale locale)
      Create a locale specific comparator.
      StringComparator​(java.util.Locale locale, int collatorStrength, boolean isAscending)
      Create a locale specific comparator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.Object object1, java.lang.Object object2)
      Compare the two strings.
      • 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

      • locale_

        private final java.util.Locale locale_
      • collator_

        private final java.text.Collator collator_
      • isAscending_

        private final boolean isAscending_
    • Constructor Detail

      • StringComparator

        public StringComparator​(java.util.Locale locale,
                                int collatorStrength,
                                boolean isAscending)
        Create a locale specific comparator.
        Parameters:
        locale - The locale to be used when determining sorting order. If locale is null then a binary comparison is performed.
        collatorStrength - The strength value to be used by the Collator. If locale is null then this value is ignored.
        isAscending - True if we are sorting in ascending order, false otherwise.
      • StringComparator

        public StringComparator​(java.util.Locale locale)
        Create a locale specific comparator.
        Parameters:
        locale - The locale to be used when determining sorting order. If locale is null then a binary comparison is performed.
    • Method Detail

      • compare

        public int compare​(java.lang.Object object1,
                           java.lang.Object object2)
        Compare the two strings.
        Specified by:
        compare in interface java.util.Comparator
        Parameters:
        object1 - The first string.
        object2 - The second string.
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.