Java Code Examples for org.eclipse.jgit.diff.EditList#addAll()

The following examples show how to use org.eclipse.jgit.diff.EditList#addAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyersAlgorithm.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Override
public List<Comparison> compare(String source, String dest) {

  if ((source == null) || (dest == null)) {
    LOGGER.error("Source is {} and dest is {}", source, dest);
    throw new RuntimeException("Source and dest must not be null");
  }

  EditList diffList = new EditList();
  diffList.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT,
      new RawText(source.getBytes()), new RawText(dest.getBytes())));

  List<Comparison> comparisonList = new ArrayList<>();

  diffList.stream().forEachOrdered(edit -> {
    ComparisionType comparisionType;
    switch (edit.getType()) {
      case INSERT:
        comparisionType = ComparisionType.INSERT;
        break;
      case DELETE:
        comparisionType = ComparisionType.DELETE;
        break;
      case REPLACE:
        comparisionType = ComparisionType.REPLACE;
        break;
      default:
        comparisionType = ComparisionType.EQUAL;
        break;
    }
    comparisonList
        .add(new Comparison(comparisionType, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB()));
  });
  return comparisonList;
}
 
Example 2
Source File: HistogramDiff.java    From java-diff-utils with Apache License 2.0 5 votes vote down vote up
@Override
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
    Objects.requireNonNull(source, "source list must not be null");
    Objects.requireNonNull(target, "target list must not be null");
    if (progress != null) {
        progress.diffStart();
    }
    EditList diffList = new EditList();
    diffList.addAll(new org.eclipse.jgit.diff.HistogramDiff().diff(new DataListComparator<>(progress), new DataList<>(source), new DataList<>(target)));
    List<Change> patch = new ArrayList<>();
    for (Edit edit : diffList) {
        DeltaType type = DeltaType.EQUAL;
        switch (edit.getType()) {
            case DELETE:
                type = DeltaType.DELETE;
                break;
            case INSERT:
                type = DeltaType.INSERT;
                break;
            case REPLACE:
                type = DeltaType.CHANGE;
                break;
        }
        patch.add(new Change(type, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB()));
    }
    if (progress != null) {
        progress.diffEnd();
    }
    return patch;
}