@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 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)); }
/** * 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){ } }