MATSIM
AbstractPopulationWriterHandler.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2011 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 package org.matsim.core.population.io;
21 
22 import org.apache.logging.log4j.LogManager;
23 import org.apache.logging.log4j.Logger;
30 
31 import java.io.BufferedWriter;
32 import java.io.IOException;
33 
38 abstract class AbstractPopulationWriterHandler implements PopulationWriterHandler {
39  // all public non-final methods are empty.
40 
41  private final static Logger log = LogManager.getLogger(AbstractPopulationWriterHandler.class);
42 
43  @Override
44  public final void writePerson(final Person person, final BufferedWriter writer) throws IOException {
45  this.startPerson(person, writer);
46  // travelcards
47  if (PersonUtils.getTravelcards(person) != null) {
48  for (String t : PersonUtils.getTravelcards(person)) {
49  this.startTravelCard(t, writer);
50  this.endTravelCard(writer);
51  }
52  }
53  // plans
54  for (Plan plan : person.getPlans()) {
55  this.startPlan(plan, writer);
56  // act/leg
57  for (Object pe : plan.getPlanElements()) {
58  if (pe instanceof Activity) {
59  Activity act = (Activity) pe;
60  this.startAct(act, writer);
61  this.endAct(writer);
62  }
63  else if (pe instanceof Leg) {
64  Leg leg = (Leg) pe;
65  this.startLeg(leg, writer);
66  // route
67  Route route = leg.getRoute();
68  if (route != null) {
69  this.startRoute(route, writer);
70  this.endRoute(writer);
71  }
72  this.endLeg(writer);
73  }
74  }
75  this.endPlan(writer);
76  }
77  this.endPerson(writer);
78  this.writeSeparator(writer);
79  }
80 
81  public abstract void startPerson(final Person person, final BufferedWriter out) throws IOException;
82 
83  public abstract void endPerson(final BufferedWriter out) throws IOException;
84 
85  public abstract void startTravelCard(final String travelcard, final BufferedWriter out) throws IOException;
86 
87  public abstract void endTravelCard(final BufferedWriter out) throws IOException;
88 
89  public abstract void startPlan(final Plan plan, final BufferedWriter out) throws IOException;
90 
91  public abstract void endPlan(final BufferedWriter out) throws IOException;
92 
93  public abstract void startAct(final Activity act, final BufferedWriter out) throws IOException;
94 
95  public abstract void endAct(final BufferedWriter out) throws IOException;
96 
97  public abstract void startLeg(final Leg leg, final BufferedWriter out) throws IOException;
98 
99  public abstract void endLeg(final BufferedWriter out) throws IOException;
100 
101  public abstract void startRoute(final Route route, final BufferedWriter out) throws IOException;
102 
103  public abstract void endRoute(final BufferedWriter out) throws IOException;
104 
105 }
static TreeSet< String > getTravelcards(Person person)
abstract List<? extends T > getPlans()