Class NumberAwareStringComparator

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

    public final class NumberAwareStringComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.String>
    A comparator for strings that compares numbers which are part of compared string as numbers and not as strings. This allows to sort strings that are a mixture of numbers and text (e.g. house numbers) in an intuitive fashion. For instance, plain string sorting sorts 200A greater than 1000A. This comparator sorts 1000A greater than 200A.
    Since:
    1.20
    Author:
    Lucas Koehler
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.String o1, java.lang.String o2)  
      static NumberAwareStringComparator getInstance()  
      • 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
    • Method Detail

      • compare

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