Home All Groups
commons-codec / org / apache / commons / codec / StringEncoderComparator.html /
org.apache.commons.codec

Class StringEncoderComparator

  • All Implemented Interfaces:
    Comparator

    public class StringEncoderComparator
    extends Object
    implements 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 Detail

      • 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.
        Specified by:
        compare in 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:
        Comparable

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.