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
ConstructorDescriptionTokenComparator
(String text) Creates aTokenComparator
for the given string. -
Method Summary
Modifier and TypeMethodDescriptionint
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 otherIRangeComparator
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).
-
Constructor Details
-
TokenComparator
Creates aTokenComparator
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 interfaceIRangeComparator
- 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 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: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 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:IRangeComparator
Returns whether the comparable entity given by the first index matches an entity specified by the otherIRangeComparator
and index.- Specified by:
rangesEqual
in interfaceIRangeComparator
- Parameters:
thisIndex
- the index of the comparable entity within thisIRangeComparator
other
- the IRangeComparator to compare this withotherIndex
- the index of the comparable entity within the otherIRangeComparator
- Returns:
true
if the comparable entities are equal
-
skipRangeComparison
Description copied from interface:IRangeComparator
Returns whether a comparison should be skipped because it would be too costly (or lengthy).- Specified by:
skipRangeComparison
in interfaceIRangeComparator
- Parameters:
length
- a number on which to base the decision whether to returntrue
orfalse
max
- another number on which to base the decision whether to returntrue
orfalse
other
- the otherIRangeComparator
to compare with- Returns:
true
to avoid a too lengthy range comparison
-