Подскажите что не так, тестил в идее, все проходит
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 {
String f1;
String f2;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
f1 = reader.readLine();
f2 = reader.readLine();
}
ArrayList<String> f1Data = new ArrayList<>();
ArrayList<String> f2Data = new ArrayList<>();
try (BufferedReader f1Reader = new BufferedReader(new FileReader(f1));
BufferedReader f2Reader = new BufferedReader(new FileReader(f2))) {
while (f1Reader.ready()) {
f1Data.add(f1Reader.readLine());
}
while (f2Reader.ready()) {
f2Data.add(f2Reader.readLine());
}
}
int countF1 = 1;
int countF2 = 1;
while (countF1 < f1Data.size() && countF2 < f2Data.size()) {
if (f1Data.get(countF1-1).equals(f2Data.get(countF2-1))) {
lines.add(new LineItem(Type.SAME, f1Data.get(countF1)));
countF1++;
countF2++;
} else if (f1Data.get(countF1).equals(f2Data.get(countF2-1))) {
lines.add(new LineItem(Type.REMOVED, f1Data.get(countF1-1)));
lines.add(new LineItem(Type.SAME, f1Data.get(countF1)));
countF1+=2;
countF2++;
} else if (f1Data.get(countF1-1).equals(f2Data.get(countF2))) {
lines.add(new LineItem(Type.ADDED, f2Data.get(countF2-1)));
lines.add(new LineItem(Type.SAME, f2Data.get(countF2)));
countF1++;
countF2+=2;
}
}
while (countF1 <= f1Data.size()) {
if (!(countF2 > f2Data.size())) {
if (f1Data.get(countF1-1).equals(f2Data.get(countF2-1))) {
lines.add(new LineItem(Type.SAME, f1Data.get(countF1 - 1)));
countF2++;
} else {
lines.add(new LineItem(Type.REMOVED, f1Data.get(countF1-1)));
countF1++;
}
} else {
lines.add(new LineItem(Type.REMOVED, f1Data.get(countF1 - 1)));
}
countF1++;
}
while (countF2 <= f2Data.size()) {
lines.add(new LineItem(Type.ADDED, f2Data.get(countF2 - 1)));
countF2 ++;
}
}
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;
}
}
}