Пытался решить сам, но в итоге наткнулся на совет по решению и всё равно не принимает. Помогите разобраться, пожалуйста.
package com.javarush.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;
import java.util.regex.Pattern;
/*
Отслеживаем изменения
*/
public class Solution {
public static List<LineItem> lines = new ArrayList<LineItem>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader file1 = new BufferedReader(new FileReader(reader.readLine()));
BufferedReader file2 = new BufferedReader(new FileReader(reader.readLine()));
reader.close();
ArrayList<String> lineList1 = new ArrayList<>();
ArrayList<String> lineList2 = new ArrayList<>();
while (file1.ready()){
lineList1.add(file1.readLine());
}
while (file2.ready()){
lineList2.add(file2.readLine());
}
file1.close();
file2.close();
int size = lineList1.size();
if (size > lineList2.size()) size = lineList2.size();
for (int x = 0; x < size; x++){
if (lineList1.get(0).equals(lineList2.get(0))){
lines.add(new LineItem(Type.SAME, lineList1.get(0)));
lineList1.remove(0);
lineList2.remove(0);
}
else if (lineList1.get(0).equals(lineList2.get(1))){
lines.add(new LineItem(Type.ADDED, lineList2.get(0)));
lines.add(new LineItem(Type.SAME, lineList1.get(0)));
lineList1.remove(0);
lineList2.remove(0);
lineList2.remove(0);
}
else if (lineList1.get(1).equals(lineList2.get(0))){
lines.add(new LineItem(Type.REMOVED, lineList1.get(0)));
lines.add(new LineItem(Type.SAME, lineList2.get(0)));
lineList1.remove(0);
lineList1.remove(0);
lineList2.remove(0);
}
}
if (lineList1.size() > lineList2.size()) {
lines.add(new LineItem(Type.REMOVED, lineList1.get(0)));
}
else if (lineList1.size() < lineList2.size()){
lines.add(new LineItem(Type.ADDED, lineList2.get(0)));
}
}
public static enum Type {
ADDED, //добавлена новая строка
REMOVED, //удалена строка
SAME //без изменений
}
public static class LineItem {
public Type type;
public String line;
public LineItem(Type type, String line) {
this.type = type;
this.line = line;
}
}
}