Class DiffRowGenerator

java.lang.Object
com.github.difflib.text.DiffRowGenerator

public final class DiffRowGenerator extends Object
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();
  • Field Details

    • DEFAULT_EQUALIZER

      public static final BiPredicate<String,String> DEFAULT_EQUALIZER
    • IGNORE_WHITESPACE_EQUALIZER

      public static final BiPredicate<String,String> IGNORE_WHITESPACE_EQUALIZER
    • LINE_NORMALIZER_FOR_HTML

      public static final Function<String,String> LINE_NORMALIZER_FOR_HTML
    • SPLITTER_BY_CHARACTER

      public static final Function<String,List<String>> SPLITTER_BY_CHARACTER
      Splitting lines by character to achieve char by char diff checking.
    • SPLIT_BY_WORD_PATTERN

      public static final Pattern SPLIT_BY_WORD_PATTERN
    • SPLITTER_BY_WORD

      public static final Function<String,List<String>> SPLITTER_BY_WORD
      Splitting lines by word to achieve word by word diff checking.
    • WHITESPACE_PATTERN

      public static final Pattern WHITESPACE_PATTERN
    • columnWidth

      private final int columnWidth
    • equalizer

      private final BiPredicate<String,String> equalizer
    • ignoreWhiteSpaces

      private final boolean ignoreWhiteSpaces
    • inlineDiffSplitter

      private final Function<String,List<String>> inlineDiffSplitter
    • mergeOriginalRevised

      private final boolean mergeOriginalRevised
    • newTag

      private final BiFunction<DiffRow.Tag,Boolean,String> newTag
    • oldTag

      private final BiFunction<DiffRow.Tag,Boolean,String> oldTag
    • reportLinesUnchanged

      private final boolean reportLinesUnchanged
    • lineNormalizer

      private final Function<String,String> lineNormalizer
    • processDiffs

      private final Function<String,String> processDiffs
    • showInlineDiffs

      private final boolean showInlineDiffs
    • replaceOriginalLinefeedInChangesWithSpaces

      private final boolean replaceOriginalLinefeedInChangesWithSpaces
    • decompressDeltas

      private final boolean decompressDeltas
  • Constructor Details

  • Method Details

    • create

      public static DiffRowGenerator.Builder create()
    • adjustWhitespace

      private static String adjustWhitespace(String raw)
    • splitStringPreserveDelimiter

      protected static final List<String> splitStringPreserveDelimiter(String str, Pattern SPLIT_PATTERN)
    • 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

      public List<DiffRow> generateDiffRows(List<String> original, List<String> revised)
      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 text
      revised - the revised text
      Returns:
      the DiffRows between original and revised texts
    • generateDiffRows

      public List<DiffRow> generateDiffRows(List<String> original, Patch<String> patch)
      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 text
      patch - 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

      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. With this problems of building DiffRows getting smaller.
      Parameters:
      deltaList -
    • buildDiffRow

      private DiffRow buildDiffRow(DiffRow.Tag type, String orgline, String newline)
    • buildDiffRowWithoutNormalizing

      private DiffRow buildDiffRowWithoutNormalizing(DiffRow.Tag type, String orgline, String newline)
    • normalizeLines

      List<String> normalizeLines(List<String> list)
    • generateInlineDiffs

      private List<DiffRow> generateInlineDiffs(AbstractDelta<String> delta)
      Add the inline diffs for given delta
      Parameters:
      delta - the given delta
    • preprocessLine

      private String preprocessLine(String line)