Все извилины свернул, не могу понять на что валидатор ругается?
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 IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String fileName1 = bufferedReader.readLine();
String fileName2 = bufferedReader.readLine();
bufferedReader.close();
// src/com/javarush/task/task19/task1916/File1
// src/com/javarush/task/task19/task1916/File2
ArrayList<String> list1 = fromFileToList(fileName1);
ArrayList<String> list2 = fromFileToList(fileName2);
try {
while (list1.size() > 0){
if (list1.get(0).equals(list2.get(0))){
lines.add(new LineItem(Type.SAME, list1.get(0)));
list1.remove(0);
list2.remove(0);
}
else if (list1.get(1).equals(list2.get(0))){
lines.add(new LineItem(Type.REMOVED, list1.get(0)));
list1.remove(0);
}
else if (list1.get(0).equals(list2.get(1))){
lines.add(new LineItem(Type.ADDED, list2.get(0)));
list2.remove(0);
}
}
} catch (Exception e) {
//e.printStackTrace();
if (list1.size() > 0 && list2.size() == 0) {
lines.add(new LineItem(Type.REMOVED, list1.get(0)));
//list1.remove(0);
}
if (list2.size() > 0 && list1.size() == 0) {
lines.add(new LineItem(Type.ADDED, list2.get(0)));
//list2.remove(0);
}
}
//System.out.println(lines.toString());
}
//этот метод считает из файла строки и добавит их в лист
public static ArrayList<String> fromFileToList(String fileName) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
ArrayList<String> list = new ArrayList<>();
while (reader.ready()){
list.add(reader.readLine());
}
reader.close();
return list;
}
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;
}
@Override
public String toString() {
return this.type + " " + this.line;
}
}
}