Class CaseFirstCollator

  • All Implemented Interfaces:
    java.io.Serializable, StringCollator

    public class CaseFirstCollator
    extends java.lang.Object
    implements StringCollator, java.io.Serializable
    A StringCollator that sorts lowercase before uppercase, or vice versa.

    Case is irrelevant, unless the strings are equal ignoring case, in which case lowercase comes first.

    Author:
    Michael H. Kay
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean comparesEqual​(java.lang.String s1, java.lang.String s2)
      Compare two strings for equality.
      int compareStrings​(java.lang.String a, java.lang.String b)
      Compare two string objects: case is irrelevant, unless the strings are equal ignoring case, in which case lowercase comes first.
      java.lang.Object getCollationKey​(java.lang.String s)
      Get a collation key for two Strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CaseFirstCollator

        public CaseFirstCollator​(StringCollator base,
                                 boolean upperFirst)
        Create a CaseFirstCollator
        Parameters:
        base - the base collator, which determines how characters are sorted irrespective of case
        upperFirst - true if uppercase precedes lowercase, false otherwise
    • Method Detail

      • compareStrings

        public int compareStrings​(java.lang.String a,
                                  java.lang.String b)
        Compare two string objects: case is irrelevant, unless the strings are equal ignoring case, in which case lowercase comes first.
        Specified by:
        compareStrings in interface StringCollator
        Parameters:
        a - the first string
        b - the second string
        Returns:
        <0 if a0 if a>b
        Throws:
        java.lang.ClassCastException - if the objects are of the wrong type for this Comparer
      • comparesEqual

        public boolean comparesEqual​(java.lang.String s1,
                                     java.lang.String s2)
        Compare two strings for equality. This may be more efficient than using compareStrings and testing whether the result is zero, but it must give the same result
        Specified by:
        comparesEqual in interface StringCollator
        Parameters:
        s1 - the first string
        s2 - the second string
        Returns:
        true if and only if the strings are considered equal,
      • getCollationKey

        public java.lang.Object getCollationKey​(java.lang.String s)
        Get a collation key for two Strings. The essential property of collation keys is that if two values are equal under the collation, then the collation keys are compare correctly under the equals() method.
        Specified by:
        getCollationKey in interface StringCollator
        Parameters:
        s - the string whose collation key is required
        Returns:
        the collation key