ajout diag de classes vide + refactoring & javadoc de Request (devenu Event)
This commit is contained in:
parent
0b3dc7381c
commit
a2fdc0934e
79
diag_classes.uml
Normal file
79
diag_classes.uml
Normal 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
0
diag_classes.uml~
Normal file
@ -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
|
@ -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
|
@ -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
|
@ -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
|
76
src/Events/Event.java
Normal file
76
src/Events/Event.java
Normal 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();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package Requests;
|
||||
package Events;
|
||||
|
||||
public enum RequestType {
|
||||
public enum EventType {
|
||||
CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP, REACHEDFLOORSIGNAL
|
||||
}
|
@ -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
|
@ -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();
|
||||
}
|
@ -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<Integer> upQueue = new ArrayList<>();
|
||||
private ArrayList<Integer> downQueue = new ArrayList<>();
|
||||
private boolean emergencyState;
|
||||
|
||||
|
||||
private int currentFloor;
|
||||
private Direction direction;
|
||||
|
||||
@ -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 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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user