Class CharSequenceComparator

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<java.lang.Object>

    public class CharSequenceComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.Object>, java.io.Serializable
    A Comparator that compares CharSequence objects (including String and StringBuffer as both extend CharSequence. Throws ClassCastExceptions if the objects are not CharSequence, or if they are null. If both objects are null, they will be treated as equal. If one is null and the other is not, the null value will be treated as smaller then non-null value.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.Object o1, java.lang.Object o2)  
      boolean isCaseSensitive()
      Checks if the case is sensitive when comparing.
      void setCaseSensitive​(boolean caseSensitive)
      Sets the case sensitive flag.
      • 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
    • Constructor Detail

      • CharSequenceComparator

        public CharSequenceComparator()
        Constructs a CharSequenceComparator.
      • CharSequenceComparator

        public CharSequenceComparator​(boolean caseSensitive)
    • Method Detail

      • isCaseSensitive

        public boolean isCaseSensitive()
        Checks if the case is sensitive when comparing.
        Returns:
        true if the comparator is case sensitive.
      • setCaseSensitive

        public void setCaseSensitive​(boolean caseSensitive)
        Sets the case sensitive flag. By default, it's true meaning the comparator is case sensitive.
        Parameters:
        caseSensitive - true or false.
      • compare

        public int compare​(java.lang.Object o1,
                           java.lang.Object o2)
        Specified by:
        compare in interface java.util.Comparator<java.lang.Object>