use of difflib.Chunk in project Gargoyle by callakrsos.
the class DiffPathText method diffPathTest.
@Test
public void diffPathTest() throws IOException, URISyntaxException, PatchFailedException {
URL test1 = ClassLoader.getSystemClassLoader().getResource("compare/Test1");
URL test2 = ClassLoader.getSystemClassLoader().getResource("compare/Test2");
List<String> test1List = Files.readAllLines(new File(test1.toURI()).toPath());
List<String> test2List = Files.readAllLines(new File(test2.toURI()).toPath());
Patch diff = DiffUtils.diff(test1List, test2List);
List<Delta> deltas = diff.getDeltas();
deltas.stream().forEach(d -> {
Chunk original = d.getOriginal();
List<?> lines = original.getLines();
lines.stream().forEach(System.out::println);
});
// List<?> patch = DiffUtils.patch(test1List, diff);
// patch.stream().forEach(System.out::println);
//
// List<?> unpatch = DiffUtils.unpatch(test2List, diff);
// unpatch.stream().forEach(System.out::println);
}
use of difflib.Chunk in project Gargoyle by callakrsos.
the class DiffPathText method patchTest.
@Test
public void patchTest() throws IOException, URISyntaxException, PatchFailedException {
URL test1 = ClassLoader.getSystemClassLoader().getResource("compare/Test1");
URL test2 = ClassLoader.getSystemClassLoader().getResource("compare/Test2");
// 원본데이터 리스트
List<String> test1List = Files.readAllLines(new File(test1.toURI()).toPath());
List<String> test2List = Files.readAllLines(new File(test2.toURI()).toPath());
List<String> tmpOrigin = new LinkedList<String>();
test1List.forEach(str -> {
tmpOrigin.add(str);
});
List<String> tmpRevice = new LinkedList<String>();
test2List.forEach(str -> {
tmpRevice.add(str);
});
Patch diff = DiffUtils.diff(test1List, test2List);
System.out.println(diff.getDeltas());
List<Delta> deltas = diff.getDeltas();
Collections.reverse(deltas);
System.out.println("before");
System.out.println(tmpOrigin);
// 공백 작업pos
deltas.forEach(d -> {
Chunk original = d.getOriginal();
Chunk revised = d.getRevised();
int position = original.getPosition();
switch(d.getType()) {
case INSERT:
{
List<String> lines = (List<String>) original.getLines();
List<String> lines2 = (List<String>) revised.getLines();
tmpOrigin.addAll(position, lines2);
tmpRevice.addAll(position, lines);
}
break;
}
});
System.out.println("origin");
System.out.println(tmpOrigin);
System.out.println("revice");
System.out.println(tmpRevice);
// tmpOrigin.forEach(System.out::println);
}
use of difflib.Chunk in project Gargoyle by callakrsos.
the class HtmlBaseDiffAppController method extractedWrapperedChunk.
/**
* chunk객체를 UI로 표현하기 위해 wrapping처리함.
*
* @param deltaType
* @param deltas
* @param readLines
* @return
*/
private List<ChunkWrapper> extractedWrapperedChunk(final DeltaType deltaType, final List<Delta> deltas, final List<String> readLines) {
int size = readLines.size();
ArrayList<ChunkWrapper> collect = deltas.stream().map(delta -> {
Chunk chunk = null;
if (DeltaType.ORIGINAL == deltaType) {
chunk = delta.getOriginal();
} else {
chunk = delta.getRevised();
}
int position = chunk.getPosition();
@SuppressWarnings("unchecked") List<String> lines = (List<String>) chunk.getLines();
TYPE type = delta.getType();
ChunkWrapper chunkWrapper = new ChunkWrapper();
chunkWrapper.setType(type);
chunkWrapper.setLines(lines);
chunkWrapper.setChunk(chunk);
chunkWrapper.setPosition(position);
chunkWrapper.setDelta(delta);
return chunkWrapper;
}).collect(() -> {
ArrayList<ChunkWrapper> newChunk = new ArrayList<>(size);
for (int i = 0; i < readLines.size(); i++) {
ChunkWrapper chunkWrapper = new ChunkWrapper();
chunkWrapper.setStr(readLines.get(i));
chunkWrapper.setPosition(i);
newChunk.add(chunkWrapper);
}
return newChunk;
}, (collection, item) -> {
int position = item.getPosition();
List<String> lines = item.getLines();
TYPE type = item.getType();
int tmpPosition = position;
for (String str : lines) {
ChunkWrapper chunkWrapper = new ChunkWrapper();
chunkWrapper.setType(type);
chunkWrapper.setLines(lines);
chunkWrapper.setPosition(position);
chunkWrapper.setChunk(item.getChunk());
chunkWrapper.setStr(str);
chunkWrapper.setDelta(item.getDelta());
collection.set(tmpPosition++, chunkWrapper);
}
}, (collection1, collection2) -> collection1.addAll(collection2));
return collect;
}
use of difflib.Chunk in project Gargoyle by callakrsos.
the class FileBaseDiffAppController method extractedWrapperedChunk.
/**
* chunk객체를 UI로 표현하기 위해 wrapping처리함.
*
* @param deltaType
* @param deltas
* @param readLines
* @return
*/
private List<ChunkWrapper> extractedWrapperedChunk(final DeltaType deltaType, final List<Delta> deltas, final List<String> readLines) {
int size = readLines.size();
ArrayList<ChunkWrapper> collect = deltas.stream().map(delta -> {
Chunk chunk = null;
if (DeltaType.ORIGINAL == deltaType) {
chunk = delta.getOriginal();
} else {
chunk = delta.getRevised();
}
int position = chunk.getPosition();
@SuppressWarnings("unchecked") List<String> lines = (List<String>) chunk.getLines();
TYPE type = delta.getType();
ChunkWrapper chunkWrapper = new ChunkWrapper();
chunkWrapper.setType(type);
chunkWrapper.setLines(lines);
chunkWrapper.setChunk(chunk);
chunkWrapper.setPosition(position);
chunkWrapper.setDelta(delta);
return chunkWrapper;
}).collect(() -> {
ArrayList<ChunkWrapper> newChunk = new ArrayList<>(size);
for (int i = 0; i < readLines.size(); i++) {
ChunkWrapper chunkWrapper = new ChunkWrapper();
chunkWrapper.setStr(readLines.get(i));
chunkWrapper.setPosition(i);
newChunk.add(chunkWrapper);
}
return newChunk;
}, (collection, item) -> {
int position = item.getPosition();
List<String> lines = item.getLines();
TYPE type = item.getType();
int tmpPosition = position;
for (String str : lines) {
ChunkWrapper chunkWrapper = new ChunkWrapper();
chunkWrapper.setType(type);
chunkWrapper.setLines(lines);
chunkWrapper.setPosition(position);
chunkWrapper.setChunk(item.getChunk());
chunkWrapper.setStr(str);
chunkWrapper.setDelta(item.getDelta());
collection.set(tmpPosition++, chunkWrapper);
}
}, (collection1, collection2) -> collection1.addAll(collection2));
return collect;
}
use of difflib.Chunk in project disconf by knightliao.
the class FileComparatorTestCase method shouldGetInsertsBetweenFiles.
@Test
public void shouldGetInsertsBetweenFiles() {
final FileComparator comparator = new FileComparator(original, revised);
try {
final List<Chunk> insertsFromOriginal = comparator.getInsertsFromOriginal();
assertEquals(1, insertsFromOriginal.size());
final Chunk firstInsert = insertsFromOriginal.get(0);
final int firstLineOfFirstInsert = firstInsert.getPosition() + 1;
final int firstInsertSize = firstInsert.size();
assertEquals(7, firstLineOfFirstInsert);
assertEquals(1, firstInsertSize);
final String firstInsertText = firstInsert.getLines().get(0).toString();
assertEquals("new line 6.1", firstInsertText);
} catch (IOException ioe) {
fail("Error running test shouldGetInsertsBetweenFiles " + ioe.toString());
}
}
Aggregations