mirror of
https://github.com/zach-sb/COMP2240-Assignment1.git
synced 2024-07-02 12:04:00 +10:00
149 lines
2.8 KiB
Java
149 lines
2.8 KiB
Java
public class Process {
|
|
|
|
private String id;
|
|
private int arrive;
|
|
private int execSize;
|
|
private int tickets;
|
|
|
|
//Post Run details
|
|
private int turnAroundTime = -1;
|
|
private int waitTime = -1;
|
|
private int startTime = -1;
|
|
private int endTime= -1;
|
|
|
|
private int remainingTime;
|
|
|
|
|
|
//Constructors
|
|
public Process(){
|
|
}
|
|
|
|
public Process(String idInput, int arriveInput, int execSizeInput, int ticketsInput) {
|
|
id = idInput;
|
|
arrive = arriveInput;
|
|
execSize = execSizeInput;
|
|
tickets = ticketsInput;
|
|
remainingTime = execSizeInput;
|
|
}
|
|
|
|
//Setters
|
|
public void setId(String idInput){
|
|
id = idInput;
|
|
}
|
|
public void setArrive(int arriveInput){
|
|
arrive = arriveInput;
|
|
}
|
|
public void setSize(int execSizeInput){
|
|
execSize = execSizeInput;
|
|
remainingTime = execSizeInput;
|
|
}
|
|
public void setTickets(int ticketsInput){
|
|
tickets = ticketsInput;
|
|
}
|
|
|
|
/**
|
|
* Saves the time that the process first started running
|
|
* Only saves if there isn't already a valid time stored
|
|
* (ie, startTime == -1)
|
|
* @param timeInput
|
|
*/
|
|
public void saveStartTime(int timeInput)
|
|
{
|
|
if(startTime == -1)
|
|
{
|
|
startTime=timeInput;
|
|
}
|
|
}
|
|
public void saveEndTime(int timeInput)
|
|
{
|
|
endTime=timeInput;
|
|
}
|
|
|
|
public void saveTurnTime(){
|
|
turnAroundTime = endTime-arrive;
|
|
}
|
|
|
|
public void saveWaitTime(){
|
|
waitTime = startTime - arrive;
|
|
}
|
|
|
|
|
|
//Getters
|
|
public String getId(){
|
|
return id;
|
|
}
|
|
public int getArrive(){
|
|
return arrive;
|
|
}
|
|
public int getExecSize(){
|
|
return execSize;
|
|
}
|
|
public int getTickets(){
|
|
return tickets;
|
|
}
|
|
public int getTurnTime(){
|
|
return turnAroundTime;
|
|
}
|
|
public int getWaitTime(){
|
|
return waitTime;
|
|
}
|
|
public int getStartTime()
|
|
{
|
|
return startTime;
|
|
}
|
|
public int getEndTime()
|
|
{
|
|
return endTime;
|
|
}
|
|
public int getRemainingTime()
|
|
{
|
|
return remainingTime;
|
|
}
|
|
|
|
|
|
//Functions
|
|
public void runForOneTick(boolean isRunning)
|
|
{
|
|
if(isRunning)
|
|
{
|
|
remainingTime--;
|
|
}
|
|
else
|
|
{
|
|
wait(1);
|
|
}
|
|
}
|
|
|
|
public void wait(int time)
|
|
{
|
|
if(waitTime==-1)
|
|
{
|
|
waitTime=time;
|
|
}
|
|
else
|
|
{
|
|
waitTime+= time;
|
|
}
|
|
}
|
|
|
|
public boolean isDone()
|
|
{
|
|
if (remainingTime <= 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void reset()
|
|
{
|
|
turnAroundTime = -1;
|
|
waitTime = -1;
|
|
remainingTime = execSize;
|
|
startTime = -1;
|
|
endTime = -1;
|
|
}
|
|
} |