montimaj

Test

Mar 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5.  
  6. public class Test {
  7.     public static void main(String[] args) throws IOException {
  8.         BufferedReader br = new BufferedReader(new FileReader(args[0]));
  9.         String entry;
  10.         ArrayList<Samples> samplesArrayList = new ArrayList<>();
  11.         while((entry = br.readLine()) != null) {
  12.             Samples samples = new Samples(entry);
  13.             samplesArrayList.add(samples);
  14.         }
  15.  
  16.         for(int index = 1; index < samplesArrayList.size(); ++index) {
  17.             if(merge(index, samplesArrayList)) --index;
  18.         }
  19.  
  20.         for(Samples samples: samplesArrayList) {
  21.             System.out.println(samples.toString());
  22.         }
  23.     }
  24.  
  25.     private static boolean merge(int index, ArrayList<Samples> list) {
  26.         Samples prev = list.get(index - 1);
  27.         Samples curr = list.get(index);
  28.         if(curr.getStartTime() == curr.getEndTime() || prev.getStatus().equals(curr.getStatus())) {
  29.             if(prev.getStatus().equals("PENDING") || curr.getStatus().equals("PENDING")) {
  30.                 prev.setStatus("PENDING");
  31.             } else prev.setStatus("DONE");
  32.             prev.setEndTime(curr.getEndTime());
  33.             prev.setLastWordIndex(curr.getLastWordIndex());
  34.             list.remove(index);
  35.             return true;
  36.         }
  37.         return false;
  38.     }
  39. }
Add Comment
Please, Sign In to add comment