| 15 | public class ParseTrash { |
| 16 | public static String source = "Trash.dat"; |
| 17 | public static <T extends Trash> void |
| 18 | fillBin(String packageName, Fillable<T> bin) { |
| 19 | DynaFactory factory = |
| 20 | new DynaFactory(packageName); |
| 21 | try { |
| 22 | Files.lines(Paths.get("trash", source)) |
| 23 | // Remove comments and empty lines: |
| 24 | .filter(line -> line.trim().length() != 0) |
| 25 | .filter(line -> !line.startsWith("//")) |
| 26 | .forEach(line -> { |
| 27 | String type = line.substring( |
| 28 | 0, line.indexOf(':')).trim(); |
| 29 | double weight = Double.valueOf( |
| 30 | line.substring(line.indexOf(':') + 1) |
| 31 | .trim()); |
| 32 | bin.addTrash(factory.create( |
| 33 | new TrashInfo(type, weight))); |
| 34 | }); |
| 35 | } catch(IOException | NumberFormatException e) { |
| 36 | throw new RuntimeException(e); |
| 37 | } |
| 38 | } |
| 39 | // Special case to handle a List: |
| 40 | public static <T extends Trash> void |
| 41 | fillBin(String packageName, List<T> bin) { |