-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathResources.java
158 lines (122 loc) · 4.86 KB
/
Resources.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package de.tum.bgu.msm.resources;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import static de.tum.bgu.msm.resources.Properties.*;
/**
* Created by Nico on 19.07.2017.
*/
public class Resources {
//TODO: provide defaults.
public static Resources instance;
private final Properties properties;
private final Path baseDirectory;
private Resources(Properties properties, String baseDirectory) {
this.properties = properties;
this.baseDirectory = Paths.get(baseDirectory).getParent();
}
public static void initializeResources(String fileName) {
try (FileInputStream in = new FileInputStream(fileName)) {
Properties properties = new Properties();
properties.load(in);
instance = new Resources(properties, fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
public Path getZonesInputFile() {
return baseDirectory.resolve(getString(ZONES));
}
public Path getZoneShapesInputFile() {
return baseDirectory.resolve(getString(ZONE_SHAPEFILE));
}
public Path getBaseDirectory() {
return baseDirectory.toAbsolutePath();
}
public Path getBorderReductionDamperFilePath() {
return baseDirectory.resolve(getString(REDUCTION_NEAR_BORDER_DAMPERS));
}
public Path getJobsFilePath() {
return baseDirectory.resolve(getString(JOBS));
}
public Path getSchoolsFilePath() {
return baseDirectory.resolve(getString(SCHOOLS));
}
public Path getHouseholdsFilePath() {
return baseDirectory.resolve(getString(HOUSEHOLDS));
}
public Path getPersonsFilePath() {
return baseDirectory.resolve(getString(PERSONS));
}
public Path getDwellingsFilePath() {
return baseDirectory.resolve(getString(DWELLINGS));
}
public Path getEconomicStatusFilePath() {
return baseDirectory.resolve(getString(ECONOMIC_STATUS));
}
public synchronized int getInt(String key) {
return Integer.parseInt(properties.getProperty(key));
}
public synchronized int getInt(String key, int defaultValue) {
if (properties.containsKey(key)) {
return Integer.parseInt(properties.getProperty(key));
} else {
return defaultValue;
}
}
public synchronized String getString(String key) {
return properties.getProperty(key);
}
public synchronized String[] getArray(String key) {
return properties.getProperty(key).split(",");
}
public synchronized String[] getArray(String key, String[] defaultValue) {
if (properties.containsKey(key)) {
return properties.getProperty(key).split(",");
} else {
return defaultValue;
}
}
public synchronized boolean getBoolean(String key) {
return Boolean.parseBoolean(properties.getProperty(key));
}
public synchronized boolean getBoolean(String key, boolean defaultValue) {
if (properties.containsKey(key)) {
return Boolean.parseBoolean(properties.getProperty(key));
} else {
return defaultValue;
}
}
public synchronized double getDouble(String key, double defaultValue) {
String value = properties.getProperty(key);
return value != null ? Double.parseDouble(value) : defaultValue;
}
public Path getAreaTypesAndRailDistancesFilePath() {
return baseDirectory.resolve(getString((AREA_TYPES_AND_RAIL_DISTANCE)));
}
public Path getExternalDepartureTimeFilePath() {
return baseDirectory.resolve(EXTERNAL_DEPARTURE_TIME_FILE);
}
public Path getTimeOfDayDistributionsFilePath() {
return baseDirectory.resolve(getString(TIME_OF_DAY_DISTRIBUTIONS));
}
public Path getTripAttractionRatesFilePath() {
return baseDirectory.resolve(getString(TRIP_ATTRACTION_RATES));
}
public Path getOutputHouseholdPath() {
String scenarioName = Resources.instance.getString(de.tum.bgu.msm.resources.Properties.SCENARIO_NAME);
return baseDirectory.resolve("scenOutput").resolve(scenarioName).resolve(getString(SCENARIO_YEAR)).resolve("microData").resolve("hhInclTrips.csv");
}
public Path getOutputPersonsPath() {
String scenarioName = Resources.instance.getString(de.tum.bgu.msm.resources.Properties.SCENARIO_NAME);
return baseDirectory.resolve("scenOutput").resolve(scenarioName).resolve(getString(SCENARIO_YEAR)).resolve("microData").resolve("ppInclTrips.csv");
}
public Path getExternalZonesListFilePath() {
return baseDirectory.resolve(getString(de.tum.bgu.msm.resources.Properties.EXTERNAL_ZONES_LIST_FILE));
}
public Path getRelativePath(String autoPeakSkim) {
return baseDirectory.resolve(getString(autoPeakSkim));
}
}