Class DefaultEditComparator<T>

  • All Implemented Interfaces:
    EditComparator<T>

    public class DefaultEditComparator<T>
    extends Object
    implements EditComparator<T>
    Default implementation of IEditComparator, for which any from/to pair for which equals() is not true is given an edit distance of getChangeDistance().
    Author:
    Robert Fromont robert@fromont.net.nz
    • Constructor Detail

      • DefaultEditComparator

        public DefaultEditComparator()
        Default constructor
      • DefaultEditComparator

        public DefaultEditComparator​(Comparator<T> comparator)
        Constructor with custom comparator.
        Parameters:
        comparator - The custom comparator.
      • DefaultEditComparator

        public DefaultEditComparator​(int insertDeleteChangeDistance)
        Constructor
        Parameters:
        insertDeleteChangeDistance - The distance applied to an insert, delete, or change.
      • DefaultEditComparator

        public DefaultEditComparator​(int insertDistance,
                                     int deleteDistance,
                                     int changeDistance)
        Constructor
        Parameters:
        insertDistance - The distance applied to an insertion.
        deleteDistance - The distance applied to a deletion.
        changeDistance - The distance applied to a change.
    • Method Detail

      • getChangeDistance

        public int getChangeDistance()
        Getter for iChangeDistance: The distance represented by a change.
        Returns:
        The distance represented by a change.
      • setChangeDistance

        public DefaultEditComparator<T> setChangeDistance​(int iNewChangeDistance)
        Setter for iChangeDistance: The distance represented by a change.
        Parameters:
        iNewChangeDistance - The distance represented by a change.
      • getDeleteDistance

        public int getDeleteDistance()
        Getter for iDeleteDistance: The distance represented by a deletion.
        Returns:
        The distance represented by a deletion.
      • setDeleteDistance

        public DefaultEditComparator<T> setDeleteDistance​(int iNewDeleteDistance)
        Setter for iDeleteDistance: The distance represented by a deletion.
        Parameters:
        iNewDeleteDistance - The distance represented by a deletion.
      • getInsertDistance

        public int getInsertDistance()
        Getter for iInsertDistance: The distance represented by an insertion.
        Returns:
        The distance represented by an insertion.
      • setInsertDistance

        public DefaultEditComparator<T> setInsertDistance​(int iNewInsertDistance)
        Setter for iInsertDistance: The distance represented by an insertion.
        Parameters:
        iNewInsertDistance - The distance represented by an insertion.
      • getComparator

        public Comparator<T> getComparator()
        Getter for comparator: A comparator to use to determin equality, or null to use java.util.Object.equals(Object).
        Returns:
        A comparator to use to determin equality, or null to use java.util.Object.equals(Object).
      • setComparator

        public DefaultEditComparator<T> setComparator​(Comparator<T> newComparator)
        Setter for comparator: A comparator to use to determin equality, or null to use java.util.Object.equals(Object).
        Parameters:
        newComparator - A comparator to use to determine equality, or null to use java.util.Object.equals(Object).
      • compare

        public EditStep<T> compare​(T from,
                                   T to)
        EditComparator method: Compares two sequence elements, and evaluates the distance between them.
        Specified by:
        compare in interface EditComparator<T>
        Parameters:
        from - The element from the source sequence, which may be null.
        to - The element from the destination sequence, which may be null.
        Returns:
        An edit step between the two elements. EditStep.getFrom() is set to from, EditStep.getTo() is set to to, EditStep.getStepDistance() is set to the computed edit distance between these two elements, and EditStep.getOperation() is set to either EditStep.StepOperation.NONE or EditStep.StepOperation.CHANGE.