public static final class Edits.Iterator extends Object
At any moment in time, an instance of this class points to a single edit: a "window" into a span
of the source string and the corresponding span of the destination string. The source string span
starts at Edits.Iterator.sourceIndex() and runs for Edits.Iterator.oldLength() chars; the destination string
span starts at Edits.Iterator.destinationIndex() and runs for Edits.Iterator.newLength() chars.
The iterator can be moved between edits using the Edits.Iterator.next(), Edits.Iterator.findSourceIndex(int),
and Edits.Iterator.findDestinationIndex(int) methods. Calling any of these methods mutates the iterator
to make it point to the corresponding edit.
For more information, see the documentation for Edits.
Note: Although this class is called "Iterator", it does not implement Iterator.
Edits.getCoarseIterator(),
Edits.getFineIterator()| Modifier and Type | Method and Description |
|---|---|
int |
destinationIndex()
The start index of the current span in the destination string; the span has length
Edits.Iterator.newLength(). |
int |
destinationIndexFromSourceIndex(int i)
Computes the destination index corresponding to the given source index.
|
boolean |
findDestinationIndex(int i)
Moves the iterator to the edit that contains the destination index.
|
boolean |
findSourceIndex(int i)
Moves the iterator to the edit that contains the source index.
|
boolean |
hasChange()
Returns whether the edit currently represented by the iterator is a change edit.
|
int |
newLength()
The length of the current span in the destination string, which starts at
Edits.Iterator.destinationIndex(), or in the replacement string, which starts at
Edits.Iterator.replacementIndex(). |
boolean |
next()
Advances the iterator to the next edit.
|
int |
oldLength()
The length of the current span in the source string, which starts at
Edits.Iterator.sourceIndex(). |
int |
replacementIndex()
The start index of the current span in the replacement string; the span has length
Edits.Iterator.newLength(). |
int |
sourceIndex()
The start index of the current span in the source string; the span has length
Edits.Iterator.oldLength(). |
int |
sourceIndexFromDestinationIndex(int i)
Computes the source index corresponding to the given destination index.
|
String |
toString()
A string representation of the current edit represented by the iterator for debugging.
|
public boolean next()
public boolean findSourceIndex(int i)
The iterator state before this search logically does not matter. (It may affect the performance of the search.)
The iterator state after this search is undefined if the source index is out of bounds for the source string.
i - source indexpublic boolean findDestinationIndex(int i)
The iterator state before this search logically does not matter. (It may affect the performance of the search.)
The iterator state after this search is undefined if the source index is out of bounds for the source string.
i - destination indexpublic int destinationIndexFromSourceIndex(int i)
(This means that indexes to the start and middle of an edit, for example around a grapheme cluster, are mapped to indexes encompassing the entire edit. The alternative, mapping an interior index to the start, would map such an interval to an empty one.)
This operation will usually but not always modify this object. The iterator state after this search is undefined.
i - source indexpublic int sourceIndexFromDestinationIndex(int i)
(This means that indexes to the start and middle of an edit, for example around a grapheme cluster, are mapped to indexes encompassing the entire edit. The alternative, mapping an interior index to the start, would map such an interval to an empty one.)
This operation will usually but not always modify this object. The iterator state after this search is undefined.
i - destination indexpublic boolean hasChange()
public int oldLength()
Edits.Iterator.sourceIndex().public int newLength()
Edits.Iterator.destinationIndex(), or in the replacement string, which starts at
Edits.Iterator.replacementIndex().public int sourceIndex()
Edits.Iterator.oldLength().public int replacementIndex()
Edits.Iterator.newLength(). Well-defined only if the current edit is a change edit.
The replacement string is the concatenation of all substrings of the destination string corresponding to change edits.
This method is intended to be used together with operations that write only replacement
characters (e.g., CaseMap.omitUnchangedText()). The source string can then be modified
in-place.
public int destinationIndex()
Edits.Iterator.newLength().