Passing an object to the next item in a linked list

I created an array of List treatto show 5 instances of the treatment room, I also created a linked list inTreatmentfor the treatment room to pass 5 objects to the patient queue, however when I skip several objects in linkedList they constantly replace the first element added instead of going to the next available element . I believe the problem is the row inTreatment.add, but I'm not sure how to reference the next available index. All suggestions are more than welcome. Below is my code for creating an array and adding to a inTreatmentlinkedList.

Creating an array of processed rooms

public static void createTreatmentRooms() {
    for (int i = 0; i < treat.length; i++) {
        treat[i] = new TreatmentRoom();
        treat[i].setAvailable(true);
    }
}

Add to treatment procedures

for (int i = 0; i < TreatmentRoom.treat.length; i++) {

        if ((TreatmentRoom.treat[i].isAvailable())
                && (Queue.queue.size() != 0)
                && (Queue.queue.getFirst().getTriage() != Status.NOT_ASSESSED)) {

            // add patient to inTreatment list for future sorting...
            inTreatment.add(queue.getFirst());
            System.out.println("taken to treatment queue");
            // remove patient from front of queue
            for (Patient p : queue) {
                System.out.println(p.getFirstName());
            }
            queue.poll();
            System.out.println("second queue");
            for (Patient p : queue) {
                System.out.println(p.getFirstName());
            }
            System.out.println("removed from queue");

            // if free, add patient to treatment room
            TreatmentRoom.treat[i].setPatient(inTreatment.getFirst());
            System.out.println("sent to treatment room"
                    + TreatmentRoom.treat[i]);

            // System.out.println("patient added" +
            // queue.get(i).getFirstName());
            // set treatment room to unavailable
            TreatmentRoom.treat[i].setAvailable(false);
            System.out.println("treatment room busy");

        } else {
            System.out.println("Treatment room is not available");

        }

    }
}
+4
1

:

queue.remove(i);

i, i ?

.

: poll(), , , , , java.util.Queue.

+1

All Articles