21 package org.matsim.counts;
28 import java.io.IOException;
29 import java.io.OutputStream;
30 import java.io.Serializable;
31 import java.util.Collections;
32 import java.util.Comparator;
33 import java.util.List;
34 import java.util.Vector;
37 final class CountsWriterV1
extends MatsimXmlWriter implements MatsimWriter {
39 private final CountsWriterHandler handler;
40 private final Counts counts;
42 public CountsWriterV1(
final Counts counts) {
43 this(
new IdentityTransformation() , counts );
46 public CountsWriterV1(
47 final CoordinateTransformation coordinateTransformation,
48 final Counts counts) {
52 this.handler =
new CountsWriterHandlerImplV1(coordinateTransformation);
56 public final void write(
final String filename) {
62 catch (IOException e) {
67 public final void write(
final OutputStream stream) {
73 catch (IOException e) {
78 private void doTheWriting() throws IOException {
82 this.handler.startCounts(this.counts, this.writer);
83 this.handler.writeSeparator(this.writer);
85 List<Count> countsTemp =
new Vector<Count>();
86 countsTemp.addAll(this.counts.getCounts().values());
87 Collections.sort(countsTemp,
new CountComparator());
89 for (Count c : countsTemp) {
90 List<Volume> volumesTemp =
new Vector<Volume>();
91 volumesTemp.addAll(c.getVolumes().values());
92 Collections.sort(volumesTemp,
new VolumeComparator());
93 this.handler.startCount(c, this.writer);
94 for (Volume v : volumesTemp) {
95 this.handler.startVolume(v, this.writer);
96 this.handler.endVolume(this.writer);
98 this.handler.endCount(this.writer);
99 this.handler.writeSeparator(this.writer);
102 this.handler.endCounts(this.writer);
106 public final String toString() {
107 return super.toString();
110 static class VolumeComparator
implements Comparator<Volume>, Serializable {
111 private static final long serialVersionUID = 1L;
114 public int compare(
final Volume v1,
final Volume v2) {
115 return Double.compare(v1.getHourOfDayStartingWithOne(), v2.getHourOfDayStartingWithOne());
119 static class CountComparator
implements Comparator<Count>, Serializable {
120 private static final long serialVersionUID = 1L;
123 public int compare(
final Count c1,
final Count c2) {
135 return c1.getCsLabel().compareTo(c2.getCsLabel());
final void writeXmlHead()
final void openOutputStream(OutputStream outputStream)
final void openFile(final String filename)