Package com.github.difflib
Class DiffUtils
- java.lang.Object
-
- com.github.difflib.DiffUtils
-
public final class DiffUtils extends Object
Implements the difference and patching engine
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Patch<String>diff(String sourceText, String targetText, DiffAlgorithmListener progress)Computes the difference between the original and revised text.static <T> Patch<T>diff(List<T> original, List<T> revised)static <T> Patch<T>diff(List<T> original, List<T> revised, boolean includeEqualParts)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 algorithmstatic Patch<String>diffInline(String original, String revised)Computes the difference between the given texts inline.static <T> List<T>patch(List<T> original, Patch<T> patch)Patch the original text with given patchstatic <T> List<T>unpatch(List<T> revised, Patch<T> patch)Unpatch the revised text for a given patchstatic voidwithDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
-
-
-
Method Detail
-
withDefaultDiffAlgorithmFactory
public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
-
diff
public static <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 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
public static Patch<String> diff(String sourceText, String targetText, DiffAlgorithmListener progress)
Computes the difference between the original and revised text.
-
diff
public static <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 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). Ifnullthe 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
public 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 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
public static Patch<String> diffInline(String original, String revised)
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:
-
patch
public static <T> List<T> patch(List<T> original, Patch<T> patch) throws PatchFailedException
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
-
-