Помогите, пожалуйста найти ошибку.
Спасибо.
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;
/*
Отслеживаем изменения
*/
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));
String nameFile_1 = reader.readLine();
String nameFile_2 = reader.readLine();
reader.close();
ArrayList<String> list_old = new ArrayList<>();
ArrayList<String> list_new = new ArrayList<>();
BufferedReader br_old = new BufferedReader(new FileReader(nameFile_1));
String buff_old;
while ((buff_old = br_old.readLine()) != null){
list_old.add(buff_old);
}
br_old.close();
BufferedReader br_new = new BufferedReader(new FileReader(nameFile_2));
String buff_new;
while ((buff_new = br_new.readLine()) != null){
list_new.add(buff_new);
}
br_new.close();
if (list_old.size() < list_new.size()) {
for (int i = 0; i < list_old.size(); i++) {
if (list_old.get(i).equals(list_new.get(i))) {
lines.add(new LineItem(Type.SAME, list_old.get(i)));
} else if (list_old.get(i).equals(list_new.get(i + 1))) {
lines.add(new LineItem(Type.ADDED, list_new.get(i)));
list_old.add(i, "ADDED_add");
} else if (list_old.get(i + 1).equals(list_new.get(i))) {
lines.add(new LineItem(Type.REMOVED, list_old.get(i)));
list_new.add(i, "REMOVED_add");
}
}
} else {
for (int i = 0; i < list_new.size(); i++) {
if (list_old.get(i).equals(list_new.get(i))) {
lines.add(new LineItem(Type.SAME, list_old.get(i)));
} else if (list_old.get(i).equals(list_new.get(i + 1))) {
lines.add(new LineItem(Type.ADDED, list_new.get(i)));
list_old.add(i, "ADDED_add");
} else if (list_old.get(i + 1).equals(list_new.get(i))) {
lines.add(new LineItem(Type.REMOVED, list_old.get(i)));
list_new.add(i, "REMOVED_add");
}
}
}
if (list_old.size() > list_new.size()){
lines.add(new LineItem(Type.REMOVED, list_old.get(list_old.size() - 1)));
} else lines.add(new LineItem(Type.ADDED, list_new.get(list_new.size() - 1)));
for (LineItem x : lines){
System.out.println(x.type + " " + x.line);
}
}
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;
}
}
}