Top Description Fields Constructors Methods
org.apache.commons.text.diff

public Class EditScript<T>

extends Object
Class Inheritance
Type Parameters
<T>
object type
Imports
java.util.ArrayList, .List

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
StringsComparator, EditCommand, CommandVisitor, ReplacementsHandler

Field Summary

Modifier and TypeField and Description
private final List<EditCommand<T>>
commands

Container for the commands.

private int
lcsLength

Length of the longest common subsequence.

private int
modifications

Number of modifications.

Constructor Summary

AccessConstructor and Description
public
EditScript()

Constructs a new empty script.

Method Summary

Modifier and TypeMethod and Description
public void
append(final DeleteCommand<T>
command to add.
command
)

Appends a delete command to the script.

public void
append(final InsertCommand<T>
command to add.
command
)

Appends an insert command to the script.

public void
append(final KeepCommand<T>
command to add.
command
)

Appends a keep command to the script.

public int

Returns:

length of the Longest Common Subsequence.
getLCSLength
()

Gets the length of the Longest Common Subsequence (LCS).

public int

Returns:

number of effective modifications.
getModifications
()

Gets the number of effective modifications.

public void
visit(final CommandVisitor<T>
the visitor that will visit all commands in turn.
visitor
)

Visits the script.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

commandsback to summary
private final List<EditCommand<T>> commands

Container for the commands.

lcsLengthback to summary
private int lcsLength

Length of the longest common subsequence.

modificationsback to summary
private int modifications

Number of modifications.

Constructor Detail

EditScriptback to summary
public EditScript()

Constructs a new empty script.

Method Detail

appendback to summary
public void append(final DeleteCommand<T> command)

Appends a delete command to the script.

Parameters
command:DeleteCommand<T>

command to add.

appendback to summary
public void append(final InsertCommand<T> command)

Appends an insert command to the script.

Parameters
command:InsertCommand<T>

command to add.

appendback to summary
public void append(final KeepCommand<T> command)

Appends a keep command to the script.

Parameters
command:KeepCommand<T>

command to add.

getLCSLengthback to summary
public int getLCSLength()

Gets the length of the Longest Common Subsequence (LCS). The length of the longest common subsequence is the number of keep commands in the script.

Returns:int

length of the Longest Common Subsequence.

getModificationsback to summary
public int getModifications()

Gets the number of effective modifications. The number of effective modification is the number of delete and insert commands in the script.

Returns:int

number of effective modifications.

visitback to summary
public void visit(final CommandVisitor<T> visitor)

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:CommandVisitor<T>

the visitor that will visit all commands in turn.