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();
}
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();
}
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();
}
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;
}
}
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;
}
Aggregations