Package org.apache.commons.text.diff
Class EditScript<T>
java.lang.Object
org.apache.commons.text.diff.EditScript<T>
- Type Parameters:
T- object type
This class gathers all the
commands needed to transform
one objects sequence into another objects sequence.
An edit script is the most general view of the differences between two
sequences. It is built as the result of the comparison between two sequences
by the StringsComparator class. The user can
walk through it using the visitor design pattern.
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.
- Since:
- 1.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(DeleteCommand<T> command) Appends a delete command to the script.voidappend(InsertCommand<T> command) Appends an insert command to the script.voidappend(KeepCommand<T> command) Appends a keep command to the script.intGets the length of the Longest Common Subsequence (LCS).intGets the number of effective modifications.voidvisit(CommandVisitor<T> visitor) Visits the script.
-
Constructor Details
-
EditScript
public EditScript()Constructs a new empty script.
-
-
Method Details
-
append
Appends a delete command to the script.- Parameters:
command- command to add
-
append
Appends an insert command to the script.- Parameters:
command- command to add
-
append
Appends a keep command to the script.- Parameters:
command- command to add
-
getLCSLength
Gets the length of the Longest Common Subsequence (LCS). The length of the longest common subsequence is the number ofkeep commandsin the script.- Returns:
- length of the Longest Common Subsequence
-
getModifications
Gets the number of effective modifications. The number of effective modification is the number ofdeleteandinsertcommands in the script.- Returns:
- number of effective modifications
-
visit
Visits the script. The script implements the visitor design pattern, this method is the entry point to which the user supplies its own visitor, the script will be responsible to drive it through the commands in order and call the appropriate method as each command is encountered.- Parameters:
visitor- the visitor that will visit all commands in turn
-