Won't pass final validation point.
Be sure that the lines list has the ADDED label with the required lines in the correct places.
I have been reading about what others have done.
I have tried with this inputs:
Here is an example, lets say file one contained:
line one is going to be the same
line two is going to be removed
line three is going to be the same
line four is going to be removed
line five is going to be the same
line seven is going to be the same
line nine is going to be the same
and file two contained:
line one is going to be the same
line three is going to be the same
line five is going to be the same
line six is going to be added
line seven is going to be the same
line eight is going to be added
line nine is going to be the same
The result needs to match:
[LineItem{SAME - line one is going to be the same}
LineItem{REMOVED - line two is going to be removed}
LineItem{SAME - line three is going to be the same}
LineItem{REMOVED - line four is going to be removed}
LineItem{SAME - line five is going to be the same}
LineItem{ADDED - line six is going to be added}
LineItem{SAME - line seven is going to be the same}
LineItem{ADDED - line eight is going to be added}
LineItem{SAME - line nine is going to be the same}]
The result is the same, but I can't pass the validation.
package com.codegym.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;
/*
Tracking changes
*/
public class Solution {
public static List<LineItem> lines = new ArrayList<>();
public static void main(String[] args) throws IOException {
ArrayList<String>line1=new ArrayList<>();
ArrayList<String>line2=new ArrayList<>();
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
String fileName1= reader.readLine();
String fileName2= reader.readLine();
reader.close();
BufferedReader reader1=new BufferedReader(new FileReader(fileName1));
String data;
while((data=reader1.readLine())!=null){
line1.add(data);
}
reader1.close();
BufferedReader reader2=new BufferedReader(new FileReader(fileName2));
while((data=reader2.readLine())!=null){
line2.add(data);
}
reader2.close();
int i=0;
int j=0;
for(;i<line1.size();){
if(line1.get(i).equals(line2.get(j))){
LineItem item=new LineItem(Type.SAME,line1.get(i));
lines.add(item);
i++;
j++;
}
else if(!(line1.get(i).equals(line2.get(j)))&&(line1.get(i).equals(line2.get(j+1)))){
LineItem item=new LineItem(Type.ADDED,line2.get(j));
lines.add(item);
j++;
}
else{
LineItem item=new LineItem(Type.REMOVED,line1.get(i));
lines.add(item);
i++;
}
}
}
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;
}
}
}