It's outputting the correct code in my tests, but after seeing how many people are struggling with this, I know there must be more to it and I am missing something
package com.codegym.task.task19.task1916;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.InflaterInputStream;
/*
Tracking changes
*/
public class Solution {
public static List<LineItem> lines = new ArrayList<>();
//use insert in list to put in empty strings when a line is removed.
//use a method to check which lines match. parameters will be a list?
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
reader.close();
ArrayList<String> list1 = new ArrayList<>();
ArrayList<String> list2 = new ArrayList<>();
//Needs to make the lists the same size by replacing empty array elements with empty
//string or null if that works
try (BufferedReader fileReader = new BufferedReader(new FileReader(file1))) {
while (fileReader.ready()) {
list1.add(fileReader.readLine());
}
}
try (BufferedReader fileReader2 = new BufferedReader(new FileReader(file2))){
while (fileReader2.ready()) {
list2.add(fileReader2.readLine());
}
}
while (list1.size() != list2.size())
if (list1.size() > list2.size()) {
list2.add("");
}else list1.add("");
int lineNumber = 1;
for (int i = 0; i < list1.size(); i++) {
if (lineNumber > 5) lineNumber = 0;
if (list1.get(i).equals(list2.get(i))) {
lines.add(new LineItem(Type.SAME,"line" + lineNumber));
} else if (list2.get(i).equals("")) {
lines.add(new LineItem(Type.REMOVED,"line" + lineNumber));
} else if (list1.get(i).equals("")) {
lines.add(new LineItem(Type.ADDED,"line" + lineNumber));
} else if (list1.contains(list2.get(i))) {
lines.add(new LineItem(Type.REMOVED,"line" + lineNumber));
} else if (list2.contains(list1.get(i))) {
lines.add(new LineItem(Type.ADDED,"line" + lineNumber));
}
lineNumber++;
}
// for (LineItem x : lines) {
// System.out.println(x.toString());
// }
// for (int i = 0; i < lines.size(); i++) {
// if (i == 0) {
// boolean added = lines.get(i).getType().equals(Type.ADDED);
// }
// if (lines.get(i).getType().equals(Type.ADDED) && lines.get(i).getType().equals(Type.)) {
//
// }
// }
}
public static enum Type {
ADDED, // New line added
REMOVED, // Line deleted
SAME // No change
}
public static class LineItem {
public Type type;
public String line;
public LineItem(Type type, String line) {
this.type = type;
this.line = line;
}
// public Type getType() {
// return type;
// }
//
// public String toString() {
// return String.format("LineItem{%s - %s}", type, line);
// }
}
}