Валидатор не пропускает по последнему пункту. В рекомендациях от ментора совет убедиться, что "список lines в нужных местах содержит операции ADDED c нужными строками". Однако мой ответ ТОЧНО соответствует условию. Что не так?
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 bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String file1 = bufferedReader.readLine();
String file2 = bufferedReader.readLine();
bufferedReader.close();
BufferedReader reader1 = new BufferedReader(new FileReader(file1));
List<String> list1 = new ArrayList<>();
while (reader1.ready()) {
list1.add(reader1.readLine());
}
reader1.close();
BufferedReader reader2 = new BufferedReader(new FileReader(file2));
List<String> list2 = new ArrayList<>();
while (reader2.ready()) {
list2.add(reader2.readLine());
}
reader2.close();
if (list2.size() < list1.size()) {
for (int i = list2.size(); i < list1.size(); i++) {
list2.add("");
}
}
for (int i = 0; i < list1.size(); i++) {
String str1 = list1.get(i);
String str2 = list2.get(i);
if (str2.equals(str1)) {
lines.add(new LineItem(Type.SAME, str2));
} else if (list2.get(i + 1).equals(str1)) {
lines.add(new LineItem(Type.ADDED, str2));
list1.add(i, "");
} else {
lines.add(new LineItem(Type.REMOVED, str1));
list2.add(i, "");
}
}
}
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;
}
}
}