Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- public class Test {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new FileReader(args[0]));
- String entry;
- ArrayList<Samples> samplesArrayList = new ArrayList<>();
- while((entry = br.readLine()) != null) {
- Samples samples = new Samples(entry);
- samplesArrayList.add(samples);
- }
- for(int index = 1; index < samplesArrayList.size(); ++index) {
- if(merge(index, samplesArrayList)) --index;
- }
- for(Samples samples: samplesArrayList) {
- System.out.println(samples.toString());
- }
- }
- private static boolean merge(int index, ArrayList<Samples> list) {
- Samples prev = list.get(index - 1);
- Samples curr = list.get(index);
- if(curr.getStartTime() == curr.getEndTime() || prev.getStatus().equals(curr.getStatus())) {
- if(prev.getStatus().equals("PENDING") || curr.getStatus().equals("PENDING")) {
- prev.setStatus("PENDING");
- } else prev.setStatus("DONE");
- prev.setEndTime(curr.getEndTime());
- prev.setLastWordIndex(curr.getLastWordIndex());
- list.remove(index);
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment