Package com.github.difflib.text
Class DiffRowGenerator
java.lang.Object
com.github.difflib.text.DiffRowGenerator
This class for generating DiffRows for side-by-sidy view. You can customize
the way of generating. For example, show inline diffs on not, ignoring white
spaces or/and blank lines and so on. All parameters for generating are
optional. If you do not specify them, the class will use the default values.
These values are: showInlineDiffs = false; ignoreWhiteSpaces = true;
ignoreBlankLines = true; ...
For instantiating the DiffRowGenerator you should use the its builder. Like
in example
DiffRowGenerator generator = new DiffRowGenerator.Builder().showInlineDiffs(true).
ignoreWhiteSpaces(true).columnWidth(100).build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class used for building the DiffRowGenerator. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final booleanstatic final BiPredicate<String, String> private final BiPredicate<String, String> static final BiPredicate<String, String> private final booleanprivate final booleanprivate final BiFunction<DiffRow.Tag, Boolean, String> private final BiFunction<DiffRow.Tag, Boolean, String> private final booleanprivate final booleanprivate final booleanstatic final PatternSplitting lines by character to achieve char by char diff checking.Splitting lines by word to achieve word by word diff checking.static final Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringadjustWhitespace(String raw) private DiffRowbuildDiffRow(DiffRow.Tag type, String orgline, String newline) private DiffRowbuildDiffRowWithoutNormalizing(DiffRow.Tag type, String orgline, String newline) static DiffRowGenerator.Buildercreate()private List<AbstractDelta<String>> decompressDeltas(AbstractDelta<String> delta) Decompresses ChangeDeltas with different source and target size to a ChangeDelta with same size and a following InsertDelta or DeleteDelta.generateDiffRows(List<String> original, Patch<String> patch) Generates the DiffRows describing the difference between original and revised texts using the given patch.generateDiffRows(List<String> original, List<String> revised) Get the DiffRows describing the difference between original and revised texts using the given patch.generateInlineDiffs(AbstractDelta<String> delta) Add the inline diffs for given deltanormalizeLines(List<String> list) private StringpreprocessLine(String line) splitStringPreserveDelimiter(String str, Pattern SPLIT_PATTERN) private inttransformDeltaIntoDiffRow(List<String> original, int endPos, List<DiffRow> diffRows, AbstractDelta<String> delta) Transforms one patch delta into a DiffRow object.(package private) static voidwrapInTag(List<String> sequence, int startPosition, int endPosition, DiffRow.Tag tag, BiFunction<DiffRow.Tag, Boolean, String> tagGenerator, Function<String, String> processDiffs, boolean replaceLinefeedWithSpace) Wrap the elements in the sequence with the given tag
-
Field Details
-
DEFAULT_EQUALIZER
-
IGNORE_WHITESPACE_EQUALIZER
-
LINE_NORMALIZER_FOR_HTML
-
SPLITTER_BY_CHARACTER
Splitting lines by character to achieve char by char diff checking. -
SPLIT_BY_WORD_PATTERN
-
SPLITTER_BY_WORD
Splitting lines by word to achieve word by word diff checking. -
WHITESPACE_PATTERN
-
columnWidth
private final int columnWidth -
equalizer
-
ignoreWhiteSpaces
private final boolean ignoreWhiteSpaces -
inlineDiffSplitter
-
mergeOriginalRevised
private final boolean mergeOriginalRevised -
newTag
-
oldTag
-
reportLinesUnchanged
private final boolean reportLinesUnchanged -
lineNormalizer
-
processDiffs
-
showInlineDiffs
private final boolean showInlineDiffs -
replaceOriginalLinefeedInChangesWithSpaces
private final boolean replaceOriginalLinefeedInChangesWithSpaces -
decompressDeltas
private final boolean decompressDeltas
-
-
Constructor Details
-
DiffRowGenerator
-
-
Method Details
-
create
-
adjustWhitespace
-
splitStringPreserveDelimiter
-
wrapInTag
static void wrapInTag(List<String> sequence, int startPosition, int endPosition, DiffRow.Tag tag, BiFunction<DiffRow.Tag, Boolean, String> tagGenerator, Function<String, String> processDiffs, boolean replaceLinefeedWithSpace) Wrap the elements in the sequence with the given tag- Parameters:
startPosition- the position from which tag should start. The counting start from a zero.endPosition- the position before which tag should should be closed.tagGenerator- the tag generator
-
generateDiffRows
Get the DiffRows describing the difference between original and revised texts using the given patch. Useful for displaying side-by-side diff.- Parameters:
original- the original textrevised- the revised text- Returns:
- the DiffRows between original and revised texts
-
generateDiffRows
Generates the DiffRows describing the difference between original and revised texts using the given patch. Useful for displaying side-by-side diff.- Parameters:
original- the original textpatch- the given patch- Returns:
- the DiffRows between original and revised texts
-
transformDeltaIntoDiffRow
private int transformDeltaIntoDiffRow(List<String> original, int endPos, List<DiffRow> diffRows, AbstractDelta<String> delta) Transforms one patch delta into a DiffRow object. -
decompressDeltas
Decompresses ChangeDeltas with different source and target size to a ChangeDelta with same size and a following InsertDelta or DeleteDelta. With this problems of building DiffRows getting smaller.- Parameters:
deltaList-
-
buildDiffRow
-
buildDiffRowWithoutNormalizing
-
normalizeLines
-
generateInlineDiffs
Add the inline diffs for given delta- Parameters:
delta- the given delta
-
preprocessLine
-