@Override public Set<Id<Vehicle>> identifyVehiclesUsableForAgent(final Id<Person> person) { // we can't simply remember an agent->hh mapping at construction, // as the households container is mutable. It would not make any sense // to modify it, but one is never too prudent. final Id<Household> hhId = agent2hh.get( person ); if ( hhId == null ) throw new RuntimeException( "no household known for "+person ); final Household hh = households.getHouseholds().get( hhId ); if ( hh == null ) throw new RuntimeException( "household "+hhId+" vanished!" ); if ( !hh.getMemberIds().contains( person ) ) throw new RuntimeException( "household "+hhId+" does not contain "+person ); return new HashSet<Id<Vehicle>>( hh.getVehicleIds() ); } }
/*package*/ void writeHousehold(Household h) throws UncheckedIOException { this.atts.clear(); atts.add(createTuple(HouseholdsSchemaV10Names.ID, h.getId().toString())); this.writeStartTag(HouseholdsSchemaV10Names.HOUSEHOLD, atts); if ((h.getMemberIds() != null) && !h.getMemberIds().isEmpty()){ this.writeMembers(h.getMemberIds()); } if ((h.getVehicleIds() != null) && !h.getVehicleIds().isEmpty()) { this.writeStartTag(HouseholdsSchemaV10Names.VEHICLES, null); for (Id<Vehicle> id : h.getVehicleIds()){ atts.clear(); atts.add(createTuple(HouseholdsSchemaV10Names.REFID, id.toString())); this.writeStartTag(HouseholdsSchemaV10Names.VEHICLEDEFINITIONID, atts, true); } this.writeEndTag(HouseholdsSchemaV10Names.VEHICLES); } if (h.getIncome() != null){ this.writeIncome(h.getIncome()); } AttributesXmlWriterDelegate attributesWriter = new AttributesXmlWriterDelegate(); attributesWriter.putAttributeConverters(this.attributeConverters); try { this.writer.write(NL); } catch (IOException e) { e.printStackTrace(); } attributesWriter.writeAttributes( "\t\t" , this.writer , h.getAttributes() ); this.writeEndTag(HouseholdsSchemaV10Names.HOUSEHOLD); }
assertEquals(pid43, hhmemberIds.get(2)); assertNotNull(hh.getVehicleIds()); List<Id<Vehicle>> vehIds = new ArrayList<>(); vehIds.addAll(hh.getVehicleIds()); Collections.sort(vehIds); assertEquals(2, vehIds.size()); assertEquals(pid45, hh.getMemberIds().get(1)); assertNotNull(hh.getVehicleIds()); assertEquals(1, hh.getVehicleIds().size()); assertEquals(vid23, hh.getVehicleIds().get(0)); assertEquals(0, hh.getMemberIds().size()); assertNotNull(hh.getVehicleIds()); assertEquals(0, hh.getVehicleIds().size());