All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fitnesse.responders.versions.VersionComparer Maven / Gradle / Ivy

There is a newer version: 20241026
Show newest version
package fitnesse.responders.versions;

import java.util.LinkedList;
import java.util.List;

import difflib.DiffUtils;
import difflib.Patch;

public class VersionComparer {

  private List differences;

  public boolean compare(String originalVersion, String originalContent, String revisedVersion, String revisedContent) {
    Patch patch = DiffUtils.diff(contentToLines(originalContent), contentToLines(revisedContent));
    differences = DiffUtils.generateUnifiedDiff(originalVersion, revisedVersion,
        contentToLines(originalContent), patch, 5);
    return true;
  }

  public List getDifferences() {
    return differences;
  }

  private List contentToLines(String content) {
    List lines = new LinkedList<>();
    for(String line : content.split("\n"))
      lines.add(line);
    return lines;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy