/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package userdefined;

import database.Context;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import structures.Constants;
import structures.HashContext;
import structures.RoadSignEntry;

/**
 *
 * @author baba
 */
public interface ConditionInterface {

    public String[] innerClasses = {"CheckDynamicRoadSign", "CheckLocation"};

    //The user will have to implement these two functions
    public Vector CheckCondition(Hashtable context, HashContext mySelf);

    public String getName();
    //Take care in the second method "getName()". It returns you the name of the class not the method

    //Searches the context for vehicles with the type school bus or construction cone
    public class CheckDynamicRoadSign implements ConditionInterface {

        public Vector CheckCondition(Hashtable context, HashContext mySelf) {
            Vector tmpVector = new Vector();
            Enumeration en = context.elements();

            while (en.hasMoreElements()) {


                HashContext tmpHash = (HashContext) en.nextElement();
                String vehicle_type = tmpHash.GetObjectAsString(Constants.HASH_TYPE);
                if (vehicle_type != null) {
                    if (vehicle_type.equals(Constants.TYPE_SCHOOL_STRING)
                            || vehicle_type.equals(Constants.TYPE_CONSTRUCTION_STRING)
                            || vehicle_type.equals(Constants.TYPE_AMBULANCE_STRING)
                            || vehicle_type.equals(Constants.TYPE_POLICE_STRING)
                            || vehicle_type.equals(Constants.TYPE_FIRE_STRING)
                            || vehicle_type.equals(Constants.TYPE_PEDESTRIAN_STRING)
                            || vehicle_type.equals(Constants.TYPE_TOW_STRING)) {

                        System.out.println("ADDING DYNAMIC SIGN!!");
                        tmpVector.addElement(tmpHash);
                    }


                    Enumeration enDynamic = Context.dynamicRoadSignVector.elements();
                    while (enDynamic.hasMoreElements()) {
                        RoadSignEntry tmpRoadSign = (RoadSignEntry) enDynamic.nextElement();
                        if (tmpRoadSign.getDynamicid().equals(tmpHash.GetObjectAsString(Constants.HASH_ID))) {
                            Context.dynamicRoadSignVector.removeElement(tmpRoadSign);
                            break;
                        }

                    }

                }

            }
            return tmpVector;
        }

        public String getName() {
            return "CheckDynamicRoadSign";
        }
    }

    public class CheckLocation implements ConditionInterface {

        public Vector CheckCondition(Hashtable context, HashContext mySelf) {
            Vector tmpVector = new Vector();
            Enumeration en = context.elements();

            while (en.hasMoreElements()) {
                HashContext tmpHash = (HashContext) en.nextElement();

                tmpVector.addElement(tmpHash);

            }
            return tmpVector;
        }

        public String getName() {
            return "CheckLocation";
        }
    }
}

