Class TokenComparator
java.lang.Object
org.eclipse.compare.contentmergeviewer.TokenComparator
- All Implemented Interfaces:
ITokenComparator,IRangeComparator
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
ConstructorsConstructorDescriptionTokenComparator(String text) Creates aTokenComparatorfor the given string. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of comparable entities.intgetTokenLength(int index) Returns the character length of the token with the given index.intgetTokenStart(int index) Returns the start character position of the token with the given index.booleanrangesEqual(int thisIndex, IRangeComparator other, int otherIndex) Returns whether the comparable entity given by the first index matches an entity specified by the otherIRangeComparatorand index.booleanskipRangeComparison(int length, int max, IRangeComparator other) Returns whether a comparison should be skipped because it would be too costly (or lengthy).
-
Constructor Details
-
TokenComparator
Creates aTokenComparatorfor the given string.- Parameters:
text- the string that is split into token
-
-
Method Details
-
getRangeCount
public int getRangeCount()Description copied from interface:IRangeComparatorReturns the number of comparable entities.- Specified by:
getRangeCountin interfaceIRangeComparator- Returns:
- the number of comparable entities
-
getTokenStart
public int getTokenStart(int index) Description copied from interface:ITokenComparatorReturns 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:
getTokenStartin interfaceITokenComparator- 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:ITokenComparatorReturns 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:
getTokenLengthin interfaceITokenComparator- 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
Description copied from interface:IRangeComparatorReturns whether the comparable entity given by the first index matches an entity specified by the otherIRangeComparatorand index.- Specified by:
rangesEqualin interfaceIRangeComparator- Parameters:
thisIndex- the index of the comparable entity within thisIRangeComparatorother- the IRangeComparator to compare this withotherIndex- the index of the comparable entity within the otherIRangeComparator- Returns:
trueif the comparable entities are equal
-
skipRangeComparison
Description copied from interface:IRangeComparatorReturns whether a comparison should be skipped because it would be too costly (or lengthy).- Specified by:
skipRangeComparisonin interfaceIRangeComparator- Parameters:
length- a number on which to base the decision whether to returntrueorfalsemax- another number on which to base the decision whether to returntrueorfalseother- the otherIRangeComparatorto compare with- Returns:
trueto avoid a too lengthy range comparison
-