StringEncoderComparator (Encode/Decode Utilities (Version 1.10))
Date: 2019-08-31

org.apache.commons.codec

## Class StringEncoderComparator

- java.lang.Object
- - org.apache.commons.codec.StringEncoderComparator

- All Implemented Interfaces:
    java.util.Comparator

      public class StringEncoderComparator
      extends java.lang.Object
      implements java.util.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.

  Version:
    $Id: StringEncoderComparator.java 1468177 2013-04-15 18:35:15Z ggregory $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private StringEncoder` | `stringEncoder` Internal encoder instance.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringEncoderComparator()` Deprecated. Creating an instance without a `StringEncoder` leads to a `NullPointerException`. Will be removed in 2.0.
    `StringEncoderComparator(StringEncoder stringEncoder)` Constructs a new instance with the given algorithm.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compare(java.lang.Object o1, java.lang.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

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Field Detail

    - #### stringEncoder

          private final StringEncoder stringEncoder

      Internal encoder instance.

  - ### Constructor Detail

    - #### StringEncoderComparator

          @Deprecated
          public StringEncoderComparator()

      Deprecated. Creating an instance without a `StringEncoder` leads to a `NullPointerException`. Will be removed in 2.0.
      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(java.lang.Object o1,
                             java.lang.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 `java.util.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`

commons-codec version 1.10 - Copyright © 2002-2019 - Apache Software Foundation