Package com.github.difflib
Class DiffUtils
- java.lang.Object
-
- com.github.difflib.DiffUtils
-
public final class DiffUtils extends java.lang.Object
Implements the difference and patching engine
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static DiffAlgorithmFactory
DEFAULT_DIFF
This factory generates the DEFAULT_DIFF algorithm for all these routines.
-
Constructor Summary
Constructors Modifier Constructor Description private
DiffUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.util.List<java.lang.String>
compressLines(java.util.List<java.lang.String> lines, java.lang.String delimiter)
static Patch<java.lang.String>
diff(java.lang.String sourceText, java.lang.String targetText, DiffAlgorithmListener progress)
Computes the difference between the original and revised text.static <T> Patch<T>
diff(java.util.List<T> original, java.util.List<T> revised)
static <T> Patch<T>
diff(java.util.List<T> original, java.util.List<T> revised, boolean includeEqualParts)
static <T> Patch<T>
diff(java.util.List<T> original, java.util.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(java.util.List<T> original, java.util.List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress)
static <T> Patch<T>
diff(java.util.List<T> original, java.util.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(java.util.List<T> original, java.util.List<T> revised, DiffAlgorithmListener progress)
Computes the difference between the original and revised list of elements with default diff algorithmstatic <T> Patch<T>
diff(java.util.List<T> source, java.util.List<T> target, java.util.function.BiPredicate<T,T> equalizer)
Computes the difference between the original and revised list of elements with default diff algorithmstatic Patch<java.lang.String>
diffInline(java.lang.String original, java.lang.String revised)
Computes the difference between the given texts inline.static <T> java.util.List<T>
patch(java.util.List<T> original, Patch<T> patch)
Patch the original text with given patchstatic <T> java.util.List<T>
unpatch(java.util.List<T> revised, Patch<T> patch)
Unpatch the revised text for a given patchstatic void
withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
-
-
-
Field Detail
-
DEFAULT_DIFF
static DiffAlgorithmFactory DEFAULT_DIFF
This factory generates the DEFAULT_DIFF algorithm for all these routines.
-
-
Method Detail
-
withDefaultDiffAlgorithmFactory
public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
-
diff
public static <T> Patch<T> diff(java.util.List<T> original, java.util.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 <T> Patch<T> diff(java.util.List<T> original, java.util.List<T> revised)
-
diff
public static <T> Patch<T> diff(java.util.List<T> original, java.util.List<T> revised, boolean includeEqualParts)
-
diff
public static Patch<java.lang.String> diff(java.lang.String sourceText, java.lang.String targetText, DiffAlgorithmListener progress)
Computes the difference between the original and revised text.
-
diff
public static <T> Patch<T> diff(java.util.List<T> source, java.util.List<T> target, java.util.function.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). 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(java.util.List<T> original, java.util.List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress)
-
diff
public static <T> Patch<T> diff(java.util.List<T> original, java.util.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(java.util.List<T> original, java.util.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<java.lang.String> diffInline(java.lang.String original, java.lang.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:
-
compressLines
private static java.util.List<java.lang.String> compressLines(java.util.List<java.lang.String> lines, java.lang.String delimiter)
-
patch
public static <T> java.util.List<T> patch(java.util.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
-
unpatch
public static <T> java.util.List<T> unpatch(java.util.List<T> revised, Patch<T> patch)
Unpatch the revised text for a given patch- Parameters:
revised
- the revised textpatch
- the given patch- Returns:
- the original text
-
-