package Elevator; public class HoofdWachtrij extends Wachtrij{ private int aantalEtages = 0; public HoofdWachtrij(int a) { super(((2*a)-2), 2); aantalEtages = a; } /////////////////// // Name: addToWachtrij // Description: Adds a request to the wachttrij, at the end of the wachtrij // Input: The etage and the richting // Result: The request is added to the wachtrij, if it wasn't already there /////////////////// public void addToWachtrij(int Etage, int Richting) { int Eindewachtrij = bepaalEindeWachtrij(); boolean existsinWachtrij = false; existsinWachtrij = existsinWachtrij(Etage,Richting); if(!existsinWachtrij){ cleanupWachtrij(); try { wachtrij[Eindewachtrij][0] = Etage; // Etage waar gedrukt wordt wachtrij[Eindewachtrij][1] = Richting; // 1 is omhoog, 0 is omlaag } catch(Exception e) { System.out.println("addToWachtrij ging waarschijnlijk buiten het array!"); } } } /////////////////// // Name: existsinWachtrij // Description: Checks if the request already is in the wachtrij // Input: Etage and Richting // Result: True if already in wachtrij, otherwise false /////////////////// public boolean existsinWachtrij(int Etage, int Richting){ // Loop array na, als Etage en Richting er al inzitten return true for (int i=0;i < wachtrijLengte;i++){ if ((wachtrij[i][0] == Etage) && (wachtrij[i][1] == Richting)){ return true; } } return false; } /////////////////// // Name: removeFromWachtrij // Description: removes the value from the wachtrij // Input: Etage and Richting // Result: Is removed from wachtrij /////////////////// public void removeFromWachtrij(int Etage, int Richting){ // Loop array na, als Etage en Richting er al inzitten return true for (int i=0;i < wachtrijLengte;i++){ if ((wachtrij[i][0] == Etage) && (wachtrij[i][1] == Richting)){ wachtrij[i][0] = -1; // zet Etage weer op -1 wachtrij[i][1] = -1; // zet Richting weer op -1 cleanupWachtrij(); } } } /////////////////// // Name: getNewEtage // Description: Gives a new etage where a lift should go to // Input: None // Result: The etage that is the first in the wachtrij, return -1 if wachtrij is empty // Note: It isn't important to know where if the first one in the wachtrij // wants to go up or down. /////////////////// public int getNewEtage(){ int etage; cleanupWachtrij(); // make sure the wachtrij is nicely ordered (extra insurance..) etage = wachtrij[0][0]; // de etage wachtrij[0][0] = -1; // remove the request from the wachtrij wachtrij[0][1] = -1; cleanupWachtrij(); // clean up the wachtrij for the other elevators if (etage == -1){ return -1; // the wachtrij is empty } else{ return etage; } } }