cdc
This commit is contained in:
commit
9aeb29c895
BIN
Cahier_des_charges.pdf
Normal file
BIN
Cahier_des_charges.pdf
Normal file
Binary file not shown.
1830
diag_classes.uml
1830
diag_classes.uml
File diff suppressed because it is too large
Load Diff
@ -4,10 +4,10 @@ import commandSystem.Direction;
|
|||||||
|
|
||||||
public class CallFromElevatorEvent implements Event {
|
public class CallFromElevatorEvent implements Event {
|
||||||
|
|
||||||
private final int wantedFloor;
|
private final int requestedFloor;
|
||||||
|
|
||||||
public CallFromElevatorEvent(int wantedFloor) {
|
public CallFromElevatorEvent(int requestedFloor) {
|
||||||
this.wantedFloor = wantedFloor;
|
this.requestedFloor = requestedFloor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -17,7 +17,7 @@ public class CallFromElevatorEvent implements Event {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRequestedFloor() {
|
public int getRequestedFloor() {
|
||||||
return wantedFloor;
|
return requestedFloor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,7 +12,7 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
private boolean emergencyState;
|
private boolean emergencyState;
|
||||||
|
|
||||||
private int currentFloor;
|
private int currentFloor;
|
||||||
private Direction direction;
|
private Direction currentDirection;
|
||||||
|
|
||||||
public BasicInstructionQueue() {
|
public BasicInstructionQueue() {
|
||||||
|
|
||||||
@ -20,22 +20,7 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
downQueue = new ArrayList<Integer>();
|
downQueue = new ArrayList<Integer>();
|
||||||
emergencyState = false;
|
emergencyState = false;
|
||||||
currentFloor = 0;
|
currentFloor = 0;
|
||||||
direction = Direction.NONE;
|
currentDirection = Direction.UP;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new floor to the argument's <b>queue</b> then sorts the elements.
|
|
||||||
*
|
|
||||||
* @param queue the list to be sorted.
|
|
||||||
* @param floor the index of the floor that will be added.
|
|
||||||
* @param reversed if set to true, the queue will be sorted by descending order.
|
|
||||||
*/
|
|
||||||
private void appSort(ArrayList<Integer> queue, int floor, boolean reversed) {
|
|
||||||
queue.add(floor);
|
|
||||||
if (reversed)
|
|
||||||
Collections.sort(queue, Collections.reverseOrder());
|
|
||||||
else
|
|
||||||
Collections.sort(queue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void computeEvent(Event event) {
|
public void computeEvent(Event event) {
|
||||||
@ -79,7 +64,7 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
/*
|
/*
|
||||||
* If the requested floor is under the elevator, adds the instruction to the
|
* If the requested floor is under the elevator, adds the instruction to the
|
||||||
* downQueue then sorts it. if it's above, adds the instruction to the upQueue
|
* downQueue then sorts it. if it's above, adds the instruction to the upQueue
|
||||||
* then sorts it. If it's the same floor, doesn't do anything
|
* then sorts it. If it's the same floor, doesn't do anything.
|
||||||
*/
|
*/
|
||||||
case CALLFROMELEVATOR:
|
case CALLFROMELEVATOR:
|
||||||
if (event.getRequestedFloor() > currentFloor && !upQueue.contains(event.getRequestedFloor()))
|
if (event.getRequestedFloor() > currentFloor && !upQueue.contains(event.getRequestedFloor()))
|
||||||
@ -94,7 +79,7 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
*/
|
*/
|
||||||
case EMERGENCYSTOP:
|
case EMERGENCYSTOP:
|
||||||
emergencyState = true;
|
emergencyState = true;
|
||||||
clearQueue();
|
clearQueues();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -109,7 +94,8 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
*/
|
*/
|
||||||
case REACHEDFLOORSIGNAL:
|
case REACHEDFLOORSIGNAL:
|
||||||
currentFloor = event.getCurrentFloor();
|
currentFloor = event.getCurrentFloor();
|
||||||
direction = event.getCurrentDirection();
|
currentDirection = event.getCurrentDirection();
|
||||||
|
if (currentFloor == getNextInstruction())
|
||||||
removeInstruction(currentFloor);
|
removeInstruction(currentFloor);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -118,32 +104,6 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes one instruction from the queue - has to be called when the elevator
|
|
||||||
* reaches targeted floor.
|
|
||||||
*
|
|
||||||
* @param floor the reached floor
|
|
||||||
* @param direction the direction of the elevator
|
|
||||||
*/
|
|
||||||
private void removeInstruction(int floor) {
|
|
||||||
switch (direction) {
|
|
||||||
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
|
* Returns the next floor the elevator has to go to
|
||||||
*
|
*
|
||||||
@ -151,7 +111,10 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
*/
|
*/
|
||||||
public int getNextInstruction() {
|
public int getNextInstruction() {
|
||||||
int nextFloor = -1;
|
int nextFloor = -1;
|
||||||
switch (direction) {
|
|
||||||
|
//System.out.println("" + upQueue + downQueue);
|
||||||
|
|
||||||
|
switch (currentDirection) {
|
||||||
// get the 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++) {
|
||||||
@ -185,7 +148,60 @@ public class BasicInstructionQueue implements InstructionQueue {
|
|||||||
return nextFloor;
|
return nextFloor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearQueue() {
|
/**
|
||||||
|
* Adds a new floor to the argument's <b>queue</b> then sorts the elements.
|
||||||
|
*
|
||||||
|
* @param queue the list to be sorted.
|
||||||
|
* @param floor the index of the floor that will be added.
|
||||||
|
* @param reversed if set to true, the queue will be sorted by descending order.
|
||||||
|
*/
|
||||||
|
private void appSort(ArrayList<Integer> queue, int floor, boolean reversed) {
|
||||||
|
queue.add(floor);
|
||||||
|
if (reversed)
|
||||||
|
Collections.sort(queue, Collections.reverseOrder());
|
||||||
|
else
|
||||||
|
Collections.sort(queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes one instruction from the queue - has to be called when the elevator
|
||||||
|
* reaches targeted floor.
|
||||||
|
*
|
||||||
|
* @param floor the reached floor.
|
||||||
|
* @param currentDirection the direction of the elevator.
|
||||||
|
*/
|
||||||
|
private void removeInstruction(int floor) {
|
||||||
|
switch (currentDirection) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Elevator is headed upwards.
|
||||||
|
*/
|
||||||
|
case UP:
|
||||||
|
if (upQueue.contains(floor))
|
||||||
|
upQueue.remove(upQueue.indexOf(floor));
|
||||||
|
else
|
||||||
|
downQueue.remove(downQueue.indexOf(floor));
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Elevator is headed downwards.
|
||||||
|
*/
|
||||||
|
case DOWN:
|
||||||
|
if (downQueue.contains(floor))
|
||||||
|
downQueue.remove(downQueue.indexOf(floor));
|
||||||
|
else
|
||||||
|
upQueue.remove(upQueue.indexOf(floor));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears both queues.
|
||||||
|
*/
|
||||||
|
private void clearQueues() {
|
||||||
downQueue.removeAll(downQueue);
|
downQueue.removeAll(downQueue);
|
||||||
upQueue.removeAll(upQueue);
|
upQueue.removeAll(upQueue);
|
||||||
}
|
}
|
||||||
|
@ -5,4 +5,6 @@ public interface ElevatorListener {
|
|||||||
public void elevatorCall(int floor);
|
public void elevatorCall(int floor);
|
||||||
public void floorCall(int floor, Direction direction);
|
public void floorCall(int floor, Direction direction);
|
||||||
public void floorChange(Direction direction);
|
public void floorChange(Direction direction);
|
||||||
|
public void emergency();
|
||||||
|
public void cancelEmergency();
|
||||||
}
|
}
|
||||||
|
@ -7,21 +7,24 @@ import Events.ReachedFloorEvent;
|
|||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
private static boolean running = false;
|
private static boolean running = false;
|
||||||
private static BasicInstructionQueue queue;
|
private static InstructionQueue queue;
|
||||||
|
|
||||||
private static Direction currentDirection;
|
private static Direction currentDirection = Direction.UP;
|
||||||
private static int currentFloor;
|
private static int currentFloor = 0;
|
||||||
|
|
||||||
public static void iter() {
|
public static void iter() {
|
||||||
int nextDestination = queue.getNextInstruction();
|
int nextDestination = queue.getNextInstruction();
|
||||||
|
|
||||||
if (!running) {
|
if (!running) {
|
||||||
// would be -1 if the queue doesn't have any next instruction
|
// would be -1 if the queue doesn't have any next instruction
|
||||||
|
|
||||||
|
//System.out.println("next dest : " + nextDestination);
|
||||||
if (nextDestination != -1) {
|
if (nextDestination != -1) {
|
||||||
running = true;
|
running = true;
|
||||||
currentDirection = currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
currentDirection = currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//System.out.println("not running");
|
||||||
// if we just reached a new floor
|
// if we just reached a new floor
|
||||||
if (currentFloor == nextDestination) {
|
if (currentFloor == nextDestination) {
|
||||||
queue.computeEvent(new ReachedFloorEvent(currentFloor, currentDirection));
|
queue.computeEvent(new ReachedFloorEvent(currentFloor, currentDirection));
|
||||||
@ -32,16 +35,14 @@ public class Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("elevator floor " + currentFloor + " direction " +
|
System.out.println("elevator floor " + currentFloor + " direction " +
|
||||||
(currentDirection == Direction.UP? "up" : "down") + " running: " + running);
|
(currentDirection) + " running: " + running);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//TODO envoyer les notifs de changements d'étages
|
|
||||||
queue = new BasicInstructionQueue();
|
queue = new BasicInstructionQueue();
|
||||||
iter();
|
iter();
|
||||||
iter();
|
iter();
|
||||||
queue.computeEvent(new CallFromFloorEvent(2, Direction.DOWN));
|
queue.computeEvent(new CallFromFloorEvent(2, Direction.DOWN));
|
||||||
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.computeEvent(new CallFromFloorEvent(1, Direction.UP));
|
queue.computeEvent(new CallFromFloorEvent(1, Direction.UP));
|
||||||
|
@ -26,7 +26,8 @@ public class ElevatorApplication implements ActionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
canvas.setElevatorY((canvas.getElevatorY() + 1) % canvas.getHeight());
|
elevator.update();
|
||||||
|
canvas.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAndShowGUI() {
|
private void createAndShowGUI() {
|
||||||
@ -42,11 +43,13 @@ public class ElevatorApplication implements ActionListener {
|
|||||||
canvas.setAlignmentY(Component.TOP_ALIGNMENT);
|
canvas.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||||
pane.add(canvas);
|
pane.add(canvas);
|
||||||
|
|
||||||
|
pane.add(Box.createRigidArea(new Dimension(40, 0)));
|
||||||
|
|
||||||
FloorPanels fp = new FloorPanels(5, simulation);
|
FloorPanels fp = new FloorPanels(5, simulation);
|
||||||
fp.setAlignmentY(Component.TOP_ALIGNMENT);
|
fp.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||||
pane.add(fp);
|
pane.add(fp);
|
||||||
|
|
||||||
pane.add(Box.createRigidArea(new Dimension(20, 0)));
|
pane.add(Box.createRigidArea(new Dimension(40, 0)));
|
||||||
|
|
||||||
ElevatorPanel elevatorPanel = new ElevatorPanel(5, simulation);
|
ElevatorPanel elevatorPanel = new ElevatorPanel(5, simulation);
|
||||||
elevatorPanel.setAlignmentY(Component.TOP_ALIGNMENT);
|
elevatorPanel.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||||
|
@ -11,7 +11,6 @@ class ElevatorCanvas extends JPanel {
|
|||||||
private final static int HEIGHT = 50;
|
private final static int HEIGHT = 50;
|
||||||
private final static Dimension DIMENSIONS = new Dimension(WIDTH, 200);
|
private final static Dimension DIMENSIONS = new Dimension(WIDTH, 200);
|
||||||
|
|
||||||
private int y = 0;
|
|
||||||
private Elevator elevator;
|
private Elevator elevator;
|
||||||
|
|
||||||
public ElevatorCanvas(Elevator elevator) {
|
public ElevatorCanvas(Elevator elevator) {
|
||||||
@ -46,15 +45,7 @@ class ElevatorCanvas extends JPanel {
|
|||||||
else {
|
else {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
}
|
}
|
||||||
g.fillRect(0, y, WIDTH, HEIGHT);
|
g.fillRect(0, 200 - (int) Math.floor(elevator.getHeight() * 200) - HEIGHT, WIDTH, HEIGHT);
|
||||||
}
|
Toolkit.getDefaultToolkit().sync();
|
||||||
|
|
||||||
public void setElevatorY(int y) {
|
|
||||||
this.y = y;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getElevatorY() {
|
|
||||||
return y;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
import commandSystem.ElevatorListener;
|
import commandSystem.ElevatorListener;
|
||||||
@ -9,6 +10,7 @@ import commandSystem.ElevatorListener;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class ElevatorPanel extends JPanel {
|
class ElevatorPanel extends JPanel {
|
||||||
private JButton emergencyStop = new JButton("Emergency stop.");
|
private JButton emergencyStop = new JButton("Emergency stop.");
|
||||||
|
private JButton cancelEmergencyStop = new JButton("Cancel emergency stop.");
|
||||||
private JButton[] buttons;
|
private JButton[] buttons;
|
||||||
|
|
||||||
public ElevatorPanel(int nbFloors, ElevatorListener l) {
|
public ElevatorPanel(int nbFloors, ElevatorListener l) {
|
||||||
@ -25,11 +27,20 @@ class ElevatorPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(buttons[i]);
|
this.add(buttons[i]);
|
||||||
|
this.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||||
}
|
}
|
||||||
|
emergencyStop.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
l.emergency();
|
||||||
|
}
|
||||||
|
});
|
||||||
add(emergencyStop);
|
add(emergencyStop);
|
||||||
|
this.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||||
|
cancelEmergencyStop.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
l.cancelEmergency();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
public void addEmergencyStopListener(ActionListener l) {
|
add(cancelEmergencyStop);
|
||||||
emergencyStop.addActionListener(l);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ class FloorPanels extends JPanel {
|
|||||||
floors[i] = new JPanel();
|
floors[i] = new JPanel();
|
||||||
floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS));
|
floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS));
|
||||||
floors[i].add(new JLabel("" + i));
|
floors[i].add(new JLabel("" + i));
|
||||||
|
floors[i].add(Box.createRigidArea(new Dimension(5, 0)));
|
||||||
if (i < nbFloors - 1) {
|
if (i < nbFloors - 1) {
|
||||||
final int j = i;
|
final int j = i;
|
||||||
JButton upButton = new JButton("↑");
|
JButton upButton = new JButton("↑");
|
||||||
@ -31,6 +32,7 @@ class FloorPanels extends JPanel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
floors[i].add(upButton);
|
floors[i].add(upButton);
|
||||||
|
floors[i].add(Box.createRigidArea(new Dimension(5, 0)));
|
||||||
}
|
}
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
final int j = i;
|
final int j = i;
|
||||||
@ -43,6 +45,7 @@ class FloorPanels extends JPanel {
|
|||||||
floors[i].add(downButton);
|
floors[i].add(downButton);
|
||||||
}
|
}
|
||||||
this.add(floors[i]);
|
this.add(floors[i]);
|
||||||
|
this.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ public class Elevator {
|
|||||||
height = (double) currentFloor / nbFloors;
|
height = (double) currentFloor / nbFloors;
|
||||||
floorHeight = 1. / nbFloors;
|
floorHeight = 1. / nbFloors;
|
||||||
step = floorHeight / PRECISION;
|
step = floorHeight / PRECISION;
|
||||||
|
System.out.println("step: " + step + ", floorHeight: " + floorHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActionListener(ElevatorListener listener) {
|
public void setActionListener(ElevatorListener listener) {
|
||||||
@ -41,7 +42,7 @@ public class Elevator {
|
|||||||
direction = Direction.DOWN;
|
direction = Direction.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopElevator() {
|
public void stop() {
|
||||||
direction = Direction.NONE;
|
direction = Direction.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ public class Elevator {
|
|||||||
|
|
||||||
/* Passed a floor, invoke the listener. */
|
/* Passed a floor, invoke the listener. */
|
||||||
if (Math.floor(height / floorHeight) < prevFloor && listener != null) {
|
if (Math.floor(height / floorHeight) < prevFloor && listener != null) {
|
||||||
listener.floorChange(Direction.UP);
|
listener.floorChange(Direction.DOWN);
|
||||||
}
|
}
|
||||||
// /* Go halfway below. */
|
// /* Go halfway below. */
|
||||||
// if (!betweenFloors) currentFloor--;
|
// if (!betweenFloors) currentFloor--;
|
||||||
@ -89,8 +90,8 @@ public class Elevator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Passed a floor, invoke the listener. */
|
/* Passed a floor, invoke the listener. */
|
||||||
if (Math.floor(height / floorHeight) < prevFloor && listener != null) {
|
if (Math.floor(height / floorHeight) > prevFloor && listener != null) {
|
||||||
listener.floorChange(Direction.DOWN);
|
listener.floorChange(Direction.UP);
|
||||||
}
|
}
|
||||||
// /* Go halfway above. */
|
// /* Go halfway above. */
|
||||||
// if (betweenFloors) currentFloor++;
|
// if (betweenFloors) currentFloor++;
|
||||||
|
@ -6,12 +6,13 @@ import Events.CallFromFloorEvent;
|
|||||||
import commandSystem.Direction;
|
import commandSystem.Direction;
|
||||||
import commandSystem.ElevatorListener;
|
import commandSystem.ElevatorListener;
|
||||||
import simulation.Elevator;
|
import simulation.Elevator;
|
||||||
|
import Events.*;
|
||||||
|
|
||||||
|
|
||||||
public class Simulation implements ElevatorListener {
|
public class Simulation implements ElevatorListener {
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
private int currentFloor = 0;
|
private int currentFloor = 0;
|
||||||
private BasicInstructionQueue queue;
|
private BasicInstructionQueue queue = new BasicInstructionQueue();
|
||||||
private Elevator elevator;
|
private Elevator elevator;
|
||||||
|
|
||||||
public Simulation(Elevator elevator) {
|
public Simulation(Elevator elevator) {
|
||||||
@ -19,15 +20,20 @@ public class Simulation implements ElevatorListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void elevatorCall(int floor) {
|
public void elevatorCall(int floor) {
|
||||||
System.out.println("elevator call " + floor);
|
System.out.println("Call from elevator: " + floor);
|
||||||
|
queue.computeEvent(new CallFromElevatorEvent(floor));
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void floorCall(int floor, Direction direction) {
|
public void floorCall(int floor, Direction direction) {
|
||||||
System.out.println("floor call " + floor + " " + direction);
|
System.out.println("Call from floor: " + floor + " going " + direction);
|
||||||
|
queue.computeEvent(new CallFromFloorEvent(floor, direction));
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void floorChange(Direction d) {
|
public void floorChange(Direction direction) {
|
||||||
switch (d) {
|
System.out.println("Floor reached: " + direction);
|
||||||
|
switch (direction) {
|
||||||
case UP:
|
case UP:
|
||||||
currentFloor++;
|
currentFloor++;
|
||||||
break;
|
break;
|
||||||
@ -35,30 +41,32 @@ public class Simulation implements ElevatorListener {
|
|||||||
currentFloor--;
|
currentFloor--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// iter();
|
queue.computeEvent(new ReachedFloorEvent(currentFloor, direction));
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void iter() {
|
public void emergency() {
|
||||||
// int nextDestination = queue.getNextInstruction();
|
System.out.println("Emergency declared.");
|
||||||
// int currentFloor = 0;
|
}
|
||||||
// //System.out.println("next dest = " + nextDestination);
|
|
||||||
// if (!running) {
|
public void cancelEmergency() {
|
||||||
// if (nextDestination > 0) { /* We have a destination to go to. */
|
System.out.println("Emergency cancelled.");
|
||||||
// running = true;
|
}
|
||||||
// elevator.goDown();
|
|
||||||
// }
|
private void update() {
|
||||||
// }
|
final int next = queue.getNextInstruction();
|
||||||
// else {
|
System.out.println("Next instruction: " + next);
|
||||||
// if (elevator.currentFloor == nextDestination) {
|
if (next == -1 || next == currentFloor) {
|
||||||
// queue.removeInstruction(elevator.currentFloor, elevator.direction);
|
System.out.println("Stopping.");
|
||||||
// running = false;
|
elevator.stop();
|
||||||
// }
|
}
|
||||||
// else {
|
else if (next > currentFloor) {
|
||||||
// elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
System.out.println("Going up.");
|
||||||
// elevator.currentFloor += elevator.direction == Direction.UP ? 1 : -1;
|
elevator.goUp();
|
||||||
// }
|
}
|
||||||
// }
|
else if (next < currentFloor) {
|
||||||
// System.out.println("elevator floor " + elevator.currentFloor + " direction " +
|
System.out.println("Going down.");
|
||||||
// (elevator.direction == Direction.UP? "up" : "down") + " running: " + running);
|
elevator.goDown();
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user