Search in sources :

Example 6 with Patch

use of difflib.Patch in project disconf by knightliao.

the class FileComparator method getDeltas.

private List<Delta> getDeltas() throws IOException {
    final List<String> originalFileLines = fileToLines(original);
    final List<String> revisedFileLines = fileToLines(revised);
    final Patch patch = DiffUtils.diff(originalFileLines, revisedFileLines);
    return patch.getDeltas();
}
Also used : Patch(difflib.Patch)

Example 7 with Patch

use of difflib.Patch in project disconf by knightliao.

the class FileComparator method getDeltas.

protected List<Delta> getDeltas() throws IOException {
    final List<String> originalFileLines = fileToLines(original);
    final List<String> revisedFileLines = fileToLines(revised);
    final Patch patch = DiffUtils.diff(originalFileLines, revisedFileLines);
    return patch.getDeltas();
}
Also used : Patch(difflib.Patch)

Example 8 with Patch

use of difflib.Patch in project disconf by knightliao.

the class StringComparator method getDeltas.

protected List<Delta> getDeltas() throws IOException {
    final List<String> originalFileLines = StringToLines(original);
    final List<String> revisedFileLines = StringToLines(revised);
    final Patch patch = DiffUtils.diff(originalFileLines, revisedFileLines);
    return patch.getDeltas();
}
Also used : Patch(difflib.Patch)

Example 9 with Patch

use of difflib.Patch in project phoenix by apache.

the class QueryVerifier method doDiff.

/**
     * Do a diff between exported query results and temporary CSV file
     *
     * @param query
     * @param newCSV
     * @return
     */
public boolean doDiff(Query query, String newCSV) {
    List<String> original = fileToLines(getCSVName(query, PherfConstants.EXPORT_DIR, ""));
    List<String> newLines = fileToLines(newCSV);
    Patch patch = DiffUtils.diff(original, newLines);
    if (patch.getDeltas().isEmpty()) {
        logger.info("Match: " + query.getId() + " with " + newCSV);
        return true;
    } else {
        logger.error("DIFF FAILED: " + query.getId() + " with " + newCSV);
        return false;
    }
}
Also used : Patch(difflib.Patch)

Example 10 with Patch

use of difflib.Patch in project Gargoyle by callakrsos.

the class RelocateFileComparator method getDeltas.

/**
	 * 비교결과 리턴
	 *
	 * @return
	 * @throws Exception
	 */
private CompareResult getDeltas() throws Exception {
    CompareResult result = new CompareResult();
    List<String> originalFileLines = fileToLines(original);
    List<String> revisedFileLines = fileToLines(revised);
    int max = Math.max(originalFileLines.size(), revisedFileLines.size());
    // array copy
    ArrayList<String> tmpOriginalFileLines = new ArrayList<String>();
    originalFileLines.forEach(str -> {
        tmpOriginalFileLines.add(str);
    });
    while (tmpOriginalFileLines.size() <= max) {
        tmpOriginalFileLines.add("");
    }
    ArrayList<String> tmpReviceFileLines = new ArrayList<String>();
    revisedFileLines.forEach(str -> {
        tmpReviceFileLines.add(str);
    });
    while (tmpReviceFileLines.size() <= max) {
        tmpReviceFileLines.add("");
    }
    // occur .. exception..
    // Collections.copy(originalFileLines, tmpOriginalFileLines);
    result.setOriginalFileLines(tmpOriginalFileLines);
    result.setRevisedFileLines(tmpReviceFileLines);
    final Patch patch = DiffUtils.diff(originalFileLines, revisedFileLines);
    List<Chunk> listOfOriginChanges = new ArrayList<Chunk>();
    List<Chunk> listOfReviceChanges = new ArrayList<Chunk>();
    List<Delta> deltas = patch.getDeltas();
    Collections.reverse(deltas);
    for (Delta delta : deltas) {
        Chunk original = delta.getOriginal();
        Chunk revised = delta.getRevised();
        int position = original.getPosition();
        @SuppressWarnings("unchecked") List<String> lines = (List<String>) original.getLines();
        @SuppressWarnings("unchecked") List<String> lines2 = (List<String>) revised.getLines();
        switch(delta.getType()) {
            case DELETE:
                break;
            case INSERT:
                {
                    // tmpOriginalFileLines.addAll(position, lines2);
                    tmpReviceFileLines.addAll(position, lines);
                    break;
                }
            case CHANGE:
                {
                    LinkedList<String> src = new LinkedList<>();
                    List<String> tmp1 = null;
                    List<String> tmp2 = null;
                    int compare = Integer.compare(lines.size(), lines2.size());
                    if (compare >= 0) {
                        tmp1 = lines;
                        tmp2 = lines2;
                    } else {
                        tmp1 = lines2;
                        tmp2 = lines;
                    }
                    tmp1.forEach(str -> {
                        src.add(str);
                    });
                    try {
                        for (int i = 0; i < tmp2.size(); i++) {
                            src.set(i, tmp2.get(i));
                        }
                        for (int i = tmp2.size(); i < src.size(); i++) src.set(i, "");
                    } catch (IndexOutOfBoundsException e) {
                        e.printStackTrace();
                    }
                    if (compare == 1) {
                        tmpReviceFileLines.addAll(position, src);
                        tmpReviceFileLines.remove(position + src.size());
                    } else {
                        tmpOriginalFileLines.addAll(position, src);
                        tmpOriginalFileLines.remove(position + src.size());
                    }
                }
                break;
            default:
                break;
        }
        listOfOriginChanges.add(delta.getOriginal());
        listOfReviceChanges.add(delta.getRevised());
    }
    result.setListOfOriginChanges(listOfOriginChanges);
    result.setListOfReviceChanges(listOfReviceChanges);
    return result;
}
Also used : List(java.util.List) Patch(difflib.Patch) Chunk(difflib.Chunk) LinkedList(java.util.LinkedList) DiffUtils(difflib.DiffUtils) Collections(java.util.Collections) Delta(difflib.Delta) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Chunk(difflib.Chunk) LinkedList(java.util.LinkedList) Delta(difflib.Delta) List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) Patch(difflib.Patch)

Aggregations

Patch (difflib.Patch)11 Delta (difflib.Delta)6 Chunk (difflib.Chunk)4 File (java.io.File)4 URL (java.net.URL)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Test (org.junit.Test)3 Migrator (com.evolveum.midpoint.model.impl.migrator.Migrator)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 DiffUtils (difflib.DiffUtils)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1