MATSIM
Public Member Functions | Private Member Functions | Private Attributes | List of all members
tutorial.programming.example08DemandGeneration.ZCensusParser Class Reference

Public Member Functions

List< ZCensusEntryreadFile (String inFile)
 

Private Member Functions

int parseInteger (String string)
 
double parseDouble (String string)
 

Private Attributes

String separator = "\t"
 
Charset charset = Charset.forName("UTF-8")
 

Detailed Description

Definition at line 12 of file ZCensusParser.java.

Member Function Documentation

List<ZCensusEntry> tutorial.programming.example08DemandGeneration.ZCensusParser.readFile ( String  inFile)

Definition at line 17 of file ZCensusParser.java.

References tutorial.programming.example08DemandGeneration.ZCensusParser.parseDouble(), and tutorial.programming.example08DemandGeneration.ZCensusParser.parseInteger().

Referenced by tutorial.programming.example08DemandGeneration.RunZPopulationGenerator.createPopulationFromCensusFile().

18  {
19  List<ZCensusEntry> entries = new ArrayList<ZCensusEntry>();
20 
21  FileInputStream fis = null;
22  InputStreamReader isr = null;
23  BufferedReader br = null;
24 
25  try
26  {
27  fis = new FileInputStream(inFile);
28  isr = new InputStreamReader(fis, charset);
29  br = new BufferedReader(isr);
30 
31  // skip first Line
32  br.readLine();
33 
34  String line;
35  while((line = br.readLine()) != null)
36  {
37  ZCensusEntry censusEntry = new ZCensusEntry();
38 
39  String[] cols = line.split(separator);
40 
41  censusEntry.id_person = parseInteger(cols[0]);
42  censusEntry.wp = parseDouble(cols[1]);
43  censusEntry.tripnum = parseInteger(cols[2]);
44  censusEntry.starttime = parseInteger(cols[3]);
45  censusEntry.h_x = parseDouble(cols[4]);
46  censusEntry.h_y = parseDouble(cols[5]);
47  censusEntry.s_x = parseDouble(cols[6]);
48  censusEntry.s_y = parseDouble(cols[7]);
49  censusEntry.d_x = parseDouble(cols[8]);
50  censusEntry.d_y = parseDouble(cols[9]);
51  censusEntry.bike = parseInteger(cols[10]);
52  censusEntry.age = parseInteger(cols[11]);
53  censusEntry.gender = parseInteger(cols[12]);
54  censusEntry.license = parseInteger(cols[13]);
55  censusEntry.tickets = parseInteger(cols[14]);
56  censusEntry.modechoice = parseInteger(cols[15]);
57  censusEntry.caravailability = parseInteger(cols[16]);
58  censusEntry.mobtools = parseInteger(cols[17]);
59  censusEntry.inc1000 = parseDouble(cols[18]);
60  censusEntry.day = parseInteger(cols[19]);
61  censusEntry.tripmode = parseInteger(cols[20]);
62  censusEntry.trippurpose = parseInteger(cols[21]);
63  censusEntry.tripdistance = parseDouble(cols[22]);
64  censusEntry.tripduration = parseInteger(cols[23]);
65  censusEntry.id_tour = parseInteger(cols[24]);
66 
67  entries.add(censusEntry);
68  }
69 
70  br.close();
71  isr.close();
72  fis.close();
73  }
74  catch (FileNotFoundException e)
75  {
76  e.printStackTrace();
77  }
78  catch (IOException e)
79  {
80  e.printStackTrace();
81  }
82 
83  return entries;
84  }

Here is the call graph for this function:

int tutorial.programming.example08DemandGeneration.ZCensusParser.parseInteger ( String  string)
private

Definition at line 86 of file ZCensusParser.java.

Referenced by tutorial.programming.example08DemandGeneration.ZCensusParser.readFile().

87  {
88  if (string == null) return 0;
89  else if (string.trim().isEmpty()) return 0;
90  else return Integer.valueOf(string);
91  }
double tutorial.programming.example08DemandGeneration.ZCensusParser.parseDouble ( String  string)
private

Definition at line 93 of file ZCensusParser.java.

Referenced by tutorial.programming.example08DemandGeneration.ZCensusParser.readFile().

94  {
95  if (string == null) return 0.0;
96  else if (string.trim().isEmpty()) return 0.0;
97  else return Double.valueOf(string);
98  }

Member Data Documentation

String tutorial.programming.example08DemandGeneration.ZCensusParser.separator = "\t"
private

Definition at line 14 of file ZCensusParser.java.

Charset tutorial.programming.example08DemandGeneration.ZCensusParser.charset = Charset.forName("UTF-8")
private

Definition at line 15 of file ZCensusParser.java.


The documentation for this class was generated from the following file: