package os;

import readinstruction.ReadInstruction;
import scheduler.Scheduler;
import utils.Clock;
import utils.Observer;

import java.util.ArrayList;
import java.util.Queue;

/**
 * Created by Karol on 2017-04-20.
 */
public class OperatingSystemImpl implements OperatingSystem, Observer {
    private Clock systemClock;
    private Scheduler systemScheduler;
    private Queue<ReadInstruction> readQueue;
    private boolean consoleFlag;
    private ArrayList<ReadInstruction> readResults;

    public OperatingSystemImpl(
            Clock systemClock,
            Scheduler systemScheduler,
            Queue<ReadInstruction> processQueue,
            boolean consoleFlag){
        this.systemClock = systemClock;
        this.systemScheduler = systemScheduler;
        this.readQueue = processQueue;
        this.consoleFlag = consoleFlag;
        this.readResults = new ArrayList<>();
        this.systemClock.addObserver(this);
        this.systemClock.addObserver(systemScheduler);
        this.systemScheduler.setOs(this);
    }

    @Override
    public void run() {
        this.systemClock.start();
    }

    @Override
    public void push(ReadInstruction instruction) {
        this.readResults.add(instruction);
        if (this.consoleFlag)
            System.out.println(this.systemClock.getTime() + "\tfinish process ID: " + instruction.getInstructionId());
    }

    @Override
    public void generateReport() {

    }

    @Override
    public void update(int time) {

    }
}

@@ -1480,21 +1480,721 @@
 int time) %7B%0A
+        this.tick(time);%0A    %7D%0A%0A    private void tick(int time) %7B%0A        boolean listChecked = false;%0A        do %7B%0A            if (!this.readQueue.isEmpty() && this.readQueue.peek().getArrivalTime() == time) %7B%0A                if (this.consoleFlag)%0A                    System.out.println(time + %22%5Ctload process; ID: %22 + this.readQueue.peek().getInstructionId());%0A                this.systemScheduler.push(this.readQueue.remove());%0A            %7D else %7B%0A                listChecked = true;%0A            %7D%0A        %7D while (!listChecked && this.readQueue.size() %3E 0);%0A        if (this.readQueue.isEmpty() &&%0A                this.systemScheduler.isEmpty()) %7B%0A            this.systemClock.stop();%0A%0A        %7D
 %0A    %7D%0A%7D%0A

Implement update method of OperatingSystemImpl