The two sequences can hold any object type, as only the equals
method is used to compare the elements of the sequences. It is guaranteed
that the comparisons will always be done as o1.equals(o2) where
o1 belongs to the first sequence and o2 belongs to
the second sequence. This can be important if subclassing is used for some
elements in the first sequence and the equals method is
specialized.
Comparison can be seen from two points of view: either as giving the smallest
modification allowing to transform the first sequence into the second one, or
as giving the longest sequence which is a subsequence of both initial
sequences. The equals method is used to compare objects, so any
object can be put into sequences. Modifications include deleting, inserting
or keeping one object, starting from the beginning of the first sequence.
This class implements the comparison algorithm, which is the very efficient
algorithm from Eugene W. Myers
An O(ND) Difference Algorithm and Its Variations. This algorithm produces
the shortest possible
edit script
containing all the
commands
needed to transform the first sequence into the second one.
EditScript, EditCommand, CommandVisitor
| Modifier and Type | Class and Description |
|---|---|
| private static class | SequencesComparator.Snake
This class is a simple placeholder to hold the end part of a path
under construction in a |
| Modifier and Type | Field and Description |
|---|---|
| private final Equator | equator
The equator used for testing object equality. |
| private final List | sequence1
First sequence. |
| private final List | sequence2
Second sequence. |
| private final int[] | vDown
Temporary variables. |
| private final int[] |
| Access | Constructor and Description |
|---|---|
| public | SequencesComparator(final List<T>
first sequence to be compared sequence1, final List<T> second sequence to be compared sequence2)Simple constructor. |
| public | SequencesComparator(final List<T>
first sequence to be compared sequence1, final List<T> second sequence to be compared sequence2, final Equator<? super T> the equator to use for testing object equality equator)Simple constructor. |
| Modifier and Type | Method and Description |
|---|---|
| private void | buildScript(final int
the begin of the first sequence to be compared start1, final int the end of the first sequence to be compared end1, final int the begin of the second sequence to be compared start2, final int the end of the second sequence to be compared end2, final EditScript<T> the edited script script)Build an edit script. |
| private SequencesComparator. | Returns: the snake builtthe value of the start of the snake start, final int the value of the diagonal of the snake diag, final int the value of the end of the first sequence to be compared end1, final int the value of the end of the second sequence to be compared end2)Build a snake. |
| private SequencesComparator. | Returns: the middle snakethe begin of the first sequence to be compared start1, final int the end of the first sequence to be compared end1, final int the begin of the second sequence to be compared start2, final int the end of the second sequence to be compared end2)Get the middle snake corresponding to two subsequences of the main sequences. |
| public EditScript | Returns: the edit script resulting from the comparison of the two sequencesGet the |
| equator | back to summary |
|---|---|
| private final Equator<? super T> equator The equator used for testing object equality. | |
| sequence1 | back to summary |
|---|---|
| private final List<T> sequence1 First sequence. | |
| sequence2 | back to summary |
|---|---|
| private final List<T> sequence2 Second sequence. | |
| vDown | back to summary |
|---|---|
| private final int[] vDown Temporary variables. | |
| vUp | back to summary |
|---|---|
| private final int[] vUp | |
| SequencesComparator | back to summary |
|---|---|
| public SequencesComparator(final List<T> sequence1, final List<T> sequence2) Simple constructor.
Creates a new instance of SequencesComparator using a
It is guaranteed that the comparisons will always be done as
| |
| SequencesComparator | back to summary |
|---|---|
| public SequencesComparator(final List<T> sequence1, final List<T> sequence2, final Equator<? super T> equator) Simple constructor.
Creates a new instance of SequencesComparator with a custom
It is guaranteed that the comparisons will always be done as
| |
| buildScript | back to summary |
|---|---|
| private void buildScript(final int start1, final int end1, final int start2, final int end2, final EditScript<T> script) Build an edit script.
| |
| buildSnake | back to summary |
|---|---|
| private SequencesComparator. Build a snake.
| |
| getMiddleSnake | back to summary |
|---|---|
| private SequencesComparator. Get the middle snake corresponding to two subsequences of the main sequences. The snake is found using the MYERS Algorithm (this algorithms has also been implemented in the GNU diff program). This algorithm is explained in Eugene Myers article: An O(ND) Difference Algorithm and Its Variations.
| |
| getScript | back to summary |
|---|---|
| public EditScript Get the
It is guaranteed that the objects embedded in the
| |
SequencesComparator.
| Modifier and Type | Field and Description |
|---|---|
| private final int | diag
Diagonal number. |
| private final int | end
End index. |
| private final int | start
Start index. |
| Access | Constructor and Description |
|---|---|
| public | Snake(final int
start index of the snake start, final int end index of the snake end, final int diagonal number diag)Simple constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| public int | |
| public int |
| diag | back to summary |
|---|---|
| private final int diag Diagonal number. | |
| end | back to summary |
|---|---|
| private final int end End index. | |
| start | back to summary |
|---|---|
| private final int start Start index. | |
| Snake | back to summary |
|---|---|
| public Snake(final int start, final int end, final int diag) Simple constructor. Creates a new instance of Snake with specified indices.
| |
| getDiag | back to summary |
|---|---|
| public int getDiag() Get the diagonal number of the snake.
| |
| getEnd | back to summary |
|---|---|
| public int getEnd() Get the end index of the snake.
| |
| getStart | back to summary |
|---|---|
| public int getStart() Get the start index of the snake.
| |