COMP2240-Assignment1/Process.java
2021-08-27 20:19:05 +10:00

133 lines
2.6 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;
public int hold = -1;
public int unhold = -1;
//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()
{
remainingTime--;
}
public boolean isDone()
{
if (remainingTime <= 0)
{
return true;
}
else
{
return false;
}
}
public void reset()
{
turnAroundTime = -1;
waitTime = -1;
remainingTime = execSize;
startTime = -1;
endTime = -1;
}
}