Добрый день. Подскажите пожалуйста где может быть ошибка.
package com.javarush.task.task19.task1916;
import java.util.ArrayList;
import java.util.*;
import java.io.*;
/*
Отслеживаем изменения
*/
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));
BufferedReader reader1=new BufferedReader(new FileReader(reader.readLine()));
BufferedReader reader2=new BufferedReader(new FileReader(reader.readLine()));
reader.close();
ArrayList<String> line1=new ArrayList<>();
ArrayList<String> line2=new ArrayList<>();
String line="";
while((line=reader1.readLine())!=null){
line1.add(line);
} reader1.close();
while((line=reader2.readLine())!=null){
line2.add(line);
}
reader2.close();
int n=line2.size();
if(line1.size()>line2.size()){
n=line1.size();
}
int count1=0;
int count2=0;
for(int i=0;i<n;i++){
if((count1==(line1.size()-1))&&(count2>=line2.size()))
{ lines.add(new LineItem(Type.REMOVED, line1.get(count1)));
break;
}
if((count2==(line2.size()-1))&&(count1>=line1.size()))
{ lines.add(new LineItem(Type.ADDED, line2.get(count2)));
break;
}
if(line1.get(count1).equals(line2.get(count2)))
{lines.add(new LineItem(Type.SAME, line1.get(count1)));
count1++;
count2++;
}
else {
if(line1.get(count1).equals(line2.get(count2+1))){
lines.add(new LineItem(Type.ADDED, line2.get(count2)));
count2++;n++; }
else{
if(line1.get(count1+1).equals(line2.get(count2))) {
lines.add(new LineItem(Type.REMOVED, line1.get(count1)));
count1++;
}
} }
}
}
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;
}
}
}