src/horaris/Horaro.java
changeset 12 3932322b7d83
equal deleted inserted replaced
11:27ba8edb3437 12:3932322b7d83
       
     1 package horaris;
       
     2 
       
     3 import ogdl.OgdlParser;
       
     4 import ogdl.parser.*;
       
     5 import java.util.Vector;
       
     6 import java.util.Hashtable;
       
     7 
       
     8 public class Horaro extends ParserHandlerBase
       
     9 {
       
    10 	private final int S_RADIKO = 0;
       
    11 	private final int S_TAGOJ =  1;
       
    12 	private final int S_ENTAGO = 2;
       
    13 	private final int S_LOKOJ =  3;
       
    14 	private final int S_SENCOJ = 4;
       
    15 	private final int S_FINO = 5;
       
    16 	public Vector tagoj;
       
    17 	public int defaulttago = 0;
       
    18 	public Vector lokoj;
       
    19 	public Vector sencoj;
       
    20 	public Hashtable sencolokoj;
       
    21 	private int state;
       
    22 	private int nivelo;
       
    23 
       
    24 	public Horaro()
       
    25 	{
       
    26 		tagoj = new Vector();
       
    27 		lokoj = new Vector();
       
    28 		sencoj = new Vector();
       
    29 	}
       
    30 
       
    31 	private void addTago(String s)
       
    32 	{
       
    33 		tagoj.addElement(s);
       
    34 	}
       
    35 
       
    36 	private void addLoko(String s)
       
    37 	{
       
    38 		lokoj.addElement(s);
       
    39 	}
       
    40 
       
    41 	private void addSenco(String s)
       
    42 	{
       
    43 		sencoj.addElement(s);
       
    44 	}
       
    45 
       
    46 	private void add(String s)
       
    47 	{
       
    48 		if (nivelo == 0)
       
    49 		{
       
    50 			System.err.println("Nivelo 0: " + s);
       
    51 			if (s.equals("Dies"))
       
    52 				state = S_TAGOJ;
       
    53 			else if (s.equals("Sentits"))
       
    54 				state = S_SENCOJ;
       
    55 			else if (s.equals("Llocs"))
       
    56 				state = S_LOKOJ;
       
    57 			else if (s.equals("Comboi"))
       
    58 				state = S_FINO;
       
    59 		} else if (nivelo == 1)
       
    60 		{
       
    61 			System.err.println("Nivelo 1: " + s);
       
    62 			switch(state)
       
    63 			{
       
    64 				case S_TAGOJ:
       
    65 					addTago(s);
       
    66 					break;
       
    67 				case S_LOKOJ:
       
    68 					addLoko(s);
       
    69 					break;
       
    70 				case S_SENCOJ:
       
    71 					addSenco(s);
       
    72 					break;
       
    73 			}
       
    74 		} else if (nivelo == 2) {
       
    75 			System.err.println("Nivelo 2");
       
    76 		}
       
    77 
       
    78 	}
       
    79 
       
    80 	public boolean event(int speco, int level, String s)
       
    81 	{
       
    82 		if (speco != OgdlParser.CONTENT)
       
    83 			return true;
       
    84 
       
    85 		if (s == null) return true;
       
    86 
       
    87 		nivelo = level;
       
    88 		add(s);
       
    89 		if (state == S_FINO)
       
    90 			return false;
       
    91 		else
       
    92 			return true;
       
    93 	}
       
    94 }