Class AlphanumComparator

  • All Implemented Interfaces:
    java.util.Comparator<java.lang.CharSequence>

    public class AlphanumComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.CharSequence>
    This is an updated version from the same named class from http://www.davekoelle.com/alphanum.html. The enhancement JIDE did to this class is
    • 1. Use JDK 5 generic to support CharSequence
    • 2. Add support to case insensitive comparison.
    • Constructor Summary

      Constructors 
      Constructor Description
      AlphanumComparator()
      Creates a case sensitive comparator to use the alphanum algorithm to compare the strings.
      AlphanumComparator​(boolean caseSensitive)
      Creates a comparator to use the alphanum algorithm to compare the strings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.CharSequence s1, java.lang.CharSequence s2)  
      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

      • AlphanumComparator

        public AlphanumComparator()
        Creates a case sensitive comparator to use the alphanum algorithm to compare the strings.
      • AlphanumComparator

        public AlphanumComparator​(boolean caseSensitive)
        Creates a comparator to use the alphanum algorithm to compare the strings.
        Parameters:
        caseSensitive - true or false.
    • Method Detail

      • compare

        public int compare​(java.lang.CharSequence s1,
                           java.lang.CharSequence s2)
        Specified by:
        compare in interface java.util.Comparator<java.lang.CharSequence>
      • 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.