Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1.  
  2.         File file = new File("pback.txt");
  3.         Scanner in = null;
  4.         Scanner scanner = null;
  5.         try {
  6.             in = new Scanner(file);
  7.  
  8.         } catch (FileNotFoundException e) {
  9.             System.out.println ("File not found!");
  10.         }
  11.         System.out.println(in);
  12.         List<String> ids = new ArrayList<String>();
  13.         List<String> usr = new ArrayList<String>();
  14.         List<String> desc = new ArrayList<String>();
  15.         List<String> dep = new ArrayList<String>();
  16.         List<String> pri = new ArrayList<String>();
  17.         List<String> est = new ArrayList<String>();
  18.         List<String> acrit = new ArrayList<String>();
  19.         String currentId = "<id>";
  20.         String acritStr = "";
  21.         while(in.hasNextLine()) {
  22.             String currentLine = in.nextLine();
  23.             if(currentLine.startsWith("<")) {
  24.                 currentId = currentLine;
  25.                 continue;
  26.             }
  27.             switch(currentId) {
  28.             case "<id>":
  29.                 ids.add(currentLine);
  30.                 break;
  31.  
  32.             case "<usr>":
  33.                 usr.add(currentLine);
  34.                 break;
  35.  
  36.             case "<desc>":
  37.                 desc.add(currentLine);
  38.                 break;
  39.  
  40.             case "<dep>":
  41.                 dep.add(currentLine);
  42.                 break;
  43.  
  44.             case "<pri>":
  45.                 pri.add(currentLine);
  46.                 break;
  47.  
  48.             case "<est>":
  49.                 est.add(currentLine);
  50.                 break;
  51.  
  52.             case "<acrit>":
  53.                 if(currentLine.isEmpty()) {
  54.                     acrit.add(acritStr);
  55.                     acritStr = "";
  56.                 } else {
  57.                     acritStr += "\n" + currentLine;
  58.                 }
  59.                 break;
  60.  
  61.             }
  62.  
  63.         }
  64.         System.out.println(ids.size());
  65.         System.out.println(usr.size());
  66.         System.out.println(dep.size());
  67.         System.out.println(pri.size());
  68.         System.out.println(acrit.size());
  69.         System.out.println(est.size());
  70.         System.out.println(
  71.                 ids.size() == usr.size() &&
  72.                 ids.size() == dep.size() &&
  73.                 ids.size() == pri.size() &&
  74.                 ids.size() == acrit.size() &&
  75.                 ids.size() == est.size()
  76.                 );
  77.  
  78.  
  79.         StringBuilder sb = new StringBuilder();
  80.         for(int i = 0 ; i < ids.size() ; i++ ) {
  81.             String id = ids.get(i);
  82.             String us = usr.get(i);
  83.             String ds = desc.get(i);
  84.             String dp = dep.get(i);
  85.             String pr = pri.get(i);
  86.             String es = est.get(i);
  87.             String acr = acrit.get(i);
  88.             sb.append("ID: ");
  89.             sb.append(id);
  90.             sb.append("\nUser Story: ");
  91.             sb.append(us);
  92.             sb.append("\nPriority: ");
  93.             sb.append(pr);
  94.             sb.append("\nEst. cost: ");
  95.             sb.append(es);
  96.             sb.append("\nDescription: ");
  97.             sb.append(ds);
  98.             sb.append("\nAcceptance critera: ");
  99.             sb.append(acr);
  100.             sb.append("\nDependency: ");
  101.             sb.append(dp);
  102.             sb.append("\n\n");
  103.         }
  104.  
  105.         try {
  106.             FileWriter fstream = new FileWriter("out.txt");
  107.             BufferedWriter out = new BufferedWriter(fstream);
  108.             out.write(sb.toString());
  109.             //Close the output stream
  110.             out.close();
  111.         } catch (Exception e){//Catch exception if any
  112.             System.err.println("Error: " + e.getMessage());
  113.  
  114.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement