Guys,
Can you help me out here? I can't understand how to fix my code exactly...
package com.codegym.task.task19.task1916;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Tracking changes
*/
public class Solution {
public static List<LineItem> lines = new ArrayList<>();
public static void main(String[] args) throws IOException {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String file1 = reader.readLine();
String file2 = reader.readLine();
FileReader fileReader1 = new FileReader(file1);
FileReader fileReader2 = new FileReader(file2);
fileReader1.close();
fileReader2.close();
trackingChanges(fileReader1, fileReader2);
} catch (IOException e){}
}
public static void trackingChanges(FileReader reader1, FileReader reader2) throws IOException {
BufferedReader readOrg = new BufferedReader(reader1);
BufferedReader readUpd = new BufferedReader(reader2);
List<String> org = new ArrayList<>();
List<String> upd = new ArrayList<>();
while (readOrg.ready() && readUpd.ready()){
org.add(readOrg.readLine());
upd.add(readUpd.readLine());
}
readOrg.close();
readUpd.close();
int count1 = 0;
int count2 = 0;
while ((count1 != org.size()) && (count2 != upd.size())){
if (org.get(count1).equals(upd.get(count2))){
lines.add(new LineItem(Type.SAME, org.get(count1)));
count1++;
count2++;
}
else if (upd.get(count2).equals(org.get(count1 + 1))){
lines.add(new LineItem(Type.REMOVED, org.get(count1)));
count1++;
}
else {
lines.add(new LineItem(Type.ADDED, upd.get(count2)));
count2++;
}
}
}
public static enum Type {
ADDED, // New line added
REMOVED, // Line deleted
SAME // No change
}
public static class LineItem {
public Type type;
public String line;
public LineItem(Type type, String line) {
this.type = type;
this.line = line;
}
}
}