Class Patch<T>
java.lang.Object
com.github.difflib.patch.Patch<T>
- Type Parameters:
T- The type of the compared elements in the 'lines'.
- All Implemented Interfaces:
Serializable
Describes the patch holding all deltas between the original and revised
texts.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ConflictOutput<T> Standard Patch behaviour to throw an exception for pathching conflicts.static final ConflictOutput<String> Git like merge conflict output.private ConflictOutput<T> private final List<AbstractDelta<T>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDelta(AbstractDelta<T> delta) Add the given delta to this patchapplyFuzzy(List<T> target, int maxFuzz) Creates a new list, the patch is being applied to.voidapplyToExisting(List<T> target) Applies the patch to the supplied list.private static <T> Chunk<T> buildChunk(int start, int end, List<? extends T> data) private intfindPositionFuzzy(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta) private intfindPositionWithFuzz(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz) private intfindPositionWithFuzzAndMoreDelta(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz, int moreDelta) static <T> Patch<T> generate(List<? extends T> original, List<? extends T> revised, List<Change> _changes, boolean includeEquals) static <T> Patch<T> Get the list of computed deltasCreates a new list, containing the restored state of the given list.voidrestoreToExisting(List<T> target) Restores all changes within the given list.toString()withConflictOutput(ConflictOutput<T> conflictOutput) Alter normal conflict output behaviour to e.g.
-
Field Details
-
deltas
-
CONFLICT_PRODUCES_EXCEPTION
Standard Patch behaviour to throw an exception for pathching conflicts. -
CONFLICT_PRODUCES_MERGE_CONFLICT
Git like merge conflict output. -
conflictOutput
-
-
Constructor Details
-
Patch
public Patch() -
Patch
public Patch(int estimatedPatchSize)
-
-
Method Details
-
applyTo
Creates a new list, the patch is being applied to.- Parameters:
target- The list to apply the changes to.- Returns:
- A new list containing the applied patch.
- Throws:
PatchFailedException- if the patch cannot be applied
-
applyToExisting
Applies the patch to the supplied list.- Parameters:
target- 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.- Throws:
PatchFailedException- if the patch cannot be appliedRuntimeException- (or similar) if the list is not modifiable.
-
applyFuzzy
- Throws:
PatchFailedException
-
findPositionFuzzy
private int findPositionFuzzy(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta) throws PatchFailedException - Throws:
PatchFailedException
-
findPositionWithFuzz
private int findPositionWithFuzz(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz) throws PatchFailedException - Throws:
PatchFailedException
-
findPositionWithFuzzAndMoreDelta
private int findPositionWithFuzzAndMoreDelta(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz, int moreDelta) throws PatchFailedException - Throws:
PatchFailedException
-
withConflictOutput
Alter normal conflict output behaviour to e.g. include some conflict statements in the result, like git does it. -
restore
Creates a new list, containing the restored state of the given list. Opposite toapplyTo(List)method.- Parameters:
target- The list to copy and apply changes to.- Returns:
- A new list, containing the restored state.
-
restoreToExisting
Restores all changes within the given list. Opposite toapplyToExisting(List)method.- Parameters:
target- The list to restore changes in. This list has to be modifiable, otherwise exceptions may be thrown, depending on the used type of list.- Throws:
RuntimeException- (or similar) if the list is not modifiable.
-
addDelta
Add the given delta to this patch- Parameters:
delta- the given delta
-
getDeltas
-
toString
-
generate
-
buildChunk
-
generate
-