MATSIM
CountsWriterHandlerImplV1.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * CountsWriterHandlerImplV1.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 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 
21 package org.matsim.counts;
22 import org.matsim.api.core.v01.Coord;
24 
25 import java.io.BufferedWriter;
26 import java.io.IOException;
27 /*package*/ class CountsWriterHandlerImplV1 implements CountsWriterHandler {
28  private final CoordinateTransformation coordinateTransformation;
29 
30  CountsWriterHandlerImplV1(CoordinateTransformation coordinateTransformation) {
31  this.coordinateTransformation = coordinateTransformation;
32  }
33 
34  @Override
35  public void startCounts(final Counts counts, final BufferedWriter out) throws IOException {
36  out.write("<counts ");
37  out.write("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
38  out.write("xsi:noNamespaceSchemaLocation=\"http://matsim.org/files/dtd/counts_v1.xsd\"\n");
39 
40  if (counts.getName() != null) {
41  out.write(" name=\"" + counts.getName() + "\"");
42  } else {
43  out.write(" name=\"\"");
44  }
45  if (counts.getDescription() != null) {
46  out.write(" desc=\"" + counts.getDescription() + "\"");
47  }
48  out.write(" year=\"" + counts.getYear() + "\" ");
49  out.write(" > \n");
50  }
51 
52  @Override
53  public void endCounts(final BufferedWriter out) throws IOException {
54  out.write("</counts>\n");
55  }
56 
57  @Override
58  public void startCount(final Count count, final BufferedWriter out) throws IOException {
59  out.write("\t<count");
60  out.write(" loc_id=\"" + count.getId() + "\"");
61  out.write(" cs_id=\"" + count.getCsLabel() + "\"");
62  if (count.getCoord() != null) {
63  final Coord coord = coordinateTransformation.transform( count.getCoord() );
64  out.write(" x=\"" + coord.getX() + "\"");
65  out.write(" y=\"" + coord.getY() + "\"");
66  }
67  out.write(">\n");
68  }
69 
70  @Override
71  public void endCount(final BufferedWriter out) throws IOException {
72  out.write("\t</count>\n\n");
73  }
74 
75  @Override
76  public void startVolume(final Volume volume, final BufferedWriter out) throws IOException {
77  out.write("\t\t<volume");
78  out.write(" h=\"" + volume.getHourOfDayStartingWithOne() + "\"");
79  out.write(" val=\"" + volume.getValue() + "\"");
80  out.write(" />\n");
81  }
82 
83  @Override
84  public void endVolume(final BufferedWriter out) throws IOException {
85  }
86 
87  @Override
88  public void writeSeparator(final BufferedWriter out) throws IOException {
89  out.write("<!-- ====================================================================== -->\n\n");
90  }
91 }