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

public Class ReplacementsFinder<T>

extends Object
implements CommandVisitor<T>
Class Inheritance
All Implemented Interfaces
org.apache.commons.text.diff.CommandVisitor
Type Parameters
<T>
object type
Imports
java.util.ArrayList, .List

Handles sequences of replacements resulting from a comparison.

The comparison of two objects sequences leads to the identification of common parts and parts which only belong to the first or to the second sequence. The common parts appear in the edit script in the form of keep commands, they can be considered as synchronization objects between the two sequences. These synchronization objects split the two sequences in synchronized sub-sequences. The first sequence can be transformed into the second one by replacing each synchronized sub-sequence of the first sequence by the corresponding sub-sequence of the second sequence. This is a synthetic way to see an edit script, replacing individual delete, keep and insert commands by fewer replacements acting on complete sub-sequences.

This class is devoted to perform this interpretation. It visits an edit script (because it implements the CommandVisitor interface) and calls a user-supplied handler implementing the ReplacementsHandler interface to process the sub-sequences.

Since
1.0
See Also
ReplacementsHandler, EditScript, StringsComparator

Field Summary

Modifier and TypeField and Description
private final ReplacementsHandler<T>
handler

Handler to call when synchronized sequences are found.

private final List<T>
pendingDeletions

List of pending deletions.

private final List<T>
pendingInsertions

List of pending insertions.

private int
skipped

Count of elements skipped.

Constructor Summary

AccessConstructor and Description
public
ReplacementsFinder(final ReplacementsHandler<T>
handler to call when synchronized sequences are found
handler
)

Constructs a new instance of ReplacementsFinder.

Method Summary

Modifier and TypeMethod and Description
public void
visitDeleteCommand(final T
object to delete.
object
)

Implements org.apache.commons.text.diff.CommandVisitor.visitDeleteCommand.

Add an object to the pending deletions set.

public void
visitInsertCommand(final T
object to insert.
object
)

Implements org.apache.commons.text.diff.CommandVisitor.visitInsertCommand.

Add an object to the pending insertions set.

public void
visitKeepCommand(final T
synchronization object detected.
object
)

Implements org.apache.commons.text.diff.CommandVisitor.visitKeepCommand.

Handle a synchronization object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlerback to summary
private final ReplacementsHandler<T> handler

Handler to call when synchronized sequences are found.

pendingDeletionsback to summary
private final List<T> pendingDeletions

List of pending deletions.

pendingInsertionsback to summary
private final List<T> pendingInsertions

List of pending insertions.

skippedback to summary
private int skipped

Count of elements skipped.

Constructor Detail

ReplacementsFinderback to summary
public ReplacementsFinder(final ReplacementsHandler<T> handler)

Constructs a new instance of ReplacementsFinder.

Parameters
handler:ReplacementsHandler<T>

handler to call when synchronized sequences are found

Method Detail

visitDeleteCommandback to summary
public void visitDeleteCommand(final T object)

Implements org.apache.commons.text.diff.CommandVisitor.visitDeleteCommand.

Add an object to the pending deletions set.

Parameters
object:T

object to delete.

Annotations
@Override
visitInsertCommandback to summary
public void visitInsertCommand(final T object)

Implements org.apache.commons.text.diff.CommandVisitor.visitInsertCommand.

Add an object to the pending insertions set.

Parameters
object:T

object to insert.

Annotations
@Override
visitKeepCommandback to summary
public void visitKeepCommand(final T object)

Implements org.apache.commons.text.diff.CommandVisitor.visitKeepCommand.

Handle a synchronization object.

When a synchronization object is identified, the pending insertions and pending deletions sets are provided to the user handler as subsequences.

Parameters
object:T

synchronization object detected.

Annotations
@Override