import java.util.Scanner; import java.util.HashMap; import java.util.ArrayList; import java.io.File; class Filleser implements Runnable{ private File fil; private Monitor monitor; public Filleser(File fil, Monitor monitor){ this.fil = fil; this.monitor = monitor; } public void run(){ HashMap allePersoner = new HashMap<>(); Scanner scanner = null; Person start = null; try{ scanner = new Scanner(fil); }catch(Exception e){ System.out.println("Fant ikke fil:" + fil); e.printStackTrace(); System.exit(1); } scanner.nextLine(); while(scanner.hasNextLine()){ String linje = scanner.nextLine(); String[] info = linje.split(","); String navn = info[0]; String id = info[1]; String idBarn = info[2]; Boolean erSyk; if (info[3].equals("ja")){ erSyk = true; } else { erSyk = false; } Person person = new Person(navn, id, idBarn, erSyk); allePersoner.put(id, person); if (idBarn.equals("")){ start = person; } } for(Person person : allePersoner.values()){ Person barn = allePersoner.get(person.hentIdBarn()); if (barn != null){ barn.leggTilForelder(person); } } monitor.leggTilSlekt(start); } }