MATSIM
HouseholdsStreamingReaderV10.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * HouseholdsStreamingReaderV10
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2012 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 package org.matsim.households;
21 
22 import java.util.Stack;
23 
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
27 
28 
29 
34 public class HouseholdsStreamingReaderV10 extends AbstractHouseholdsReaderV10 {
35 
36 
37  private static final Logger log = LogManager.getLogger(HouseholdsStreamingReaderV10.class);
38 
41 
42  private final Counter counter = new Counter (" household # ");
43 
45  super(new HouseholdsImpl());
46  this.algoRunner = algoRunner;
47  }
48 
49  @Override
50  public void endTag(String name, String content, Stack<String> context) {
51  if (HouseholdsSchemaV10Names.HOUSEHOLD.equalsIgnoreCase(name)) {
52  Household household = createHousehold();
53  this.algoRunner.runAlgorithms(household);
54  this.hhWriter.writeHousehold(household);
55  counter.incCounter();
56  }
57  }
58 
59  public void readFileRunAlgorithmsAndWriteFile(String inputFile, String outputFile){
60  if (inputFile.equalsIgnoreCase(outputFile)){
61  throw new IllegalArgumentException("Inputfile and outputfile must not refer to the same filename!");
62  }
63  hhWriter = new HouseholdsWriterV10(super.getHouseholds());
64  hhWriter.openFileAndWritePreamble(outputFile);
65  super.readFile(inputFile);
66  counter.printCounter();
67  hhWriter.writeEndAndCloseFile();
68  log.info("Done reading households, running algorithms, and writing file");
69  }
70 
71 }
void readFileRunAlgorithmsAndWriteFile(String inputFile, String outputFile)
void endTag(String name, String content, Stack< String > context)
HouseholdsStreamingReaderV10(HouseholdsAlgorithmRunner algoRunner)