diff --git a/diag_classes.uml b/diag_classes.uml
new file mode 100644
index 0000000..46481ad
--- /dev/null
+++ b/diag_classes.uml
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+ 0.34
+
+
+
+
+
+ UML 1.4
+ false
+ false
+ true
+ false
+ false
+ false
+ false
+ true
+ false
+ true
+ 1
+ true
+ Dialog
+ 12
+ 0
+ Diagramme de classes
+
+
+
+
+
+
+
+
+
+
+
+
+ UML 1.4
+
+
+ GoodPractices
+
+
+ CodeGeneration
+
+
+
+
+ ArgoUML (using Netbeans XMI Writer version 1.0)
+ 0.34(6) revised on $Date: 2010-01-11 22:20:14 +0100 (Mon, 11 Jan 2010) $
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/diag_classes.uml~ b/diag_classes.uml~
new file mode 100644
index 0000000..e69de29
diff --git a/src/Requests/CallFromElevatorRequest.java b/src/Events/CallFromElevatorEvent.java
similarity index 70%
rename from src/Requests/CallFromElevatorRequest.java
rename to src/Events/CallFromElevatorEvent.java
index 828fcdb..24835a9 100644
--- a/src/Requests/CallFromElevatorRequest.java
+++ b/src/Events/CallFromElevatorEvent.java
@@ -1,12 +1,12 @@
-package Requests;
+package Events;
import commandSystem.Direction;
-public class CallFromElevatorRequest implements Request {
+public class CallFromElevatorEvent implements Event {
private final int wantedFloor;
- public CallFromElevatorRequest(int wantedFloor) {
+ public CallFromElevatorEvent(int wantedFloor) {
this.wantedFloor = wantedFloor;
}
@@ -26,8 +26,8 @@ public class CallFromElevatorRequest implements Request {
}
@Override
- public RequestType getType() {
- return RequestType.CALLFROMELEVATOR;
+ public EventType getType() {
+ return EventType.CALLFROMELEVATOR;
}
@Override
diff --git a/src/Requests/CallFromFloorRequest.java b/src/Events/CallFromFloorEvent.java
similarity index 72%
rename from src/Requests/CallFromFloorRequest.java
rename to src/Events/CallFromFloorEvent.java
index 92e3cd8..89d2824 100644
--- a/src/Requests/CallFromFloorRequest.java
+++ b/src/Events/CallFromFloorEvent.java
@@ -1,14 +1,14 @@
-package Requests;
+package Events;
import commandSystem.Direction;
-public class CallFromFloorRequest implements Request {
+public class CallFromFloorEvent implements Event {
private final int incomingCallFloor;
private final Direction direction;
- public CallFromFloorRequest(int incomingCallFloor, Direction direction) {
+ public CallFromFloorEvent(int incomingCallFloor, Direction direction) {
this.incomingCallFloor = incomingCallFloor;
this.direction = direction;
}
@@ -29,8 +29,8 @@ public class CallFromFloorRequest implements Request {
}
@Override
- public RequestType getType() {
- return RequestType.CALLFROMFLOOR;
+ public EventType getType() {
+ return EventType.CALLFROMFLOOR;
}
@Override
diff --git a/src/Requests/CancelEmergencyStopRequest.java b/src/Events/CancelEmergencyStopEvent.java
similarity index 68%
rename from src/Requests/CancelEmergencyStopRequest.java
rename to src/Events/CancelEmergencyStopEvent.java
index 553e115..999fb11 100644
--- a/src/Requests/CancelEmergencyStopRequest.java
+++ b/src/Events/CancelEmergencyStopEvent.java
@@ -1,10 +1,10 @@
-package Requests;
+package Events;
import commandSystem.Direction;
-public class CancelEmergencyStopRequest implements Request{
+public class CancelEmergencyStopEvent implements Event{
- public CancelEmergencyStopRequest() {
+ public CancelEmergencyStopEvent() {
}
@Override
@@ -23,8 +23,8 @@ public class CancelEmergencyStopRequest implements Request{
}
@Override
- public RequestType getType() {
- return RequestType.CANCELEMERGENCYSTOP;
+ public EventType getType() {
+ return EventType.CANCELEMERGENCYSTOP;
}
@Override
diff --git a/src/Requests/EmergencyStopRequest.java b/src/Events/EmergencyStopEvent.java
similarity index 70%
rename from src/Requests/EmergencyStopRequest.java
rename to src/Events/EmergencyStopEvent.java
index d57f6ec..7183072 100644
--- a/src/Requests/EmergencyStopRequest.java
+++ b/src/Events/EmergencyStopEvent.java
@@ -1,10 +1,10 @@
-package Requests;
+package Events;
import commandSystem.Direction;
-public class EmergencyStopRequest implements Request {
+public class EmergencyStopEvent implements Event {
- public EmergencyStopRequest() {
+ public EmergencyStopEvent() {
}
@Override
@@ -23,8 +23,8 @@ public class EmergencyStopRequest implements Request {
}
@Override
- public RequestType getType() {
- return RequestType.EMERGENCYSTOP;
+ public EventType getType() {
+ return EventType.EMERGENCYSTOP;
}
@Override
diff --git a/src/Events/Event.java b/src/Events/Event.java
new file mode 100644
index 0000000..f147696
--- /dev/null
+++ b/src/Events/Event.java
@@ -0,0 +1,76 @@
+package Events;
+
+import commandSystem.Direction;
+
+public interface Event {
+
+ /**
+ * Gets the EventType associated with the event
+ *
+ * @return the EventType of the event.
+ */
+ public EventType getType();
+
+ /*
+ *
+ *
+ * CallFromFloorEvent methods
+ *
+ *
+ */
+
+ /**
+ * Gets the direction of a floor call.
+ *
+ * @return the direction of the floor call, unconcerned extending classes return
+ * NONE.
+ */
+ public Direction getRequestedDirection();
+
+ /**
+ * Gets the source floor of a floor call.
+ *
+ * @return the floor the event was called from, unconcerned extending classes
+ * return -1.
+ */
+ public int getIncomingCallFloor();
+
+ /*
+ *
+ *
+ * CallFromElevatorEvent methods
+ *
+ *
+ */
+
+ /**
+ * Gets the requested floor of an inside-elevator call.
+ *
+ * @return the requested floor, unconcerned extending classes return -1.
+ */
+ public int getRequestedFloor();
+
+ /*
+ *
+ *
+ * ReachedFloorEvent methods
+ *
+ *
+ */
+
+ /**
+ * Gets the index of the floor just reached.
+ *
+ * @return the floor the elevator just reached, unconcerned extending classes
+ * return -1.
+ */
+ public int getCurrentFloor();
+
+ /**
+ * Gets the direction the elevator reached the last floor from.
+ *
+ * @return the direction of the elevator. Unconcerned extending classes return
+ * NONE.
+ */
+ public Direction getCurrentDirection();
+}
diff --git a/src/Requests/RequestType.java b/src/Events/EventType.java
similarity index 67%
rename from src/Requests/RequestType.java
rename to src/Events/EventType.java
index f8daaea..4e28abb 100644
--- a/src/Requests/RequestType.java
+++ b/src/Events/EventType.java
@@ -1,5 +1,5 @@
-package Requests;
+package Events;
-public enum RequestType {
+public enum EventType {
CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP, REACHEDFLOORSIGNAL
}
diff --git a/src/Requests/ReachedFloorSignal.java b/src/Events/ReachedFloorEvent.java
similarity index 72%
rename from src/Requests/ReachedFloorSignal.java
rename to src/Events/ReachedFloorEvent.java
index 96db50b..a2766f0 100644
--- a/src/Requests/ReachedFloorSignal.java
+++ b/src/Events/ReachedFloorEvent.java
@@ -1,13 +1,13 @@
-package Requests;
+package Events;
import commandSystem.Direction;
-public class ReachedFloorSignal implements Request{
+public class ReachedFloorEvent implements Event{
private final int currentFloor;
private final Direction currentDirection;
- public ReachedFloorSignal(int currentFloor, Direction currentDirection) {
+ public ReachedFloorEvent(int currentFloor, Direction currentDirection) {
this.currentFloor = currentFloor;
this.currentDirection = currentDirection;
}
@@ -28,8 +28,8 @@ public class ReachedFloorSignal implements Request{
}
@Override
- public RequestType getType() {
- return RequestType.REACHEDFLOORSIGNAL;
+ public EventType getType() {
+ return EventType.REACHEDFLOORSIGNAL;
}
@Override
diff --git a/src/Requests/Request.java b/src/Requests/Request.java
deleted file mode 100644
index 5f33ab9..0000000
--- a/src/Requests/Request.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package Requests;
-
-import commandSystem.Direction;
-
-public interface Request {
-
- /**
- *
- * @return the direction of the request, unconcerned extending classes return
- * NONE.
- */
- public Direction getRequestedDirection();
-
- /**
- *
- * @return the wished floor, unconcerned extending classes return -1.
- */
- public int getRequestedFloor();
-
- /**
- *
- * @return the floor it was called from, unconcerned extending classes return
- * -1.
- */
- public int getIncomingCallFloor();
-
- /**
- *
- * @return the RequestType of the request.
- */
- public RequestType getType();
-
- /**
- *
- * @return the floor the elevator just reached, unconcerned extending classes
- * return -1.
- */
- public int getCurrentFloor();
-
- /**
- *
- * @return the direction of the elevator, when a reachedFloorSignal is sent.
- * Unconcerned extending classes return NONE
- */
- public Direction getCurrentDirection();
-}
diff --git a/src/commandSystem/EventQueue.java b/src/commandSystem/EventQueue.java
index 8242982..ff2a712 100644
--- a/src/commandSystem/EventQueue.java
+++ b/src/commandSystem/EventQueue.java
@@ -3,16 +3,13 @@ package commandSystem;
import java.util.ArrayList;
import java.util.Collections;
-import Requests.Request;
-import simulation.Elevator;
-
-// emergencyStop -> clear the queue
+import Events.Event;
public class EventQueue {
private ArrayList upQueue = new ArrayList<>();
private ArrayList downQueue = new ArrayList<>();
private boolean emergencyState;
-
+
private int currentFloor;
private Direction direction;
@@ -26,7 +23,8 @@ public class EventQueue {
}
/**
- * Add new floor to queue queue and sort it to keep floors order
+ * Adds a new floor to upQueue or downQueue then sorts the
+ * elements.
*
* @param queue ArrayList
* @param floor int - the floor we add to queue
@@ -42,122 +40,121 @@ public class EventQueue {
/**
* Compute a request into the {@link #EventQueue} depending on the elevator
- * status
+ * status.
*
- * @param request - the request to compute
+ * @param event - the request to compute
*/
- public void computeRequest(Request request) {
+ public void computeEvent(Event event) {
- switch (request.getType()) {
- case CALLFROMFLOOR:
- if (emergencyState)
- return;
- switch (request.getRequestedDirection()) {
- case UP:
- if (!upQueue.contains(request.getIncomingCallFloor()))
- appSort(upQueue, request.getIncomingCallFloor(), false);
- break;
- case DOWN:
- if (!downQueue.contains(request.getIncomingCallFloor()))
- appSort(downQueue, request.getIncomingCallFloor(), true);
- break;
- default:
- break;
- }
+ switch (event.getType()) {
+ case CALLFROMFLOOR:
+ if (emergencyState)
+ return;
+ switch (event.getRequestedDirection()) {
+ case UP:
+ if (!upQueue.contains(event.getIncomingCallFloor()))
+ appSort(upQueue, event.getIncomingCallFloor(), false);
break;
- case CALLFROMELEVATOR:
- if (emergencyState)
- return;
- if (request.getRequestedFloor() > currentFloor && !upQueue.contains(request.getRequestedFloor()))
- appSort(upQueue, request.getRequestedFloor(), false);
- else if (request.getRequestedFloor() < currentFloor
- && !upQueue.contains(request.getRequestedFloor()))
- appSort(downQueue, request.getRequestedFloor(), true);
+ case DOWN:
+ if (!downQueue.contains(event.getIncomingCallFloor()))
+ appSort(downQueue, event.getIncomingCallFloor(), true);
break;
- case EMERGENCYSTOP:
- if (emergencyState)
- return;
- emergencyState = true;
- clearQueue();
- break;
- case CANCELEMERGENCYSTOP:
- emergencyState = false;
- break;
- case REACHEDFLOORSIGNAL:
- if (emergencyState)
- return;
- currentFloor = request.getCurrentFloor();
- direction = request.getCurrentDirection();
default:
break;
+ }
+ break;
+ case CALLFROMELEVATOR:
+ if (emergencyState)
+ return;
+ if (event.getRequestedFloor() > currentFloor && !upQueue.contains(event.getRequestedFloor()))
+ appSort(upQueue, event.getRequestedFloor(), false);
+ else if (event.getRequestedFloor() < currentFloor && !upQueue.contains(event.getRequestedFloor()))
+ appSort(downQueue, event.getRequestedFloor(), true);
+ break;
+ case EMERGENCYSTOP:
+ if (emergencyState)
+ return;
+ emergencyState = true;
+ clearQueue();
+ break;
+ case CANCELEMERGENCYSTOP:
+ emergencyState = false;
+ break;
+ case REACHEDFLOORSIGNAL:
+ if (emergencyState)
+ return;
+ currentFloor = event.getCurrentFloor();
+ direction = event.getCurrentDirection();
+ break;
+ default:
+ break;
}
}
/**
- * removes one instruction from the queue - call when the elevator reaches
- * targeted floor
+ * Removes one instruction from the queue - has to be called when the elevator
+ * reaches targeted floor.
*
- * @param reachedFloor
- * @param direction of elevators
+ * @param floor the reached floor
+ * @param direction the direction of the elevator
*/
- public void removeInstruction(int reachedFloor, Direction direction) {
+ public void removeInstruction(int floor, Direction direction) {
switch (direction) {
- case UP:
- if (upQueue.contains(reachedFloor))
- upQueue.remove(upQueue.indexOf(reachedFloor));
- else // we go up to the top of descending queue
- downQueue.remove(downQueue.indexOf(reachedFloor));
- break;
- case DOWN:
- if (downQueue.contains(reachedFloor))
- downQueue.remove(downQueue.indexOf(reachedFloor));
- else // we go down to the bottom of ascending queue
- upQueue.remove(upQueue.indexOf(reachedFloor));
- break;
- default:
- break;
+ case UP:
+ if (upQueue.contains(floor))
+ upQueue.remove(upQueue.indexOf(floor));
+ else // we go up to the top of descending queue
+ downQueue.remove(downQueue.indexOf(floor));
+ break;
+ case DOWN:
+ if (downQueue.contains(floor))
+ downQueue.remove(downQueue.indexOf(floor));
+ else // we go down to the bottom of ascending queue
+ upQueue.remove(upQueue.indexOf(floor));
+ break;
+ default:
+ break;
}
}
/**
* Returns the next floor the elevator has to go to
*
- * @return next floor if it exists else -1
+ * @return the next floor if it exists, else -1
*/
public int getNextInstruction() {
- //System.out.println("" + upQueue + '\n' + downQueue);
int nextFloor = -1;
switch (direction) {
- // get first element of upQueue that is ABOVE the elevator's current floor
- case UP:
- for (int i = 0; i < upQueue.size() && nextFloor < 0; i++) {
- if (upQueue.get(i) >= currentFloor) {
- nextFloor = upQueue.get(i);
- }
+ // get the first element of upQueue that is ABOVE the elevator's current floor
+ case UP:
+ for (int i = 0; i < upQueue.size() && nextFloor < 0; i++) {
+ if (upQueue.get(i) >= currentFloor) {
+ nextFloor = upQueue.get(i);
}
- // change direction if every floor in upQueue is UNDER the elevator's current
- // floor
- if (nextFloor < 0 && downQueue.size() > 0) {
- nextFloor = downQueue.get(0);
- }
- break;
-
- // get first element of downQueue that is UNDER the elevator's current floor
- case DOWN:
- for (int i = 0; i < downQueue.size() && nextFloor < 0; i++) {
- if (downQueue.get(i) <= currentFloor) {
- nextFloor = downQueue.get(i);
- }
- }
- // change direction if every floor in downQueue is ABOVE the elevator's current
- // floor
- if (nextFloor < 0 && upQueue.size() > 0) {
- nextFloor = upQueue.get(0);
- }
- break;
- default:
- break;
}
+ // change direction if every floor in upQueue is UNDER the elevator's current
+ // floor
+ if (nextFloor < 0 && downQueue.size() > 0) {
+ nextFloor = downQueue.get(0);
+ }
+ break;
+
+ // get the first element of downQueue that is UNDER the elevator's current floor
+ case DOWN:
+ for (int i = 0; i < downQueue.size() && nextFloor < 0; i++) {
+ if (downQueue.get(i) <= currentFloor) {
+ nextFloor = downQueue.get(i);
+ }
+ }
+ // change direction if every floor in downQueue is ABOVE the elevator's current
+ // floor
+ if (nextFloor < 0 && upQueue.size() > 0) {
+ nextFloor = upQueue.get(0);
+ }
+ break;
+ default:
+ break;
+ }
return nextFloor;
}
diff --git a/src/commandSystem/Test.java b/src/commandSystem/Test.java
index c5e10af..49702d8 100644
--- a/src/commandSystem/Test.java
+++ b/src/commandSystem/Test.java
@@ -1,8 +1,7 @@
package commandSystem;
-import Requests.CallFromElevatorRequest;
-import Requests.CallFromFloorRequest;
-import simulation.Elevator;
+import Events.CallFromElevatorEvent;
+import Events.CallFromFloorEvent;
public class Test {
@@ -38,15 +37,15 @@ public class Test {
queue = new EventQueue();
iter();
iter();
- queue.computeRequest(new CallFromFloorRequest(2, Direction.DOWN));
+ queue.computeEvent(new CallFromFloorEvent(2, Direction.DOWN));
iter();
System.out.println("someone calls from floor 2 to go down");
iter();
- queue.computeRequest(new CallFromFloorRequest(1, Direction.UP));
+ queue.computeEvent(new CallFromFloorEvent(1, Direction.UP));
System.out.println("someone calls from floor 1 to go up");
iter();
- queue.computeRequest(new CallFromElevatorRequest(5));
+ queue.computeEvent(new CallFromElevatorEvent(5));
System.out.println("the guy who entered calls for floor 5");
iter();
diff --git a/src/simulation/Simulation.java b/src/simulation/Simulation.java
index cbbec24..a84d68f 100644
--- a/src/simulation/Simulation.java
+++ b/src/simulation/Simulation.java
@@ -1,9 +1,8 @@
package simulation;
-import Requests.CallFromElevatorRequest;
-import Requests.CallFromFloorRequest;
-
import commandSystem.EventQueue;
+import Events.CallFromElevatorEvent;
+import Events.CallFromFloorEvent;
import commandSystem.Direction;
import commandSystem.ElevatorListener;
import simulation.Elevator;