mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
removed abstract example class
This commit is contained in:
@@ -5,16 +5,19 @@ import difflib.TestConstants;
|
||||
import difflib.UnifiedDiffUtils;
|
||||
import difflib.patch.Patch;
|
||||
import difflib.patch.PatchFailedException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
public class ApplyPatch extends Example {
|
||||
public class ApplyPatch {
|
||||
|
||||
static final String ORIGINAL = TestConstants.MOCK_FOLDER + "issue10_base.txt";
|
||||
static final String PATCH = TestConstants.MOCK_FOLDER + "issue10_patch.txt";
|
||||
|
||||
public static void main(String[] args) throws PatchFailedException {
|
||||
List<String> original = fileToLines(ORIGINAL);
|
||||
List<String> patched = fileToLines(PATCH);
|
||||
public static void main(String[] args) throws PatchFailedException, IOException {
|
||||
List<String> original = Files.readAllLines(new File(ORIGINAL).toPath());
|
||||
List<String> patched = Files.readAllLines(new File(PATCH).toPath());
|
||||
|
||||
// At first, parse the unified diff file and get the patch
|
||||
Patch<String> patch = UnifiedDiffUtils.parseUnifiedDiff(patched);
|
||||
|
||||
@@ -5,16 +5,19 @@ import difflib.TestConstants;
|
||||
import difflib.algorithm.DiffException;
|
||||
import difflib.patch.Delta;
|
||||
import difflib.patch.Patch;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
public class ComputeDifference extends Example {
|
||||
public class ComputeDifference {
|
||||
|
||||
static final String ORIGINAL = TestConstants.MOCK_FOLDER + "original.txt";
|
||||
static final String RIVISED = TestConstants.MOCK_FOLDER + "revised.txt";
|
||||
|
||||
public static void main(String[] args) throws DiffException {
|
||||
List<String> original = fileToLines(ORIGINAL);
|
||||
List<String> revised = fileToLines(RIVISED);
|
||||
public static void main(String[] args) throws DiffException, IOException {
|
||||
List<String> original = Files.readAllLines(new File(ORIGINAL).toPath());
|
||||
List<String> revised = Files.readAllLines(new File(RIVISED).toPath());
|
||||
|
||||
// Compute diff. Get the Patch object. Patch is the container for computed deltas.
|
||||
Patch<String> patch = DiffUtils.diff(original, revised);
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package difflib.examples;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Example {
|
||||
|
||||
/**
|
||||
* File separator.
|
||||
*/
|
||||
protected static final String FS = File.separator;
|
||||
/**
|
||||
* The base resource path.
|
||||
*/
|
||||
protected static String BASE_PATH = "src" + FS + "test" + FS + "resources";
|
||||
|
||||
/**
|
||||
* Tries to read the file and split it into a list of lines.
|
||||
*
|
||||
* @param filename The filename as path.
|
||||
* @return A list of lines.
|
||||
*/
|
||||
public static List<String> fileToLines(String filename) {
|
||||
List<String> lines = new LinkedList<>();
|
||||
String line = "";
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(filename));
|
||||
while ((line = in.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
// ignore ... any errors should already have been
|
||||
// reported via an IOException from the final flush.
|
||||
}
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user