Убедись, что список lines в нужных местах содержит операции REMOVED 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 reader = new BufferedReader(new InputStreamReader(System.in));
String fileName1 = reader.readLine();
String fileName2 = reader.readLine();
reader.close();
BufferedReader bufferedReader1 = new BufferedReader(new FileReader(fileName1));
BufferedReader bufferedReader2 = new BufferedReader(new FileReader(fileName2));
ArrayList<String> file1List = new ArrayList<>();
ArrayList<String> file2List = new ArrayList<>();
while (bufferedReader1.ready()) {
String line = bufferedReader1.readLine();
file1List.add(line);
}
bufferedReader1.close();
while (bufferedReader2.ready()) {
String line = bufferedReader2.readLine();
file2List.add(line);
}
bufferedReader2.close();
boolean enter = false;
boolean flag = false;
int big;
int mid;
int max = 0;
if (file1List.size() > file2List.size()) {
max = file1List.size();
big = max - file2List.size();
mid = max - big;
enter = true;
} else if (file2List.size() > file1List.size()) {
max = file2List.size();
big = max - file1List.size();
mid = max - big;
flag = true;
enter = true;
} else {
mid = file1List.size();
}
int count = 0;
while (count < mid) {
if (!file1List.get(count).equals("") && !file2List.get(count).equals("")) {
lines.add(new LineItem(Type.SAME, file1List.get(count)));
count++;
} else if (!file1List.get(count).equals("") && file2List.get(count).equals("")) {
lines.add(new LineItem(Type.REMOVED, file1List.get(count)));
count++;
} else if (file1List.get(count).equals("") && !file2List.get(count).equals("")) {
lines.add(new LineItem(Type.ADDED, file2List.get(count)));
count++;
}
}
if (enter) {
if (!flag) {
while (count < max) {
lines.add(new LineItem(Type.REMOVED, file1List.get(count)));
count++;
}
} else {
while (count < max) {
lines.add(new LineItem(Type.ADDED, file2List.get(count)));
count++;
}
}
}
//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;
}
}
}