Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
2
Indexable
Never
import java.util.ArrayList;
import java.util.Arrays;

public class Monitor {
    private int checks;
    private boolean [] booleans;

    public Monitor(int size, int checks)
    {
        this.checks = checks;
        booleans = new boolean[size];
    }

    public void setBool(int i)
    {
        System.out.println("CHANGE BOOLEAN VALUE");
        booleans[i] = true;
    }

    public int getChecks()
    {

        return checks;
    }

    public boolean isFinished() // a method to check if all threads have finished checking their neighbours
    {
        for (int i = 0; i<booleans.length; i++)
        {
            if (!booleans[i])
                System.out.println("NOT FINISHED");
                return false;
        }
        System.out.println("IS FINISHED!");
        return true;
    }

    public void setBooleansFalse() // setting all the indexes in the array as false
    {
        for (int i=0; i<checks; i++) {
            booleans[i] = false;
        }
        System.out.println("ALL FALSE NOW");
    }

}