public HouseholdsStreamingReaderV10(HouseholdsAlgorithmRunner algoRunner){ super(new HouseholdsImpl()); this.algoRunner = algoRunner; }
/** * Adds the household to the container. If streaming is set, the household * is added, the algorithms are run on the household, and it is subsequently * removed. If not, the household is added incrementally to the container. * @param household * @throws IllegalArgumentException if the container already includes the * {@link Id} of the household being added. */ public final void addHousehold(final Household household){ /* Validate that a household with the same Id does not exist yet. */ if(this.getHouseholds().containsKey(household.getId())){ throw new IllegalArgumentException("Household with Id " + household.getId() + " already exisits."); } this.households.put(household.getId(), household); }
/** * Test that households are accumulated if streaming is off. */ public void testAddHousehold_NoStreaming(){ HouseholdsImpl hhs = new HouseholdsImpl(); Household hh1 = new HouseholdImpl(Id.create("1", Household.class)); Household hh2 = new HouseholdImpl(Id.create("2", Household.class)); hhs.addHousehold(hh1); assertEquals("Should have the first household added.", 1, hhs.getHouseholds().size()); assertTrue("First household not present.", hhs.getHouseholds().containsValue(hh1)); hhs.addHousehold(hh2); assertEquals("Should have the first AND second household added.", 2, hhs.getHouseholds().size()); assertTrue("First household not present.", hhs.getHouseholds().containsValue(hh1)); assertTrue("Second household not present.", hhs.getHouseholds().containsValue(hh2)); }
@Override public void endTag(String name, String content, Stack<String> context) { if (HouseholdsSchemaV10Names.HOUSEHOLD.equalsIgnoreCase(name)) { fillHousehold(); ((HouseholdsImpl)this.households).addHousehold(currentHousehold); this.currentHousehold = null; counter.incCounter(); } else if (HouseholdsSchemaV10Names.INCOME.equalsIgnoreCase(name)) { this.currentincome = this.builder.createIncome(Double.parseDouble(content.trim()), this.currentIncomePeriod); this.currentincome.setCurrency(this.currentincomeCurrency); } else if (HouseholdsSchemaV10Names.HOUSEHOLDS.equalsIgnoreCase(name)) { counter.printCounter(); } else if (name.equalsIgnoreCase(HouseholdsSchemaV10Names.ATTRIBUTES)) { this.currAttributes = null; } else if (name.equalsIgnoreCase(HouseholdsSchemaV10Names.ATTRIBUTE)) { this.attributesReader.endTag( name , content , context ); } }
/** * Test that households with the same {@link Id} are not accepted. */ public void testAddHousehold_DuplicateId(){ HouseholdsImpl hhs = new HouseholdsImpl(); Household hh1 = new HouseholdImpl(Id.create("1", Household.class)); Household hh2 = new HouseholdImpl(Id.create("1", Household.class)); assertEquals("Shouldn't have a household.", 0, hhs.getHouseholds().size()); hhs.addHousehold(hh1); assertEquals("Didn't add the household.", 1, hhs.getHouseholds().size()); assertEquals("Should have added the household.", hh1, hhs.getHouseholds().get(hh1.getId())); try{ hhs.addHousehold(hh2); fail("Should not have accepted household with similar Id."); } catch (IllegalArgumentException e){ } }
MutableScenario(Config config) { this.config = config; this.network = NetworkUtils.createNetwork(this.config); this.population = PopulationUtils.createPopulation(this.config, this.network); this.facilities = new ActivityFacilitiesImpl(); this.households = new HouseholdsImpl(); this.lanes = LanesUtils.createLanesContainer(); this.vehicles = VehicleUtils.createVehiclesContainer(); this.transitVehicles = VehicleUtils.createVehiclesContainer(); this.transitSchedule = new TransitScheduleFactoryImpl().createTransitSchedule(); this.config.network().setLocked(); }
public void testBasicReaderWriter() throws IOException { Households households = new HouseholdsImpl(); HouseholdsReaderV10 reader = new HouseholdsReaderV10(households); reader.readFile(this.getPackageInputDirectory() + TESTHOUSEHOLDSINPUT); checkContent(households); HouseholdsWriterV10 writer = new HouseholdsWriterV10(households); String outfilename = this.getOutputDirectory() + TESTXMLOUTPUT; writer.writeFile(outfilename); File outFile = new File(outfilename); assertTrue(outFile.exists()); //read it again to check if the same is read as at the very first beginning of test households = new HouseholdsImpl(); reader = new HouseholdsReaderV10(households); reader.readFile(outfilename); checkContent(households); }