package lift;

import java.util.Arrays;

public class PassengerQueue {
    private int[] waitRecord;

    public PassengerQueue(int nfloors) {
        this.waitRecord = new int[nfloors];
    }

    public void inc(int floor) {
        this.waitRecord[floor]++;
    }

    public void dec(int floor) {
        this.waitRecord[floor]--;
    }

    public int get(int floor) {
        return this.waitRecord[floor];
    }

    public void set(int floor, int value) {
        this.waitRecord[floor] = value;
    }

    public int total() {
        return Arrays.stream(this.waitRecord).sum();
    }

    public boolean isEmpty() {
        return this.total() == 0;
    }

    public int totalBelow(int floor) {
        return Arrays.stream(this.waitRecord).limit(floor).sum();
    }

    public int totalAbove(int floor) {
        return Arrays.stream(this.waitRecord).skip(floor + 1).sum();
    }
}

