Home
Categories
Dictionary
Download
Project Details
Changes Log
License

DefaultDiffEngine


    1  Usage
    2  Example
    3  See also

The DefaultDiffEngine class allows to apply a GNU diff to get a list of differences for the left text and the right text. This class is not a Swing component, and allows to use the diff for non GUI usages (for example creating an Excel file with the content of the diff).

Usage

  1. The DefaultDiffEngine(List, List) creates the engine with the left and right text content
  2. The DiffEngine.populate() populates the diff
After calling the populate() method, you can use the DefaultDiffEngine.getLeftDiffLines() and DefaultDiffEngine.getRightDiffLines() to get the differences for the left and right content.

Each DiffEngine.DiffLine element in the left or right diff has the following methods: By default the left text value for a DiffEngine.NEW line, or the right text value for a DiffEngine.DELETED is null.

Example

      List<String> leftList = new ArrayList<>();
      leftList.add("firstline");
      leftList.add("secondline");

      List<String> rightList = new ArrayList<>();
      rightList.add("firstline");
      
      DefaultDiffEngine diffEngine = new DefaultDiffEngine(leftList, rightList);
      DiffBase diffBase = diffEngine.populate();
      assertTrue("Content is changed", diffBase.isChanged());
      
      List<DiffEngine.DiffLine> leftDiff = diffEngine.getLeftDiffLines();
      List<DiffEngine.DiffLine> rightDiff = diffEngine.getRightDiffLines();

See also


Categories: diff

Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence