org.apache.commons.codec

Class StringEncoderComparator

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 130381 2004-06-21 23:24:17Z ggregory $

Author: Apache Software Foundation

Field Summary
StringEncoderstringEncoder
Internal encoder instance.
Constructor Summary
StringEncoderComparator()
Constructs a new instance.
StringEncoderComparator(StringEncoder stringEncoder)
Constructs a new instance with the given algorithm.
Method Summary
intcompare(Object o1, Object o2)
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.

Field Detail

stringEncoder

private StringEncoder stringEncoder
Internal encoder instance.

Constructor Detail

StringEncoderComparator

public StringEncoderComparator()
Constructs a new instance.

StringEncoderComparator

public StringEncoderComparator(StringEncoder stringEncoder)
Constructs a new instance with the given algorithm.

Parameters: stringEncoder the StringEncoder used for comparisons.

Method Detail

compare

public int compare(Object o1, Object o2)
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 an EncoderException is encountered, return 0.

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: Comparable

commons-codec version 1.3 - Copyright © 2002-2004 - Apache Software Foundation