Biblioteca Java - Rev 32
Subversion Repositories:
(root)/Courses and labs samples/ISP/Exemple_ISP_Cluj_2015/ElevatorCurs/src/elevatorcurs/model/Controller.java @ 36
package elevatorcurs.model;
import java.util.LinkedList;
import java.util.NoSuchElementException;
/**
*
* @author Mihai Hulea mihai.hulea@aut.utcluj.ro
*/
public class Controller {
private Elevator e;
private Job currentJob;
private LinkedList<Job> jobs;
public Controller(Elevator e) {
this.e = e;
jobs = new LinkedList<>();
}
public void step(){
if(currentJob!=null){
//...
int targetPosition = currentJob.getDestinationFloor() * 10;
if(targetPosition < e.getPosition()){
e.setCurrentDir(Direction.DOWN);
}else if(targetPosition > e.getPosition()){
e.setCurrentDir(Direction.UP);
}else{
e.setCurrentDir(Direction.HOLD);
System.out.println("ARRIVED!");
currentJob = null;
}
}else{
//...
currentJob = jobs.poll();
/*try{
currentJob = jobs.removeFirst();
}catch(NoSuchElementException e){
}*/
}
}
public void addJob(Job j){
jobs.addLast(j);
}
}