mercredi 2 mai 2018

ArrayList always removes Objects even if If-Statement isn't met

I'm trying to build a method that checks wether a room is already booked at a certain time and if it is, it's supposed to tell the user that the room is already booked. The problem is that the method ALWAYS removes a room that has a booking, even if the room is free at the selected time. So if I book the room from 2pm to 3pm and then try to book it from 4pm to 5pm it still removes the room from my available rooms. Somehow my if statement seems to be always true even though it shouldn't be.

ArrayList<Room> availabeRooms = new ArrayList<Room>(); 
    for(Room r : rc.getRoomContainer()){
        availableRooms.add(r);
    }   
    for (Booking bk : this.bookings) {
                            if (!dateB.before(bk.getBeginning()) && !dateE.before(bk.getBeginning())
                                    || !dateB.after(bk.getEnd()) && !dateE.after(bk.getEnd())) {
                                for (Room r : rc.getRoomContainer()) {
                                    if (bk.getRoom().equals(r)) {
                                        availableRooms.remove(r);
                                    }
                                }

                            }
                        }

Aucun commentaire:

Enregistrer un commentaire