MATSIM
MatricesWriterHandlerImplV1.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * MatricesWriterHandlerImplV1.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.matrices;
22 
23 import java.io.BufferedWriter;
24 import java.io.IOException;
25 
26 /*package*/ class MatricesWriterHandlerImplV1 implements MatricesWriterHandler {
27 
29  // member variables
31 
33  //
34  // interface implementation
35  //
37 
39  // <matrices ... > ... </matrices>
41 
42  @Override
43  public void startMatrices(final Matrices matrices, final BufferedWriter out) throws IOException {
44  out.write("<matrices");
45  if (matrices.getName() != null) {
46  out.write(" name=\"" + matrices.getName() + "\"");
47  }
48  out.write(">\n\n");
49  }
50 
51  @Override
52  public void endMatrices(final BufferedWriter out) throws IOException {
53  out.write("</matrices>\n");
54  }
55 
57  // <matrix ... > ... </matrix>
59 
60  @Override
61  public void startMatrix(final Matrix matrix, final BufferedWriter out) throws IOException {
62  out.write("\t<matrix");
63  out.write(" id=\"" + matrix.getId() + "\"");
64 
65  if (matrix.getDesc() != null) {
66  out.write(" desc=\"" + matrix.getDesc() + "\"");
67  }
68  out.write(">\n");
69  }
70 
71  @Override
72  public void endMatrix(final BufferedWriter out) throws IOException {
73  out.write("\t</matrix>\n\n");
74  }
75 
77  // <entry ... />
79 
80  @Override
81  public void startEntry(final Entry entry, final BufferedWriter out) throws IOException {
82  out.write("\t\t<entry");
83  out.write(" from_id=\"" + entry.getFromLocation() + "\"");
84  out.write(" to_id=\"" + entry.getToLocation() + "\"");
85  out.write(" value=\"" + entry.getValue() + "\"");
86  out.write(" />\n");
87  }
88 
89  @Override
90  public void endEntry(final BufferedWriter out) throws IOException {
91  }
92 
94  // <!-- ============ ... ========== -->
96 
97  @Override
98  public void writeSeparator(final BufferedWriter out) throws IOException {
99  out.write("<!-- =================================================" +
100  "===================== -->\n\n");
101  }
102 }