MATSIM
ScenarioConfigGroup.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * ScenarioConfigGroup
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2009 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 package org.matsim.core.config.groups;
21 
22 import java.util.Map;
23 
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
29 
34 public final class ScenarioConfigGroup extends ConfigGroup {
35  public static final String GROUP_NAME = "scenario";
36 
37  private static final String USE_LANES = "useLanes";
38  private static final String USE_HOUSEHOLDS = "useHouseholds";
39  private static final String USE_TRANSIT = "useTransit";
40  private static final String USE_VEHICLES = "useVehicles";
41  private static final String SIMULATION_PERIOD_DAYS = "simulationPeriodInDays"; // is not yet written to log-output so we can still rename it internally
42 
43  private static final Logger log = LogManager.getLogger( ScenarioConfigGroup.class ) ;
44 
45  private double simulationPeriodInDays = 1.0;
46 
48  super(GROUP_NAME);
49  }
50 
51  @Override
52  public Map<String, String> getComments() {
53  Map<String,String> map = super.getComments();
54 
55  // I don't think that the following is used anywhere:
56  final String message = "Deprecated, do not use. The file is loaded when the filename is given. Functionality needs to be switched on elsewhere.";
57  map.put(USE_LANES, message) ; // since jul'15
58  map.put(USE_HOUSEHOLDS, message); // since jul'15
59  map.put(USE_VEHICLES, message); // since jul'15
60  map.put(USE_TRANSIT, "Deprecated, do not use. See transit section of config file.") ; // since jul'15
61 
62  return map;
63  }
64 
65  @Override
66  public final void addParam(final String paramName, final String value) {
67  // emulate previous behavior of reader (ignore null values at reading). td Apr'15
68  if ( "null".equalsIgnoreCase( value ) ) return;
69 
70  if (USE_LANES.equals(paramName)) {
71  this.setUseLanes( Boolean.parseBoolean(value) );
72  } else if (USE_HOUSEHOLDS.equals(paramName)) {
73  this.setUseHouseholds( Boolean.parseBoolean(value) );
74  } else if (USE_VEHICLES.equals(paramName)) {
75  this.setUseVehicles( Boolean.parseBoolean(value) );
76  } else if (USE_TRANSIT.equals(paramName)) {
77  this.setUseTransit( Boolean.parseBoolean(value) );
78  } else {
79  throw new IllegalArgumentException("Parameter '" + paramName + "' is not supported by config group '" + GROUP_NAME + "'.");
80  }
81  }
82  @Override
83  public final String getValue(final String param_name) {
84  throw new UnsupportedOperationException("Use getters for accessing values!");
85  }
86 
87  @Override
88  public final Map<String, String> getParams() {
89  Map<String, String> params = super.getParams();
90  return params;
91  }
92 
93  // if they are not in getParams, they will not be included into the config file dump.
94 
95  // if they are, however, in addParam, then the methods will be called (which throw exceptions).
96 
97  // Once the methods below are removed throughout the code, those exceptions can be moved into the addParam method.
98 
99  // Eventually, the whole scenario config group can be moved away.
100 
101  // kai, jul'15
102 
103 
104 
105 
106  @Deprecated // since jul'15
107  throw new RuntimeException( getMessage( USE_LANES ) ) ;
108  }
109 
110  @Deprecated // since jul'15
111  throw new RuntimeException( getMessage( USE_HOUSEHOLDS ) ) ;
112  }
113 
114  @Deprecated // since jul'15
115  throw new RuntimeException( getMessage( USE_VEHICLES ) ) ;
116  }
117 
118  @Deprecated // since jul'15
119  throw new RuntimeException("The " + USE_TRANSIT + " switch has moved to the transit section of the config file." ) ;
120  }
121 
125  }
126 
128  public double getSimulationPeriodInDays() {
129  return this.simulationPeriodInDays;
130  }
131 
132 
133  private static String getMessage( String module ) {
134  return "The " + module + " switch is no longer operational. The file is loaded if the file name"
135  + " is different from null. If you needed this for the creation of the container, use the ScenarioBuilder in "
136  + "ScenarioUtils. Note that loading the file does not mean that it is used anywhere; such functionality needs to be "
137  + "switched on elsewhere (e.g. in qsim, in transit, ...). If this does not work for you, please let us know. kai, jun'15";
138  }
139 
140 }
void setSimulationPeriodInDays(final double simulationPeriodInDays)
static String getMessage(String module)
final String getValue(final String param_name)
final void addParam(final String paramName, final String value)
final TreeMap< String, String > params