Top Description Inners Fields Constructors Methods
com.github.difflib.patch

public final Class Patch<T>

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Type Parameters
<T>
The type of the compared elements in the 'lines'.
Static Imports
java.util.Comparator.comparing

Describes the patch holding all deltas between the original and revised texts.
Author
Dmitry Naumenko

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public final ConflictOutput<T>
CONFLICT_PRODUCES_EXCEPTION

Standard Patch behaviour to throw an exception for pathching conflicts.

public static final ConflictOutput<String>
CONFLICT_PRODUCES_MERGE_CONFLICT

Git like merge conflict output.

private ConflictOutput<T>
private final List<AbstractDelta<T>>

Constructor Summary

AccessConstructor and Description
public
public
Patch(int estimatedPatchSize)

Method Summary

Modifier and TypeMethod and Description
public void
addDelta(AbstractDelta<T>
the given delta
delta
)

Add the given delta to this patch

public List<T>
applyFuzzy(List<T> target, int maxFuzz)

public List<T>

Returns:

A new list containing the applied patch.
applyTo
(List<T>
The list to apply the changes to.
target
)

Creates a new list, the patch is being applied to.

public void
applyToExisting(List<T>
The list to apply the changes to. This list has to be modifiable, otherwise exceptions may be thrown, depending on the used type of list.
target
)

Applies the patch to the supplied list.

private static <T> Chunk<T>
buildChunk(int start, int end, List<T> data)

private int
private int
private int
findPositionWithFuzzAndMoreDelta(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz, int moreDelta)

public static <T> Patch<T>
generate(List<T> original, List<T> revised, List<Change> changes)

public static <T> Patch<T>
generate(List<T> original, List<T> revised, List<Change> _changes, boolean includeEquals)

public List<AbstractDelta<T>>

Returns:

the deltas
getDeltas
()

Get the list of computed deltas

public List<T>

Returns:

A new list, containing the restored state.
restore
(List<T>
The list to copy and apply changes to.
target
)

Creates a new list, containing the restored state of the given list.

public void
restoreToExisting(List<T>
The list to restore changes in. This list has to be modifiable, otherwise exceptions may be thrown, depending on the used type of list.
target
)

Restores all changes within the given list.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Patch<T>
withConflictOutput(ConflictOutput<T> conflictOutput)

Alter normal conflict output behaviour to e.g. inclide some conflict statements in the result, like git does it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CONFLICT_PRODUCES_EXCEPTIONback to summary
public final ConflictOutput<T> CONFLICT_PRODUCES_EXCEPTION

Standard Patch behaviour to throw an exception for pathching conflicts.

CONFLICT_PRODUCES_MERGE_CONFLICTback to summary
public static final ConflictOutput<String> CONFLICT_PRODUCES_MERGE_CONFLICT

Git like merge conflict output.

conflictOutputback to summary
private ConflictOutput<T> conflictOutput
deltasback to summary
private final List<AbstractDelta<T>> deltas

Constructor Detail

Patchback to summary
public Patch()
Patchback to summary
public Patch(int estimatedPatchSize)

Method Detail

addDeltaback to summary
public void addDelta(AbstractDelta<T> delta)

Add the given delta to this patch

Parameters
delta:AbstractDelta<T>

the given delta

applyFuzzyback to summary
public List<T> applyFuzzy(List<T> target, int maxFuzz) throws PatchFailedException
applyToback to summary
public List<T> applyTo(List<T> target) throws PatchFailedException

Creates a new list, the patch is being applied to.

Parameters
target:List<T>

The list to apply the changes to.

Returns:List<T>

A new list containing the applied patch.

Exceptions
PatchFailedException:
if the patch cannot be applied
applyToExistingback to summary
public void applyToExisting(List<T> target) throws PatchFailedException

Applies the patch to the supplied list.

Parameters
target:List<T>

The list to apply the changes to. This list has to be modifiable, otherwise exceptions may be thrown, depending on the used type of list.

Exceptions
PatchFailedException:
if the patch cannot be applied
RuntimeException:
(or similar) if the list is not modifiable.
buildChunkback to summary
private static <T> Chunk<T> buildChunk(int start, int end, List<T> data)
findPositionFuzzyback to summary
private int findPositionFuzzy(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta) throws PatchFailedException
findPositionWithFuzzback to summary
private int findPositionWithFuzz(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz) throws PatchFailedException
findPositionWithFuzzAndMoreDeltaback to summary
private int findPositionWithFuzzAndMoreDelta(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz, int moreDelta) throws PatchFailedException
generateback to summary
public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Change> changes)
generateback to summary
public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Change> _changes, boolean includeEquals)
getDeltasback to summary
public List<AbstractDelta<T>> getDeltas()

Get the list of computed deltas

Returns:List<AbstractDelta<T>>

the deltas

restoreback to summary
public List<T> restore(List<T> target)

Creates a new list, containing the restored state of the given list. Opposite to applyTo(List) method.

Parameters
target:List<T>

The list to copy and apply changes to.

Returns:List<T>

A new list, containing the restored state.

restoreToExistingback to summary
public void restoreToExisting(List<T> target)

Restores all changes within the given list. Opposite to applyToExisting(List) method.

Parameters
target:List<T>

The list to restore changes in. This list has to be modifiable, otherwise exceptions may be thrown, depending on the used type of list.

Exceptions
RuntimeException:
(or similar) if the list is not modifiable.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
withConflictOutputback to summary
public Patch<T> withConflictOutput(ConflictOutput<T> conflictOutput)

Alter normal conflict output behaviour to e.g. inclide some conflict statements in the result, like git does it.

com.github.difflib.patch back to summary

private Class Patch.PatchApplyingContext<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public boolean
public boolean
public int
currentFuzz

// passing values from find to apply

public int
public int
public final int
public final List<T>

Constructor Summary

AccessConstructor and Description
private
PatchApplyingContext(List<T> result, int maxFuzz)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

afterOutRangeback to summary
public boolean afterOutRange
beforeOutRangeback to summary
public boolean beforeOutRange
currentFuzzback to summary
public int currentFuzz

// passing values from find to apply

defaultPositionback to summary
public int defaultPosition
lastPatchEndback to summary
public int lastPatchEnd
maxFuzzback to summary
public final int maxFuzz
resultback to summary
public final List<T> result

Constructor Detail

PatchApplyingContextback to summary
private PatchApplyingContext(List<T> result, int maxFuzz)