public boolean makeReservation( User user, Apartment apartment, Date start, Date end, String comment) { if (end.before(start)) { if (log.isInfoEnabled()) { logReservationRejected(user, apartment, start, end, "Invalid date"); } return false; } if (isAvailable(apartment, start, end)) { if (log.isInfoEnabled()) { SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy"); log.info( Joiner.on("") .join( "Reservation accepted: UserID='", user.getId(), "', apartmentID='", apartment.getId(), "', start='", format.format(start), "', end='", format.format(end), "'")); } Reservation reservation = new Reservation(user, apartment, start, end, comment); SortOfDataBase.reservations.put(reservation.getId(), reservation); return true; } if (log.isInfoEnabled()) { logReservationRejected( user, apartment, start, end, "Apartment is unavailable for this dates"); } return false; }
private boolean intersects(Reservation reservation, Date start, Date end) { return !(start.after(reservation.getEnd()) || end.before(reservation.getStart())); }