Package org.apache.commons.codec
Class StringEncoderComparator
java.lang.Object
org.apache.commons.codec.StringEncoderComparator
- All Implemented Interfaces:
- Comparator
Compares Strings using a 
StringEncoder. This comparator is used to sort Strings by an encoding scheme such as
 Soundex, Metaphone, etc. This class can come in handy if one need to sort Strings by an encoded form of a name such
 as Soundex.
 This class is immutable and thread-safe.
- 
Constructor SummaryConstructorsConstructorDescriptionDeprecated.StringEncoderComparator(StringEncoder stringEncoder) Constructs a new instance with the given algorithm.
- 
Method SummaryMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparatorequals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
- 
Constructor Details- 
StringEncoderComparatorDeprecated.Creating an instance without aStringEncoderleads to aNullPointerException. Will be removed in 2.0.Constructs a new instance.
- 
StringEncoderComparatorConstructs a new instance with the given algorithm.- Parameters:
- stringEncoder- the StringEncoder used for comparisons.
 
 
- 
- 
Method Details- 
compareCompares two strings based not on the strings themselves, but on an encoding of the two strings using the StringEncoder this Comparator was created with. If anEncoderExceptionis encountered, return0.- Specified by:
- comparein interface- Comparator
- Parameters:
- o1- the object to compare
- o2- the object to compare to
- Returns:
- the Comparable.compareTo() return code or 0 if an encoding error was caught.
- See Also:
 
 
- 
StringEncoderleads to aNullPointerException.