MATSIM
CountsReaderMatsimV1.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * CountsReaderMatsimV1.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 
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.matsim.api.core.v01.Coord;
26 import org.matsim.api.core.v01.Id;
31 import org.xml.sax.Attributes;
32 
33 import java.util.Stack;
34 
40 public class CountsReaderMatsimV1 extends MatsimXmlParser {
41 
42  private final static String COUNTS = "counts";
43  private final static String COUNT = "count";
44  private final static String VOLUME = "volume";
45 
47 
48  private final Counts counts;
49  private Count currcount = null;
50 
51  private static final Logger log = LogManager.getLogger(CountsReaderMatsimV1.class);
52 
53  public CountsReaderMatsimV1(final Counts counts) {
54  this( new IdentityTransformation(), counts );
55  }
56 
58  final CoordinateTransformation coordinateTransformation,
59  final Counts counts) {
60  super(ValidationType.XSD_ONLY);
61  this.coordinateTransformation = coordinateTransformation;
62  this.counts = counts;
63  }
64 
65  @Override
66  public void startTag(final String name, final Attributes atts, final Stack<String> context) {
67  if (VOLUME.equals(name)) {
68  startVolume(atts);
69  } else if (COUNT.equals(name)) {
70  startCount(atts);
71  } else if (COUNTS.equals(name)) {
72  startCounts(atts);
73  }
74  }
75 
76  @Override
77  public void endTag(final String name, final String content, final Stack<String> context) {
78 
79  }
80 
81  private void startCounts(final Attributes meta) {
82  this.counts.setName(meta.getValue("name"));
83  this.counts.setDescription(meta.getValue("desc"));
84  this.counts.setYear(Integer.parseInt(meta.getValue("year")));
85  }
86 
87  private void startCount(final Attributes meta) {
88  String locId = meta.getValue("loc_id");
89  this.currcount = this.counts.createAndAddCount(Id.create(locId, Link.class), meta.getValue("cs_id"));
90  String x = meta.getValue("x");
91  String y = meta.getValue("y");
92  if (x != null && y != null) {
93  this.currcount.setCoord(
94  coordinateTransformation.transform(
95  new Coord(
96  Double.parseDouble(x),
97  Double.parseDouble(y))));
98  }
99  }
100 
101  private void startVolume(final Attributes meta) {
102  if (this.currcount != null) {
103  this.currcount.createVolume(Integer.parseInt(meta.getValue("h")), Double.parseDouble(meta.getValue("val")));
104  }
105  }
106 
107 }
final CoordinateTransformation coordinateTransformation
void setName(String name)
Definition: Counts.java:53
void setCoord(final Coord coord)
Definition: Count.java:147
static< T > Id< T > create(final long key, final Class< T > type)
Definition: Id.java:68
void setDescription(String description)
Definition: Counts.java:61
final Volume createVolume(final int h, final double val)
Definition: Count.java:76
void setYear(int year)
Definition: Counts.java:77
void endTag(final String name, final String content, final Stack< String > context)
void startTag(final String name, final Attributes atts, final Stack< String > context)
CountsReaderMatsimV1(final CoordinateTransformation coordinateTransformation, final Counts counts)
final Count< T > createAndAddCount(final Id< T > linkId, final String stationName)
Old API.
Definition: Counts.java:114