Class DiffUtils
java.lang.Object
com.github.difflib.DiffUtils
Utility class to implement the difference and patching engine.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static DiffAlgorithmFactoryThis 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 two strings using the default diff algorithm.static <T> Patch<T> Computes the difference between two sequences of elements using the default diff algorithm.static <T> Patch<T> Computes the difference between two sequences of elements using the default diff algorithm.static <T> Patch<T> diff(List<? extends T> original, List<? extends 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<? extends T> original, List<? extends T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) static <T> Patch<T> diff(List<? extends T> original, List<? extends 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<? extends T> original, List<? extends T> revised, DiffAlgorithmListener progress) Computes the difference between two sequences of elements using the default diff algorithm.static <T> Patch<T> diff(List<? extends T> source, List<? extends T> target, BiPredicate<? super T, ? super 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> Applies the given patch to the original list and returns the revised list.static <T> List<T> Applies the given patch to the revised list and returns the original list.static voidSets the default diff algorithm factory to be used by all diff routines.
-
Field Details
-
DEFAULT_DIFF
This factory generates the DEFAULT_DIFF algorithm for all these routines.
-
-
Constructor Details
-
DiffUtils
private DiffUtils()
-
-
Method Details
-
withDefaultDiffAlgorithmFactory
Sets the default diff algorithm factory to be used by all diff routines.- Parameters:
factory- aDiffAlgorithmFactoryrepresenting the new default diff algorithm factory.
-
diff
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised, DiffAlgorithmListener progress) Computes the difference between two sequences of elements using the default diff algorithm.- Type Parameters:
T- a generic representing the type of the elements to be compared.- Parameters:
original- aListrepresenting the original sequence of elements. Must not benull.revised- aListrepresenting the revised sequence of elements. Must not benull.progress- aDiffAlgorithmListenerrepresenting the progress listener. Can benull.- Returns:
- The patch describing the difference between the original and revised sequences. Never
null.
-
diff
Computes the difference between two sequences of elements using the default diff algorithm.- Type Parameters:
T- a generic representing the type of the elements to be compared.- Parameters:
original- aListrepresenting the original sequence of elements. Must not benull.revised- aListrepresenting the revised sequence of elements. Must not benull.- Returns:
- The patch describing the difference between the original and revised sequences. Never
null.
-
diff
public static <T> Patch<T> diff(List<? extends T> original, List<? extends T> revised, boolean includeEqualParts) Computes the difference between two sequences of elements using the default diff algorithm.- Type Parameters:
T- a generic representing the type of the elements to be compared.- Parameters:
original- aListrepresenting the original sequence of elements. Must not benull.revised- aListrepresenting the revised sequence of elements. Must not benull.includeEqualParts- arepresenting whether to include equal parts in the resulting patch.invalid reference
boolean- 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 two strings using the default diff algorithm.- Parameters:
sourceText- aStringrepresenting the original string. Must not benull.targetText- aStringrepresenting the revised string. Must not benull.progress- aDiffAlgorithmListenerrepresenting the progress listener. Can benull.- Returns:
- The patch describing the difference between the original and revised strings. Never
null.
-
diff
public static <T> Patch<T> diff(List<? extends T> source, List<? extends T> target, BiPredicate<? super T, ? super T> equalizer) Computes the difference between the original and revised list of elements with default diff algorithm- Parameters:
source- aListrepresenting the original text. Must not benull.target- aListrepresenting the revised text. Must not benull.equalizer- aBiPredicaterepresenting 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<? extends T> original, List<? extends T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) -
diff
public static <T> Patch<T> diff(List<? extends T> original, List<? extends 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- aListrepresenting the original text. Must not benull.revised- aListrepresenting the revised text. Must not benull.algorithm- aDiffAlgorithmIrepresenting the diff algorithm. Must not benull.progress- aDiffAlgorithmListenerrepresenting 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<? extends T> original, List<? extends T> revised, DiffAlgorithmI<T> algorithm) Computes the difference between the original and revised list of elements with default diff algorithm- Parameters:
original- aListrepresenting the original text. Must not benull.revised- aListrepresenting the revised text. Must not benull.algorithm- aDiffAlgorithmIrepresenting 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. -
patch
public static <T> List<T> patch(List<? extends T> original, Patch<T> patch) throws PatchFailedException Applies the given patch to the original list and returns the revised list.- Parameters:
original- aListrepresenting the original list.patch- aListrepresenting the patch to apply.- Returns:
- the revised list.
- Throws:
PatchFailedException- if the patch cannot be applied.
-
unpatch
Applies the given patch to the revised list and returns the original list.- Parameters:
revised- aListrepresenting the revised list.patch- aPatchrepresenting the patch to apply.- Returns:
- the original list.
- Throws:
PatchFailedException- if the patch cannot be applied.
-
compressLines
-