org.apache.commons.codec
Class StringEncoderComparator

java.lang.Object
  extended byorg.apache.commons.codec.StringEncoderComparator
All Implemented Interfaces:
Comparator

public class StringEncoderComparator
extends Object
implements Comparator

String are comparable, and this comparator allows you to configure it with an instance of a class which implements the StringEncoder. This comparator is used to sort Strings by an encoding shceme 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.9 2003/11/13 06:50:35 ggregory Exp $
Author:
Tim O'Brien, Gary Gregory

Field Summary
private  StringEncoder stringEncoder
          Internal encoder instance.
 
Constructor Summary
StringEncoderComparator()
          Constructs a new instance.
StringEncoderComparator(StringEncoder en)
          Constructs a new instance with the given soundex algorithm.
 
Method Summary
 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.
 
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
 

Field Detail

stringEncoder

private StringEncoder stringEncoder
Internal encoder instance.

Constructor Detail

StringEncoderComparator

public StringEncoderComparator()
Constructs a new instance.


StringEncoderComparator

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

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.

Specified by:
compare in interface Comparator
See Also:
Comparable


${component.name} version 1.2 - Copyright © 2003 - Apache Software Foundation