Half-commit. Not finished.
package horaris;
import ogdl.OgdlParser;
import ogdl.parser.*;
import java.util.Vector;
import java.util.Hashtable;
class Trajnoj extends ParserHandlerBase
{
private final int S_RADIKO = 0;
private final int S_TRAJNO = 1;
private final int S_TAGOJ = 2;
private final int S_ENTAGO = 3;
private final int S_HOROJ = 4;
private final int S_LOKOJ = 5;
private final int S_SENCOJ = 6;
private final int S_KOMENTOJ = 7;
private final int S_FINO = 8;
public Vector tempoj;
public Hashtable komentoj;
private int stato;
private Vector sercxotagoj;
private String sercxosenco;
private String sercxokomenco;
private String sercxofino;
private Tempo komencotempo;
private Tempo finotempo;
private String tmptempo;
private boolean tagobona[];
private boolean sencobona;
private boolean komencobona;
private boolean finobona;
private Vector rezultoj;
public Trajnoj(Vector tagoj, String senco, String komenco, String fino)
{
sercxotagoj = tagoj;
sercxosenco = senco;
sercxokomenco = komenco;
sercxofino = fino;
tagobona = new boolean[sercxotagoj.size()];
clearSearch();
rezultoj = new Vector();
}
/** Return true if the result should be noted. */
private boolean novarezulto()
{
/* Tagoj */
for (int i=0; i < sercxotagoj.size(); i++)
if (tagobona[i] != true)
return false;
if (komencobona && finobona && sencobona)
{
/* Add the result */
}
}
private void clearSearch()
{
for (int i=0; i < sercxotagoj.size(); i++)
tagobona[i] = false;
sencobona = false;
komencobona = false;
finobona = false;
}
/** Returns the index where found or -1 if not found */
private int inVector(Vector v, String s)
{
for (int i=0; i < v.size(); i++)
if(s.equals((String)v.elementAt(i)))
return i;
return -1;
}
private void proviTagon(String s)
{
int i;
i = inVector(sercxotagoj, s);
if( i >= 0)
tagobona[i] = true;
}
/** Returns if the place matches komencon aux finon */
private boolean proviLokon(String s)
{
if (komencobona == false)
{
if (s.equals(sercxosenco))
{
komencobona = true;
komencotempo = new Tempo(tmptempo);
return true;
}
} else if (komencobona == true && finobona == false)
{
if (s.equals(sercxosenco))
{
finobona = true;
finotempo = new Tempo(tmptempo);
return true;
}
}
return false;
}
private void proviSencon(String s)
{
if (sencobona == false)
{
if (s.equals(sercxosenco))
sencobona = true;
}
}
private void add(int nivelo, String s)
{
if (nivelo == 0)
{
System.err.println("Nivelo 0: " + s);
if (s.equals("Comboi"))
stato = S_TRAJNO;
else
stato = S_RADIKO;
} else if (nivelo == 1)
{
/* S_TRAJNO when set from level 0 to 1 */
System.err.println("Nivelo 1: " + s);
if (s.equals("Dies"))
stato = S_TAGOJ;
else if (s.equals("Sentit"))
stato = S_SENCOJ;
else if (s.equals("Hores"))
stato = S_HOROJ;
else if (s.equals("Comentari"))
stato = S_KOMENTOJ;
} else if (nivelo == 2) {
System.err.println("Nivelo 2: " + s);
switch(stato)
{
case S_TAGOJ:
proviTagon(s);
break;
case S_HOROJ:
/* Konservi tempon */
tmptempo = s;
break;
case S_SENCOJ:
proviSencon(s);
break;
case S_KOMENTOJ:
/* *** ALDONI KOMENTON */
break;
}
} else if (nivelo == 3) {
switch(stato)
{
case S_HOROJ:
proviLokon(s);
break;
}
}
}
public boolean event(int speco, int level, String s)
{
if (speco != OgdlParser.CONTENT)
return true;
if (s == null) return true;
add(level, s);
if (stato == S_FINO)
return false;
else
return true;
}
}