Package org.apache.commons.codec
Class StringEncoderComparator
java.lang.Object
org.apache.commons.codec.StringEncoderComparator
- All Implemented Interfaces:
Comparator
public class StringEncoderComparator extends Object implements Comparator
Strings are comparable, and this comparator allows
you to configure it with an instance of a class
which implements 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.
- Version:
- $Id: StringEncoderComparator.java,v 1.14 2004/06/21 23:24:17 ggregory Exp $
- Author:
- Apache Software Foundation
-
Constructor Summary
Constructors Constructor Description StringEncoderComparator()Constructs a new instance.StringEncoderComparator(StringEncoder stringEncoder)Constructs a new instance with the given algorithm. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals
-
Constructor Details
-
StringEncoderComparator
public StringEncoderComparator()Constructs a new instance. -
StringEncoderComparator
Constructs a new instance with the given algorithm.- Parameters:
stringEncoder- the StringEncoder used for comparisons.
-
-
Method Details
-
compare
Compares 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 interfaceComparator- Parameters:
o1- the object to compareo2- the object to compare to- Returns:
- the Comparable.compareTo() return code or 0 if an encoding error was caught.
- See Also:
Comparable
-