public class StringsComparator extends Object
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.
This code has been adapted from Apache Commons Collections 4.0.
EditScript
,
EditCommand
,
CommandVisitor
Constructor and Description |
---|
StringsComparator(String left,
String right)
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
EditScript<Character> |
getScript()
Get the
EditScript object. |
public StringsComparator(String left, String right)
Creates a new instance of StringsComparator.
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.
left
- first character sequence to be comparedright
- second character sequence to be comparedpublic EditScript<Character> getScript()
EditScript
object.
It is guaranteed that the objects embedded in the insert commands
come from the second sequence and that the objects
embedded in either the delete commands
or
keep commands
come from the first sequence. This can
be important if subclassing is used for some elements in the first
sequence and the equals
method is specialized.
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.