private void writeIncome(Income income) throws UncheckedIOException { atts.clear(); if (income.getCurrency() != null) { atts.add(createTuple(HouseholdsSchemaV10Names.CURRENCY,income.getCurrency())); } atts.add(createTuple(HouseholdsSchemaV10Names.PERIOD, income.getIncomePeriod().toString())); this.writeStartTag(HouseholdsSchemaV10Names.INCOME, atts); this.writeContent(Double.toString(income.getIncome()), true); this.writeEndTag(HouseholdsSchemaV10Names.INCOME); }
@Override public int compare(Household o1, Household o2) { if (o1.getIncome().getIncomePeriod() != o2.getIncome().getIncomePeriod()){ throw new IllegalArgumentException("Can only compare Households with incomes in " + " same income period"); } if (o1.getIncome().getIncome() < o2.getIncome().getIncome()){ return -1; } else if (o1.getIncome().getIncome() > o2.getIncome().getIncome()){ return 1; } return 0; }
@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 ); } }
assertNotNull(hh.getIncome().getIncomePeriod()); assertEquals(IncomePeriod.month, hh.getIncome().getIncomePeriod()); assertEquals("eur", hh.getIncome().getCurrency()); assertEquals(50000.0d, hh.getIncome().getIncome(), EPSILON); assertNotNull(hh.getIncome().getIncomePeriod()); assertEquals(IncomePeriod.day, hh.getIncome().getIncomePeriod()); assertEquals("eur", hh.getIncome().getCurrency()); assertEquals(1000.0d, hh.getIncome().getIncome(), EPSILON);