MATSIM
MatricesReaderMatsimV1.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * MatricesReaderMatsimV1.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.util.Stack;
24 
26 import org.xml.sax.Attributes;
27 
34 public class MatricesReaderMatsimV1<T> extends MatsimXmlParser {
35 
36  private final static String MATRICES = "matrices";
37  private final static String MATRIX = "matrix";
38  private final static String ENTRY = "entry";
39 
40  private Matrices matrices;
41  private Matrix currMatrix = null;
42 
43  public MatricesReaderMatsimV1(final Matrices matrices) {
44  super(ValidationType.DTD_ONLY);
45  this.matrices = matrices;
46  }
47 
48  @Override
49  public void startTag(final String name, final Attributes atts, final Stack<String> context) {
50  if (MATRICES.equals(name)) {
51  startMatrices(atts);
52  } else if (MATRIX.equals(name)) {
53  startMatrix(atts);
54  } else if (ENTRY.equals(name)) {
55  startEntry(atts);
56  } else {
57  throw new RuntimeException(this + "[tag=" + name + " not known or not supported]");
58  }
59  }
60 
61  @Override
62  public void endTag(final String name, final String content, final Stack<String> context) {
63  if (MATRICES.equals(name)) {
64  this.matrices = null;
65  } else if (MATRIX.equals(name)) {
66  this.currMatrix = null;
67  }
68  }
69 
70  private void startMatrices(final Attributes atts) {
71  this.matrices.setName(atts.getValue("name"));
72  }
73 
74  private void startMatrix(final Attributes atts) {
75  this.currMatrix = this.matrices.createMatrix(atts.getValue("id"),
76  atts.getValue("desc"));
77  }
78 
79  private void startEntry(final Attributes atts) {
80  this.currMatrix.createAndAddEntry(atts.getValue("from_id"), atts.getValue("to_id"), Double.parseDouble(atts.getValue("value")));
81  }
82 
83 }
final Entry createAndAddEntry(final String fromLocId, final String toLocId, final double value)
Definition: Matrix.java:65
final void setName(final String name)
Definition: Matrices.java:53
void startTag(final String name, final Attributes atts, final Stack< String > context)
void endTag(final String name, final String content, final Stack< String > context)
final Matrix createMatrix(final String id, final String desc)
Definition: Matrices.java:38