через дебаггер проверил, условие выполняется правильно, если я его правильно пронял
package com.javarush.task.task19.task1916;
import java.io.*;
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();
BufferedReader fileReader1 = new BufferedReader(new FileReader(file1));
BufferedReader fileReader2 = new BufferedReader(new FileReader(file2));
ArrayList<String> arrayList1 = new ArrayList<>();
ArrayList<String> arrayList2 = new ArrayList<>();
String str = "";
boolean b1 = fileReader1.ready();
boolean b2 = fileReader2.ready();
while (fileReader1.ready()) {
char ch = (char) fileReader1.read();
str += String.valueOf(ch);
}
String[] strArray1 = str.split("\n");
for (int i = 0; i < strArray1.length; i++) {
arrayList1.add(strArray1[i]);
}
str = "";
while (fileReader2.ready()) {
char ch = (char) fileReader2.read();
str += String.valueOf(ch);
}
int j = 0;
String[] strArray2 = str.split("\n");
for (int i = 0; i < strArray2.length; i++) {
arrayList2.add(strArray2[i]);
}
if (arrayList1.size()>arrayList2.size()) {
while (arrayList2.size()!=arrayList1.size()) {
arrayList2.add(arrayList2.size(), "");
}
}
if (arrayList2.size()>arrayList1.size()) {
while (arrayList1.size()!=arrayList2.size()) {
arrayList1.add(arrayList1.size(), "");
}
}
for (int i = 0; i < arrayList1.size(); i++) {
String s1 = arrayList1.get(i);
String s2 = arrayList2.get(i);
if ((!(s1.trim().length()==0)) && (!(s2.trim().length()==0))) {
if (!(arrayList1.get(i).equals(arrayList2.get(i)))&&!(arrayList2.get(i).equals(arrayList1.get(i)))) {
lines.add(new LineItem(Type.SAME, arrayList1.get(i) + " " + arrayList2.get(i)));
} else if (arrayList1.get(i).equals(arrayList2.get(i))&&arrayList2.get(i).equals(arrayList1.get(i))) {
lines.add(new LineItem(Type.SAME, arrayList2.get(i)));
}
} else if (arrayList1.get(i).trim().length()==0) {
lines.add(new LineItem(Type.ADDED, arrayList2.get(i)));
} else if (arrayList2.get(i).trim().length()==0) {
lines.add(new LineItem(Type.REMOVED, arrayList1.get(i)));
}
}
System.out.println(lines);
fileReader1.close();
fileReader2.close();
}
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;
}
}
}