55package patterns .trash ;
66import java .util .*;
77import java .io .*;
8+ import java .nio .file .*;
89
910public class ParseTrash {
1011 public static <T extends Trash > void
11- fillBin (String filename , Fillable <T > bin ) {
12+ fillBin (String dir , String fname , Fillable <T > bin ) {
1213 try {
13- try (BufferedReader data = new BufferedReader (
14- new FileReader (filename ))) {
14+ Path p = FileSystems .getDefault ()
15+ .getPath (".." , dir , fname );
16+ try (BufferedReader data = Files .newBufferedReader (p )){
1517 String buf ;
1618 while ((buf = data .readLine ())!= null ) {
1719 if (buf .trim ().length () == 0 )
1820 continue ; // Skip empty lines
21+ if (buf .startsWith ("//" ))
22+ continue ; // Skip comments
1923 String type = buf .substring (0 ,
20- buf .indexOf (':' )).trim ();
24+ buf .indexOf (':' )).trim ();
2125 double weight = Double .valueOf (
22- buf .substring (buf .indexOf (':' ) + 1 )
23- .trim ());
26+ buf .substring (buf .indexOf (':' ) + 1 ).trim ());
2427 bin .addTrash (Trash .factory (
2528 new Trash .Info (type , weight )));
2629 }
@@ -34,7 +37,7 @@ public class ParseTrash {
3437 }
3538 // Special case to handle ArrayList:
3639 public static <T extends Trash > void
37- fillBin (String filename , ArrayList <T > bin ) {
38- fillBin (filename , new FillableList <>(bin ));
40+ fillBin (String dir , String fname , ArrayList <T > bin ) {
41+ fillBin (dir , fname , new FillableList <>(bin ));
3942 }
4043}
0 commit comments