12
|
1 |
package horaris;
|
|
2 |
|
|
3 |
import ogdl.OgdlParser;
|
|
4 |
import ogdl.parser.*;
|
|
5 |
import java.util.Vector;
|
|
6 |
import java.util.Hashtable;
|
|
7 |
|
|
8 |
class Trajnoj extends ParserHandlerBase
|
|
9 |
{
|
|
10 |
private final int S_RADIKO = 0;
|
|
11 |
private final int S_TRAJNO = 1;
|
|
12 |
private final int S_TAGOJ = 2;
|
|
13 |
private final int S_ENTAGO = 3;
|
|
14 |
private final int S_HOROJ = 4;
|
|
15 |
private final int S_LOKOJ = 5;
|
|
16 |
private final int S_SENCOJ = 6;
|
|
17 |
private final int S_KOMENTOJ = 7;
|
|
18 |
private final int S_FINO = 8;
|
|
19 |
public Vector tempoj;
|
|
20 |
public Hashtable komentoj;
|
|
21 |
private int stato;
|
|
22 |
|
|
23 |
private Vector sercxotagoj;
|
|
24 |
private String sercxosenco;
|
|
25 |
private String sercxokomenco;
|
|
26 |
private String sercxofino;
|
|
27 |
|
|
28 |
private Tempo komencotempo;
|
|
29 |
private Tempo finotempo;
|
|
30 |
private String tmptempo;
|
|
31 |
|
|
32 |
private boolean tagobona[];
|
|
33 |
private boolean sencobona;
|
|
34 |
private boolean komencobona;
|
|
35 |
private boolean finobona;
|
|
36 |
|
|
37 |
private Vector rezultoj;
|
|
38 |
|
|
39 |
public Trajnoj(Vector tagoj, String senco, String komenco, String fino)
|
|
40 |
{
|
|
41 |
sercxotagoj = tagoj;
|
|
42 |
sercxosenco = senco;
|
|
43 |
sercxokomenco = komenco;
|
|
44 |
sercxofino = fino;
|
|
45 |
tagobona = new boolean[sercxotagoj.size()];
|
|
46 |
clearSearch();
|
|
47 |
rezultoj = new Vector();
|
|
48 |
}
|
|
49 |
|
|
50 |
/** Return true if the result should be noted. */
|
|
51 |
private boolean novarezulto()
|
|
52 |
{
|
|
53 |
/* Tagoj */
|
|
54 |
for (int i=0; i < sercxotagoj.size(); i++)
|
|
55 |
if (tagobona[i] != true)
|
|
56 |
return false;
|
|
57 |
if (komencobona && finobona && sencobona)
|
|
58 |
{
|
|
59 |
/* Add the result */
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
private void clearSearch()
|
|
64 |
{
|
|
65 |
for (int i=0; i < sercxotagoj.size(); i++)
|
|
66 |
tagobona[i] = false;
|
|
67 |
sencobona = false;
|
|
68 |
komencobona = false;
|
|
69 |
finobona = false;
|
|
70 |
}
|
|
71 |
|
|
72 |
/** Returns the index where found or -1 if not found */
|
|
73 |
private int inVector(Vector v, String s)
|
|
74 |
{
|
|
75 |
for (int i=0; i < v.size(); i++)
|
|
76 |
if(s.equals((String)v.elementAt(i)))
|
|
77 |
return i;
|
|
78 |
return -1;
|
|
79 |
}
|
|
80 |
|
|
81 |
private void proviTagon(String s)
|
|
82 |
{
|
|
83 |
int i;
|
|
84 |
i = inVector(sercxotagoj, s);
|
|
85 |
if( i >= 0)
|
|
86 |
tagobona[i] = true;
|
|
87 |
}
|
|
88 |
|
|
89 |
/** Returns if the place matches komencon aux finon */
|
|
90 |
private boolean proviLokon(String s)
|
|
91 |
{
|
|
92 |
if (komencobona == false)
|
|
93 |
{
|
|
94 |
if (s.equals(sercxosenco))
|
|
95 |
{
|
|
96 |
komencobona = true;
|
|
97 |
komencotempo = new Tempo(tmptempo);
|
|
98 |
return true;
|
|
99 |
}
|
|
100 |
} else if (komencobona == true && finobona == false)
|
|
101 |
{
|
|
102 |
if (s.equals(sercxosenco))
|
|
103 |
{
|
|
104 |
finobona = true;
|
|
105 |
finotempo = new Tempo(tmptempo);
|
|
106 |
return true;
|
|
107 |
}
|
|
108 |
}
|
|
109 |
return false;
|
|
110 |
}
|
|
111 |
|
|
112 |
private void proviSencon(String s)
|
|
113 |
{
|
|
114 |
if (sencobona == false)
|
|
115 |
{
|
|
116 |
if (s.equals(sercxosenco))
|
|
117 |
sencobona = true;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
private void add(int nivelo, String s)
|
|
122 |
{
|
|
123 |
if (nivelo == 0)
|
|
124 |
{
|
|
125 |
System.err.println("Nivelo 0: " + s);
|
|
126 |
if (s.equals("Comboi"))
|
|
127 |
stato = S_TRAJNO;
|
|
128 |
else
|
|
129 |
stato = S_RADIKO;
|
|
130 |
} else if (nivelo == 1)
|
|
131 |
{
|
|
132 |
/* S_TRAJNO when set from level 0 to 1 */
|
|
133 |
System.err.println("Nivelo 1: " + s);
|
|
134 |
if (s.equals("Dies"))
|
|
135 |
stato = S_TAGOJ;
|
|
136 |
else if (s.equals("Sentit"))
|
|
137 |
stato = S_SENCOJ;
|
|
138 |
else if (s.equals("Hores"))
|
|
139 |
stato = S_HOROJ;
|
|
140 |
else if (s.equals("Comentari"))
|
|
141 |
stato = S_KOMENTOJ;
|
|
142 |
} else if (nivelo == 2) {
|
|
143 |
System.err.println("Nivelo 2: " + s);
|
|
144 |
switch(stato)
|
|
145 |
{
|
|
146 |
case S_TAGOJ:
|
|
147 |
proviTagon(s);
|
|
148 |
break;
|
|
149 |
case S_HOROJ:
|
|
150 |
/* Konservi tempon */
|
|
151 |
tmptempo = s;
|
|
152 |
break;
|
|
153 |
case S_SENCOJ:
|
|
154 |
proviSencon(s);
|
|
155 |
break;
|
|
156 |
case S_KOMENTOJ:
|
|
157 |
/* *** ALDONI KOMENTON */
|
|
158 |
break;
|
|
159 |
}
|
|
160 |
} else if (nivelo == 3) {
|
|
161 |
switch(stato)
|
|
162 |
{
|
|
163 |
case S_HOROJ:
|
|
164 |
proviLokon(s);
|
|
165 |
break;
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
}
|
|
170 |
|
|
171 |
public boolean event(int speco, int level, String s)
|
|
172 |
{
|
|
173 |
if (speco != OgdlParser.CONTENT)
|
|
174 |
return true;
|
|
175 |
|
|
176 |
if (s == null) return true;
|
|
177 |
|
|
178 |
add(level, s);
|
|
179 |
if (stato == S_FINO)
|
|
180 |
return false;
|
|
181 |
else
|
|
182 |
return true;
|
|
183 |
}
|
|
184 |
}
|