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

  • 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)
    • processEqualities

      protected String processEqualities(String text)
      Hook for processing equal (unchanged) text segments. Delegates to the builder-configured equalityProcessor if present.
      Parameters:
      text -
      Returns: