Class TokenComparator

java.lang.Object
org.eclipse.compare.contentmergeviewer.TokenComparator
All Implemented Interfaces:
ITokenComparator, IRangeComparator

public class TokenComparator extends Object implements ITokenComparator
Implements the ITokenComparator interface for words (or tokens) in a string. A TokenComparator is used as the input for the RangeDifferencer engine to perform a token oriented compare on strings.

This class may be instantiated by clients but is not intended to be subclassed.

Since:
3.4
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a TokenComparator for the given string.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of comparable entities.
    int
    getTokenLength(int index)
    Returns the character length of the token with the given index.
    int
    getTokenStart(int index)
    Returns the start character position of the token with the given index.
    boolean
    rangesEqual(int thisIndex, IRangeComparator other, int otherIndex)
    Returns whether the comparable entity given by the first index matches an entity specified by the other IRangeComparator and index.
    boolean
    skipRangeComparison(int length, int max, IRangeComparator other)
    Returns whether a comparison should be skipped because it would be too costly (or lengthy).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TokenComparator

      public TokenComparator(String text)
      Creates a TokenComparator for the given string.
      Parameters:
      text - the string that is split into token
  • Method Details

    • getRangeCount

      public int getRangeCount()
      Description copied from interface: IRangeComparator
      Returns the number of comparable entities.
      Specified by:
      getRangeCount in interface IRangeComparator
      Returns:
      the number of comparable entities
    • getTokenStart

      public int getTokenStart(int index)
      Description copied from interface: ITokenComparator
      Returns the start character position of the token with the given index. If the index is out of range (but not negative) the character position behind the last character (the length of the input string) is returned.
      Specified by:
      getTokenStart in interface ITokenComparator
      Parameters:
      index - index of the token for which to return the start position
      Returns:
      the start position of the token with the given index
    • getTokenLength

      public int getTokenLength(int index)
      Description copied from interface: ITokenComparator
      Returns the character length of the token with the given index. If the index is out of range (but not negative) the value 0 is returned.
      Specified by:
      getTokenLength in interface ITokenComparator
      Parameters:
      index - index of the token for which to return the start position
      Returns:
      the character length of the token with the given index
    • rangesEqual

      public boolean rangesEqual(int thisIndex, IRangeComparator other, int otherIndex)
      Description copied from interface: IRangeComparator
      Returns whether the comparable entity given by the first index matches an entity specified by the other IRangeComparator and index.
      Specified by:
      rangesEqual in interface IRangeComparator
      Parameters:
      thisIndex - the index of the comparable entity within this IRangeComparator
      other - the IRangeComparator to compare this with
      otherIndex - the index of the comparable entity within the other IRangeComparator
      Returns:
      true if the comparable entities are equal
    • skipRangeComparison

      public boolean skipRangeComparison(int length, int max, IRangeComparator other)
      Description copied from interface: IRangeComparator
      Returns whether a comparison should be skipped because it would be too costly (or lengthy).
      Specified by:
      skipRangeComparison in interface IRangeComparator
      Parameters:
      length - a number on which to base the decision whether to return true or false
      max - another number on which to base the decision whether to return true or false
      other - the other IRangeComparator to compare with
      Returns:
      true to avoid a too lengthy range comparison