|
| 1 | +package pipelinescript.java; |
| 2 | + |
| 3 | +import java.io.BufferedReader; |
| 4 | +import java.io.FileNotFoundException; |
| 5 | +import java.io.FileReader; |
| 6 | +import java.io.IOException; |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Map; |
| 11 | + |
| 12 | +public class FileManager { |
| 13 | + Map<String, String> fileMap; |
| 14 | + public FileManager(){ |
| 15 | + this.fileMap = new HashMap<>(); |
| 16 | + } |
| 17 | + public void create(String variable, String filepath){ |
| 18 | + fileMap.put(variable,filepath); |
| 19 | + } |
| 20 | + public void delete(String variable){ |
| 21 | + fileMap.remove(variable); |
| 22 | + } |
| 23 | + public void move(String variable, String filepath){ |
| 24 | + fileMap.put(variable, filepath); |
| 25 | + } |
| 26 | + public void set(String variable, Object value){ |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + public Object get(String variable){ |
| 31 | + |
| 32 | + return new Object(); |
| 33 | + } |
| 34 | + // make sure it points proper CSV file |
| 35 | + public Graph getGraphFromCSV(String variable){ |
| 36 | + String path = fileMap.get(variable); |
| 37 | + BufferedReader br = null; |
| 38 | + String line = ""; |
| 39 | + String cvsSplitBy = "\t"; |
| 40 | + List<String[]> rtn = null; |
| 41 | + try { |
| 42 | + br = new BufferedReader(new FileReader(path)); |
| 43 | + } catch (FileNotFoundException e) { |
| 44 | + // TODO Auto-generated catch block |
| 45 | + e.printStackTrace(); |
| 46 | + } |
| 47 | + try { |
| 48 | + rtn = new ArrayList<>(); |
| 49 | + while ((line = br.readLine()) != null) { |
| 50 | + String[] l = line.split(cvsSplitBy); |
| 51 | + rtn.add(l); |
| 52 | + } |
| 53 | + } catch (IOException e) { |
| 54 | + // TODO Auto-generated catch block |
| 55 | + e.printStackTrace(); |
| 56 | + } |
| 57 | + |
| 58 | + return new Graph(rtn); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments