Biblioteca Java - Blame information for rev 32
Subversion Repositories:
(root)/Courses and labs samples/ISP/Exemple_ISP_Cluj_2015/ElevatorCurs/src/elevatorcurs/model/Controller.java
Rev | Author | Line No. | Line |
---|---|---|---|
32 | mihai | 1 | |
2 | package elevatorcurs.model; | ||
3 | import java.util.LinkedList; | ||
4 | import java.util.NoSuchElementException; | ||
5 | /** | ||
6 | * | ||
7 | * @author Mihai Hulea mihai.hulea@aut.utcluj.ro | ||
8 | */ | ||
9 | public class Controller { | ||
10 | private Elevator e; | ||
11 | private Job currentJob; | ||
12 | private LinkedList<Job> jobs; | ||
13 | |||
14 | public Controller(Elevator e) { | ||
15 | this.e = e; | ||
16 | jobs = new LinkedList<>(); | ||
17 | } | ||
18 | |||
19 | public void step(){ | ||
20 | if(currentJob!=null){ | ||
21 | //... | ||
22 | int targetPosition = currentJob.getDestinationFloor() * 10; | ||
23 | if(targetPosition < e.getPosition()){ | ||
24 | e.setCurrentDir(Direction.DOWN); | ||
25 | }else if(targetPosition > e.getPosition()){ | ||
26 | e.setCurrentDir(Direction.UP); | ||
27 | }else{ | ||
28 | e.setCurrentDir(Direction.HOLD); | ||
29 | System.out.println("ARRIVED!"); | ||
30 | currentJob = null; | ||
31 | } | ||
32 | }else{ | ||
33 | //... | ||
34 | currentJob = jobs.poll(); | ||
35 | /*try{ | ||
36 | currentJob = jobs.removeFirst(); | ||
37 | }catch(NoSuchElementException e){ | ||
38 | |||
39 | }*/ | ||
40 | } | ||
41 | } | ||
42 | |||
43 | public void addJob(Job j){ | ||
44 | jobs.addLast(j); | ||
45 | } | ||
46 | |||
47 | } |