Advertisement
Guest User

Untitled

a guest
May 27th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. ```package gui;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7.  
  8. /**
  9.  * @author DylanPW
  10.  *
  11.  * Class for parsing CSVs loaded into the application.
  12.  */
  13. public class CSVParse {
  14.  
  15.     String csvPath;
  16.  
  17.     /**
  18.      * Constructor for parsing CSVs of the specified path.
  19.      * @param csvPath
  20.      */
  21.     public CSVParse(String csvPath){
  22.         this.csvPath = csvPath;
  23.     }
  24.  
  25.     /**
  26.      * Class for parsing item lists.
  27.      */
  28.     public void parseItems() {
  29.         BufferedReader br = null;
  30.        
  31.         // new store
  32.         String line = "";
  33.         String csvDelimiter = ",";
  34.         try {
  35.             br = new BufferedReader(new FileReader(csvPath));
  36.             String[] item = line.split(csvDelimiter);
  37.            
  38.             // [item],[cost],[price],[reorder point],[reorder amount],[temperature]
  39.         } catch (FileNotFoundException e) {
  40.             e.printStackTrace();
  41.         } finally {
  42.             if (br != null) {
  43.                 try {
  44.                     br.close();
  45.                 } catch (IOException e) {
  46.                     e.printStackTrace();
  47.                 }
  48.             }
  49.         }
  50.     }
  51.  
  52.     /**
  53.      * Class for parsing sales logs
  54.      */
  55.     public void parseSalesLog() {
  56.         BufferedReader br = null;
  57.         String line = "";
  58.         String csvDelimiter = ",";
  59.         try {
  60.             br = new BufferedReader(new FileReader(csvPath));
  61.             String[] item = line.split(csvDelimiter);
  62.  
  63.             // [item],[quantity]
  64.         } catch (FileNotFoundException e) {
  65.             e.printStackTrace();
  66.         } finally {
  67.             if (br != null) {
  68.                 try {
  69.                     br.close();
  70.                 } catch (IOException e) {
  71.                     e.printStackTrace();
  72.                 }
  73.             }
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * Class for parsing manifests
  79.      */
  80.     public void parseManifest() {
  81.         BufferedReader br = null;
  82.         String line = "";
  83.         String newTruck = ">";
  84.         String csvDelimiter = ",";
  85.         try {
  86.             br = new BufferedReader(new FileReader(csvPath));
  87.             if(line.startsWith(newTruck)) {
  88.                 String[] item = line.split(newTruck);
  89.                 String truckType = item[1];
  90.                 // type of truck
  91.  
  92.             } else {
  93.                 String[] item = line.split(csvDelimiter);
  94.                 // [item],[quantity]
  95.             }
  96.  
  97.  
  98.         } catch (FileNotFoundException e) {
  99.             e.printStackTrace();
  100.         } finally {
  101.             if (br != null) {
  102.                 try {
  103.                     br.close();
  104.                 } catch (IOException e) {
  105.                     e.printStackTrace();
  106.                 }
  107.             }
  108.         }
  109.     }
  110. }
  111. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement