Package com.github.difflib.patch
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:
java.io.Serializable
public final class Patch<T> extends java.lang.Object implements java.io.Serializable
Describes the patch holding all deltas between the original and revised texts.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Patch.PatchApplyingContext<T>
-
Field Summary
Fields Modifier and Type Field Description ConflictOutput<T>
CONFLICT_PRODUCES_EXCEPTION
Standard Patch behaviour to throw an exception for pathching conflicts.static ConflictOutput<java.lang.String>
CONFLICT_PRODUCES_MERGE_CONFLICT
Git like merge conflict output.private ConflictOutput<T>
conflictOutput
private java.util.List<AbstractDelta<T>>
deltas
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDelta(AbstractDelta<T> delta)
Add the given delta to this patchjava.util.List<T>
applyFuzzy(java.util.List<T> target, int maxFuzz)
java.util.List<T>
applyTo(java.util.List<T> target)
Apply this patch to the given targetprivate static <T> Chunk<T>
buildChunk(int start, int end, java.util.List<T> data)
private int
findPositionFuzzy(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta)
private int
findPositionWithFuzz(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz)
private int
findPositionWithFuzzAndMoreDelta(Patch.PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz, int moreDelta)
static <T> Patch<T>
generate(java.util.List<T> original, java.util.List<T> revised, java.util.List<Change> changes)
static <T> Patch<T>
generate(java.util.List<T> original, java.util.List<T> revised, java.util.List<Change> _changes, boolean includeEquals)
java.util.List<AbstractDelta<T>>
getDeltas()
Get the list of computed deltasjava.util.List<T>
restore(java.util.List<T> target)
Restore the text to original.java.lang.String
toString()
Patch
withConflictOutput(ConflictOutput<T> conflictOutput)
Alter normal conflict output behaviour to e.g.
-
-
-
Field Detail
-
deltas
private final java.util.List<AbstractDelta<T>> deltas
-
CONFLICT_PRODUCES_EXCEPTION
public final ConflictOutput<T> CONFLICT_PRODUCES_EXCEPTION
Standard Patch behaviour to throw an exception for pathching conflicts.
-
CONFLICT_PRODUCES_MERGE_CONFLICT
public static final ConflictOutput<java.lang.String> CONFLICT_PRODUCES_MERGE_CONFLICT
Git like merge conflict output.
-
conflictOutput
private ConflictOutput<T> conflictOutput
-
-
Method Detail
-
applyTo
public java.util.List<T> applyTo(java.util.List<T> target) throws PatchFailedException
Apply this patch to the given target- Returns:
- the patched text
- Throws:
PatchFailedException
- if can't apply patch
-
applyFuzzy
public java.util.List<T> applyFuzzy(java.util.List<T> target, int maxFuzz) throws PatchFailedException
- 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
public Patch withConflictOutput(ConflictOutput<T> conflictOutput)
Alter normal conflict output behaviour to e.g. inclide some conflict statements in the result, like git does it.
-
restore
public java.util.List<T> restore(java.util.List<T> target)
Restore the text to original. Opposite to applyTo() method.- Parameters:
target
- the given target- Returns:
- the restored text
-
addDelta
public void addDelta(AbstractDelta<T> delta)
Add the given delta to this patch- Parameters:
delta
- the given delta
-
getDeltas
public java.util.List<AbstractDelta<T>> getDeltas()
Get the list of computed deltas- Returns:
- the deltas
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
generate
public static <T> Patch<T> generate(java.util.List<T> original, java.util.List<T> revised, java.util.List<Change> changes)
-
buildChunk
private static <T> Chunk<T> buildChunk(int start, int end, java.util.List<T> data)
-
-