Выводит вроде все правильно но последний пункт не проходит
package com.javarush.task.task19.task1916;
import java.io.BufferedReader;
import java.io.FileReader;
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 Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
reader.close();
FileReader fileReader1 = new FileReader(file1);
FileReader fileReader2 = new FileReader(file2);
BufferedReader fileBufferedReader1 = new BufferedReader(fileReader1);
BufferedReader fileBufferedReader2 = new BufferedReader(fileReader2);
ArrayList<String> textFile1 = new ArrayList<>();
ArrayList<String> textFile2 = new ArrayList<>();
while (fileBufferedReader1.ready()) {
textFile1.add(fileBufferedReader1.readLine());
}
fileBufferedReader1.close();
fileReader1.close();
while (fileBufferedReader2.ready()) {
textFile2.add(fileBufferedReader2.readLine());
}
fileBufferedReader2.close();
fileReader2.close();
if (textFile1.size() < textFile2.size()) {
while (!textFile1.isEmpty()) {
if (textFile1.get(0).equals(textFile2.get(0))) {
lines.add(new LineItem(Type.SAME, textFile1.get(0)));
textFile1.remove(0);
textFile2.remove(0);
} else {
if (textFile1.get(1).equals(textFile2.get(0))) {
lines.add(new LineItem(Type.REMOVED, textFile1.get(0)));
textFile1.remove(0);
} else {
lines.add(new LineItem(Type.ADDED, textFile2.get(0)));
textFile2.remove(0);
}
}
}
} else {
while (!textFile2.isEmpty()) {
if (textFile1.get(0).equals(textFile2.get(0))) {
lines.add(new LineItem(Type.SAME, textFile1.get(0)));
textFile1.remove(0);
textFile2.remove(0);
} else if (textFile1.get(1).equals(textFile2.get(0))) {
lines.add(new LineItem(Type.REMOVED, textFile1.get(0)));
textFile1.remove(0);
} else {
lines.add(new LineItem(Type.ADDED, textFile2.get(0)));
textFile2.remove(0);
}
}
}
if (!textFile1.isEmpty()){
lines.add(new LineItem(Type.REMOVED, textFile1.get(0)));
}
if (!textFile2.isEmpty()){
lines.add(new LineItem(Type.ADDED, textFile2.get(0)));
}
for (LineItem item : lines) {
System.out.println(item.type + " " + item.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;
}
}
}