Class SimpleCollation

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

    public class SimpleCollation
    extends java.lang.Object
    implements StringCollator
    A simple collation that just wraps a suppled Comparator
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleCollation​(java.util.Comparator collation)
      Create a SimpleCollation
    • 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 o1, java.lang.String o2)
      Compares its two arguments for order.
      java.util.Comparator getCollation()
      Get the underlying comparator
      java.lang.Object getCollationKey​(java.lang.String s)
      Get a collation key for two Strings.
      void setCollation​(java.util.Comparator collation)
      Set the underlying comparator
      • Methods inherited from class java.lang.Object

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

      • SimpleCollation

        public SimpleCollation​(java.util.Comparator collation)
        Create a SimpleCollation
        Parameters:
        collation - the Comparator that does the actual string comparison
    • Method Detail

      • compareStrings

        public int compareStrings​(java.lang.String o1,
                                  java.lang.String o2)
        Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

        Specified by:
        compareStrings in interface StringCollator
        Parameters:
        o1 - the first object to be compared.
        o2 - the second object to be compared.
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
        Throws:
        java.lang.ClassCastException - if the arguments' types prevent them from being compared by this Comparator.
      • 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,
      • getCollation

        public java.util.Comparator getCollation()
        Get the underlying comparator
        Returns:
        the underlying comparator
      • setCollation

        public void setCollation​(java.util.Comparator collation)
        Set the underlying comparator
        Parameters:
        collation - the underlying comparator
      • 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