ajout diag de classes vide + refactoring & javadoc de Request (devenu Event)

This commit is contained in:
MathieuPietri 2019-10-15 13:48:47 +02:00
parent 0b3dc7381c
commit a2fdc0934e
13 changed files with 282 additions and 178 deletions

79
diag_classes.uml Normal file
View File

@ -0,0 +1,79 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<uml version="6">
<argo version="6">
<documentation>
<authorname></authorname>
<authoremail></authoremail>
<version>0.34</version>
<description>
</description>
</documentation>
<settings>
<notationlanguage>UML 1.4</notationlanguage>
<showboldnames>false</showboldnames>
<useguillemots>false</useguillemots>
<showassociationnames>true</showassociationnames>
<showvisibility>false</showvisibility>
<showmultiplicity>false</showmultiplicity>
<showinitialvalue>false</showinitialvalue>
<showproperties>false</showproperties>
<showtypes>true</showtypes>
<showstereotypes>false</showstereotypes>
<showsingularmultiplicities>true</showsingularmultiplicities>
<defaultshadowwidth>1</defaultshadowwidth>
<hidebidirectionalarrows>true</hidebidirectionalarrows>
<fontname>Dialog</fontname>
<fontsize>12</fontsize>
<defaultstereotypeview>0</defaultstereotypeview>
<activediagram>Diagramme de classes</activediagram>
</settings>
<searchpath href="PROJECT_DIR" />
<members>
<member type="profile"
name="diag_classes_profile.profile" />
<member type="xmi"
name="diag_classes.xmi" />
<member type="pgml"
name="diag_classes_Diagrammedeclasses.pgml"
diagramclass="org.argouml.uml.diagram.static_structure.ui.UMLClassDiagram"
diagramname="Diagramme de classes" />
<member type="todo"
name="diag_classes.todo" />
</members>
<historyfile name="" />
</argo>
<profile>
<plugin>
UML 1.4
</plugin>
<plugin>
GoodPractices
</plugin>
<plugin>
CodeGeneration
</plugin>
</profile>
<XMI xmi.version = '1.2' xmlns:UML = 'org.omg.xmi.namespace.UML' timestamp = 'Tue Oct 15 13:25:22 CEST 2019'>
<XMI.header> <XMI.documentation>
<XMI.exporter>ArgoUML (using Netbeans XMI Writer version 1.0)</XMI.exporter>
<XMI.exporterVersion>0.34(6) revised on $Date: 2010-01-11 22:20:14 +0100 (Mon, 11 Jan 2010) $ </XMI.exporterVersion>
</XMI.documentation>
<XMI.metamodel xmi.name="UML" xmi.version="1.4"/></XMI.header>
<XMI.content>
<UML:Model xmi.id = '127-0-1-1--36f12a6:16dcf2450da:-8000:0000000000000865'
name = 'untitledModel' isSpecification = 'false' isRoot = 'false' isLeaf = 'false'
isAbstract = 'false'/>
</XMI.content>
</XMI>
<pgml description="org.argouml.uml.diagram.static_structure.ui.UMLClassDiagram|127-0-1-1--36f12a6:16dcf2450da:-8000:0000000000000865"
name="Diagramme de classes"
>
</pgml>
<todo>
<todolist>
</todolist>
<resolvedcritics>
</resolvedcritics>
</todo>
</uml>

0
diag_classes.uml~ Normal file
View File

View File

@ -1,12 +1,12 @@
package Requests; package Events;
import commandSystem.Direction; import commandSystem.Direction;
public class CallFromElevatorRequest implements Request { public class CallFromElevatorEvent implements Event {
private final int wantedFloor; private final int wantedFloor;
public CallFromElevatorRequest(int wantedFloor) { public CallFromElevatorEvent(int wantedFloor) {
this.wantedFloor = wantedFloor; this.wantedFloor = wantedFloor;
} }
@ -26,8 +26,8 @@ public class CallFromElevatorRequest implements Request {
} }
@Override @Override
public RequestType getType() { public EventType getType() {
return RequestType.CALLFROMELEVATOR; return EventType.CALLFROMELEVATOR;
} }
@Override @Override

View File

@ -1,14 +1,14 @@
package Requests; package Events;
import commandSystem.Direction; import commandSystem.Direction;
public class CallFromFloorRequest implements Request { public class CallFromFloorEvent implements Event {
private final int incomingCallFloor; private final int incomingCallFloor;
private final Direction direction; private final Direction direction;
public CallFromFloorRequest(int incomingCallFloor, Direction direction) { public CallFromFloorEvent(int incomingCallFloor, Direction direction) {
this.incomingCallFloor = incomingCallFloor; this.incomingCallFloor = incomingCallFloor;
this.direction = direction; this.direction = direction;
} }
@ -29,8 +29,8 @@ public class CallFromFloorRequest implements Request {
} }
@Override @Override
public RequestType getType() { public EventType getType() {
return RequestType.CALLFROMFLOOR; return EventType.CALLFROMFLOOR;
} }
@Override @Override

View File

@ -1,10 +1,10 @@
package Requests; package Events;
import commandSystem.Direction; import commandSystem.Direction;
public class CancelEmergencyStopRequest implements Request{ public class CancelEmergencyStopEvent implements Event{
public CancelEmergencyStopRequest() { public CancelEmergencyStopEvent() {
} }
@Override @Override
@ -23,8 +23,8 @@ public class CancelEmergencyStopRequest implements Request{
} }
@Override @Override
public RequestType getType() { public EventType getType() {
return RequestType.CANCELEMERGENCYSTOP; return EventType.CANCELEMERGENCYSTOP;
} }
@Override @Override

View File

@ -1,10 +1,10 @@
package Requests; package Events;
import commandSystem.Direction; import commandSystem.Direction;
public class EmergencyStopRequest implements Request { public class EmergencyStopEvent implements Event {
public EmergencyStopRequest() { public EmergencyStopEvent() {
} }
@Override @Override
@ -23,8 +23,8 @@ public class EmergencyStopRequest implements Request {
} }
@Override @Override
public RequestType getType() { public EventType getType() {
return RequestType.EMERGENCYSTOP; return EventType.EMERGENCYSTOP;
} }
@Override @Override

76
src/Events/Event.java Normal file
View File

@ -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();
}

View File

@ -1,5 +1,5 @@
package Requests; package Events;
public enum RequestType { public enum EventType {
CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP, REACHEDFLOORSIGNAL CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP, REACHEDFLOORSIGNAL
} }

View File

@ -1,13 +1,13 @@
package Requests; package Events;
import commandSystem.Direction; import commandSystem.Direction;
public class ReachedFloorSignal implements Request{ public class ReachedFloorEvent implements Event{
private final int currentFloor; private final int currentFloor;
private final Direction currentDirection; private final Direction currentDirection;
public ReachedFloorSignal(int currentFloor, Direction currentDirection) { public ReachedFloorEvent(int currentFloor, Direction currentDirection) {
this.currentFloor = currentFloor; this.currentFloor = currentFloor;
this.currentDirection = currentDirection; this.currentDirection = currentDirection;
} }
@ -28,8 +28,8 @@ public class ReachedFloorSignal implements Request{
} }
@Override @Override
public RequestType getType() { public EventType getType() {
return RequestType.REACHEDFLOORSIGNAL; return EventType.REACHEDFLOORSIGNAL;
} }
@Override @Override

View File

@ -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();
}

View File

@ -3,10 +3,7 @@ package commandSystem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import Requests.Request; import Events.Event;
import simulation.Elevator;
// emergencyStop -> clear the queue
public class EventQueue { public class EventQueue {
private ArrayList<Integer> upQueue = new ArrayList<>(); private ArrayList<Integer> upQueue = new ArrayList<>();
@ -26,7 +23,8 @@ public class EventQueue {
} }
/** /**
* Add new floor to <b>queue</b> queue and sort it to keep floors order * Adds a new floor to <b>upQueue</b> or <b>downQueue</b> then sorts the
* elements.
* *
* @param queue ArrayList<Int> * @param queue ArrayList<Int>
* @param floor int - the floor we add to queue * @param floor int - the floor we add to queue
@ -42,24 +40,24 @@ public class EventQueue {
/** /**
* Compute a request into the {@link #EventQueue} depending on the elevator * 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()) { switch (event.getType()) {
case CALLFROMFLOOR: case CALLFROMFLOOR:
if (emergencyState) if (emergencyState)
return; return;
switch (request.getRequestedDirection()) { switch (event.getRequestedDirection()) {
case UP: case UP:
if (!upQueue.contains(request.getIncomingCallFloor())) if (!upQueue.contains(event.getIncomingCallFloor()))
appSort(upQueue, request.getIncomingCallFloor(), false); appSort(upQueue, event.getIncomingCallFloor(), false);
break; break;
case DOWN: case DOWN:
if (!downQueue.contains(request.getIncomingCallFloor())) if (!downQueue.contains(event.getIncomingCallFloor()))
appSort(downQueue, request.getIncomingCallFloor(), true); appSort(downQueue, event.getIncomingCallFloor(), true);
break; break;
default: default:
break; break;
@ -68,11 +66,10 @@ public class EventQueue {
case CALLFROMELEVATOR: case CALLFROMELEVATOR:
if (emergencyState) if (emergencyState)
return; return;
if (request.getRequestedFloor() > currentFloor && !upQueue.contains(request.getRequestedFloor())) if (event.getRequestedFloor() > currentFloor && !upQueue.contains(event.getRequestedFloor()))
appSort(upQueue, request.getRequestedFloor(), false); appSort(upQueue, event.getRequestedFloor(), false);
else if (request.getRequestedFloor() < currentFloor else if (event.getRequestedFloor() < currentFloor && !upQueue.contains(event.getRequestedFloor()))
&& !upQueue.contains(request.getRequestedFloor())) appSort(downQueue, event.getRequestedFloor(), true);
appSort(downQueue, request.getRequestedFloor(), true);
break; break;
case EMERGENCYSTOP: case EMERGENCYSTOP:
if (emergencyState) if (emergencyState)
@ -86,33 +83,34 @@ public class EventQueue {
case REACHEDFLOORSIGNAL: case REACHEDFLOORSIGNAL:
if (emergencyState) if (emergencyState)
return; return;
currentFloor = request.getCurrentFloor(); currentFloor = event.getCurrentFloor();
direction = request.getCurrentDirection(); direction = event.getCurrentDirection();
break;
default: default:
break; break;
} }
} }
/** /**
* removes one instruction from the queue - call when the elevator reaches * Removes one instruction from the queue - has to be called when the elevator
* targeted floor * reaches targeted floor.
* *
* @param reachedFloor * @param floor the reached floor
* @param direction of elevators * @param direction the direction of the elevator
*/ */
public void removeInstruction(int reachedFloor, Direction direction) { public void removeInstruction(int floor, Direction direction) {
switch (direction) { switch (direction) {
case UP: case UP:
if (upQueue.contains(reachedFloor)) if (upQueue.contains(floor))
upQueue.remove(upQueue.indexOf(reachedFloor)); upQueue.remove(upQueue.indexOf(floor));
else // we go up to the top of descending queue else // we go up to the top of descending queue
downQueue.remove(downQueue.indexOf(reachedFloor)); downQueue.remove(downQueue.indexOf(floor));
break; break;
case DOWN: case DOWN:
if (downQueue.contains(reachedFloor)) if (downQueue.contains(floor))
downQueue.remove(downQueue.indexOf(reachedFloor)); downQueue.remove(downQueue.indexOf(floor));
else // we go down to the bottom of ascending queue else // we go down to the bottom of ascending queue
upQueue.remove(upQueue.indexOf(reachedFloor)); upQueue.remove(upQueue.indexOf(floor));
break; break;
default: default:
break; break;
@ -122,13 +120,12 @@ public class EventQueue {
/** /**
* Returns the next floor the elevator has to go to * 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() { public int getNextInstruction() {
//System.out.println("" + upQueue + '\n' + downQueue);
int nextFloor = -1; int nextFloor = -1;
switch (direction) { switch (direction) {
// get first element of upQueue that is ABOVE the elevator's current floor // get the first element of upQueue that is ABOVE the elevator's current floor
case UP: case UP:
for (int i = 0; i < upQueue.size() && nextFloor < 0; i++) { for (int i = 0; i < upQueue.size() && nextFloor < 0; i++) {
if (upQueue.get(i) >= currentFloor) { if (upQueue.get(i) >= currentFloor) {
@ -142,7 +139,7 @@ public class EventQueue {
} }
break; break;
// get first element of downQueue that is UNDER the elevator's current floor // get the first element of downQueue that is UNDER the elevator's current floor
case DOWN: case DOWN:
for (int i = 0; i < downQueue.size() && nextFloor < 0; i++) { for (int i = 0; i < downQueue.size() && nextFloor < 0; i++) {
if (downQueue.get(i) <= currentFloor) { if (downQueue.get(i) <= currentFloor) {

View File

@ -1,8 +1,7 @@
package commandSystem; package commandSystem;
import Requests.CallFromElevatorRequest; import Events.CallFromElevatorEvent;
import Requests.CallFromFloorRequest; import Events.CallFromFloorEvent;
import simulation.Elevator;
public class Test { public class Test {
@ -38,15 +37,15 @@ public class Test {
queue = new EventQueue(); queue = new EventQueue();
iter(); iter();
iter(); iter();
queue.computeRequest(new CallFromFloorRequest(2, Direction.DOWN)); queue.computeEvent(new CallFromFloorEvent(2, Direction.DOWN));
iter(); iter();
System.out.println("someone calls from floor 2 to go down"); System.out.println("someone calls from floor 2 to go down");
iter(); 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"); System.out.println("someone calls from floor 1 to go up");
iter(); iter();
queue.computeRequest(new CallFromElevatorRequest(5)); queue.computeEvent(new CallFromElevatorEvent(5));
System.out.println("the guy who entered calls for floor 5"); System.out.println("the guy who entered calls for floor 5");
iter(); iter();

View File

@ -1,9 +1,8 @@
package simulation; package simulation;
import Requests.CallFromElevatorRequest;
import Requests.CallFromFloorRequest;
import commandSystem.EventQueue; import commandSystem.EventQueue;
import Events.CallFromElevatorEvent;
import Events.CallFromFloorEvent;
import commandSystem.Direction; import commandSystem.Direction;
import commandSystem.ElevatorListener; import commandSystem.ElevatorListener;
import simulation.Elevator; import simulation.Elevator;