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

public abstract Class EditCommand<T>

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.commons.text.diff.InsertCommand, org.apache.commons.text.diff.KeepCommand, org.apache.commons.text.diff.DeleteCommand
Type Parameters
<T>
object type

Abstract base class for all commands used to transform an objects sequence into another one.

When two objects sequences are compared through the StringsComparator.getScript method, the result is provided has a script containing the commands that progressively transform the first sequence into the second one.

There are only three types of commands, all of which are subclasses of this abstract class. Each command is associated with one object belonging to at least one of the sequences. These commands are InsertCommand which correspond to an object of the second sequence being inserted into the first sequence, DeleteCommand which correspond to an object of the first sequence being removed and KeepCommand which correspond to an object of the first sequence which equals an object in the second sequence. It is guaranteed that comparison is always performed this way (i.e. the equals method of the object from the first sequence is used and the object passed as an argument comes from the second sequence) ; this can be important if subclassing is used for some elements in the first sequence and the equals method is specialized.

This code has been adapted from Apache Commons Collections 4.0.

Since
1.0
See Also
StringsComparator, EditScript

Field Summary

Modifier and TypeField and Description
private final T
object

Object on which the command should be applied.

Constructor Summary

AccessConstructor and Description
protected
EditCommand(final T
reference to the object associated with this command, this refers to an element of one of the sequences being compared.
object
)

Constructs a new instance of EditCommand.

Method Summary

Modifier and TypeMethod and Description
public abstract void
accept(CommandVisitor<T>
the visitor to be accepted.
visitor
)

Accepts a visitor.

protected T

Returns:

The object on which the command is applied.
getObject
()

Gets the object associated with this command.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

objectback to summary
private final T object

Object on which the command should be applied.

Constructor Detail

EditCommandback to summary
protected EditCommand(final T object)

Constructs a new instance of EditCommand.

Parameters
object:T

reference to the object associated with this command, this refers to an element of one of the sequences being compared.

Method Detail

acceptback to summary
public abstract void accept(CommandVisitor<T> visitor)

Accepts a visitor.

This method is invoked for each commands belonging to an EditScript, in order to implement the visitor design pattern

Parameters
visitor:CommandVisitor<T>

the visitor to be accepted.

getObjectback to summary
protected T getObject()

Gets the object associated with this command.

Returns:T

The object on which the command is applied.