Package com.github.difflib
Class DiffUtils
java.lang.Object
com.github.difflib.DiffUtils
Implements the difference and patching engine
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static DiffAlgorithmFactory
This factory generates the DEFAULT_DIFF algorithm for all these routines. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncompressLines
(List<String> lines, String delimiter) diff
(String sourceText, String targetText, DiffAlgorithmListener progress) Computes the difference between the original and revised text.static <T> Patch<T>
static <T> Patch<T>
static <T> Patch<T>
diff
(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm) Computes the difference between the original and revised list of elements with default diff algorithmstatic <T> Patch<T>
diff
(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) static <T> Patch<T>
diff
(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress, boolean includeEqualParts) Computes the difference between the original and revised list of elements with default diff algorithmstatic <T> Patch<T>
diff
(List<T> original, List<T> revised, DiffAlgorithmListener progress) Computes the difference between the original and revised list of elements with default diff algorithmstatic <T> Patch<T>
diff
(List<T> source, List<T> target, BiPredicate<T, T> equalizer) Computes the difference between the original and revised list of elements with default diff algorithmdiffInline
(String original, String revised) Computes the difference between the given texts inline.static <T> List<T>
Patch the original text with given patchstatic <T> List<T>
Unpatch the revised text for a given patchstatic void
-
Field Details
-
DEFAULT_DIFF
This factory generates the DEFAULT_DIFF algorithm for all these routines.
-
-
Constructor Details
-
DiffUtils
private DiffUtils()
-
-
Method Details
-
withDefaultDiffAlgorithmFactory
-
diff
Computes the difference between the original and revised list of elements with default diff algorithm- Type Parameters:
T
- types to be diffed- Parameters:
original
- The original text. Must not benull
.revised
- The revised text. Must not benull
.progress
- progress listener- Returns:
- The patch describing the difference between the original and
revised sequences. Never
null
.
-
diff
-
diff
-
diff
public static Patch<String> diff(String sourceText, String targetText, DiffAlgorithmListener progress) Computes the difference between the original and revised text. -
diff
Computes the difference between the original and revised list of elements with default diff algorithm- Parameters:
source
- The original text. Must not benull
.target
- The revised text. Must not benull
.equalizer
- the equalizer object to replace the default compare algorithm (Object.equals). Ifnull
the default equalizer of the default algorithm is used..- Returns:
- The patch describing the difference between the original and
revised sequences. Never
null
.
-
diff
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) -
diff
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress, boolean includeEqualParts) Computes the difference between the original and revised list of elements with default diff algorithm- Parameters:
original
- The original text. Must not benull
.revised
- The revised text. Must not benull
.algorithm
- The diff algorithm. Must not benull
.progress
- The diff algorithm listener.includeEqualParts
- Include equal data parts into the patch.- Returns:
- The patch describing the difference between the original and
revised sequences. Never
null
.
-
diff
Computes the difference between the original and revised list of elements with default diff algorithm- Parameters:
original
- The original text. Must not benull
.revised
- The revised text. Must not benull
.algorithm
- The diff algorithm. Must not benull
.- Returns:
- The patch describing the difference between the original and
revised sequences. Never
null
.
-
diffInline
Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of characters, like DiffRowGenerator does and merges those changes at the end together again.- Parameters:
original
-revised
-- Returns:
-
compressLines
-
patch
Patch the original text with given patch- Parameters:
original
- the original textpatch
- the given patch- Returns:
- the revised text
- Throws:
PatchFailedException
- if can't apply patch
-
unpatch
Unpatch the revised text for a given patch- Parameters:
revised
- the revised textpatch
- the given patch- Returns:
- the original text
-