package Elevator; public class LiftWachtrij extends Wachtrij{ private int aantalEtages = 0; public LiftWachtrij(int a) { super(a, 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 Eindewachtrij = bepaalEindeWachtrij(); boolean existsinWachtrij = false; existsinWachtrij = existsinWachtrij(Etage); if(!existsinWachtrij){ cleanupWachtrij(); try { wachtrij[Eindewachtrij][0] = Etage; // Etage waar gedrukt wordt } 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){ // Loop array na, als Etage en Richting er al inzitten return true for (int i=0;i < wachtrijLengte;i++){ if ((wachtrij[i][0] == Etage)){ 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){ // 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][0] = -1; // zet Etage 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 e, int r){ int etage = -1; boolean testWaarde = false; cleanupWachtrij(); // make sure the wachtrij is nicely ordered (extra insurance..) for(int i = 0; i < wachtrijLengte; i++){ testWaarde = (wachtrij[i][0] != -1); testWaarde = testWaarde && ((r == LiftBesturingSysteem.RICHTINGOMHOOG) && (etage < wachtrij[i][0]) || (r == LiftBesturingSysteem.RICHTINGOMLAAG) && (etage > wachtrij[i][0])); if(testWaarde){ etage = wachtrij[i][0]; // de etage wachtrij[i][0] = -1; // remove the request from the wachtrij wachtrij[i][1] = -1; break; } } if (etage == -1){ etage = wachtrij[0][0]; wachtrij[0][0] = -1; // remove the request from the wachtrij wachtrij[0][1] = -1; } cleanupWachtrij(); // clean up the wachtrij for the other elevators return etage; } }