@Override public Object getValueAt(int rowIndex, int columnIndex) { WeeklyEvent we = weeklyEvents.get(rowIndex); Calendar cal; switch (columnIndex) { case 0: cal = we.getStartTime(); String time = cal.get(Calendar.HOUR_OF_DAY) + ":00 - " + we.getEndTime().get(Calendar.HOUR_OF_DAY) + ":00"; return time; case 1: cal = we.getStartTime(); return DateFunctions.getDayOfWeek(cal); case 2: if (we.getCourse() != null) { return we.getCourse().getName(); } else { return ""; } case 3: return we.getRoom().getRoomName(); default: return ""; } }
public boolean generateWeeklyEventFor(Course c) { List<Room> rooms = findRoomsForCourse(c); Room r = null; if (rooms.size() < 1) { LoggingFunctions.printError( "Could not generate weekly event for course " + c.getId(), "No suitable rooms found"); return false; } Calendar cal = DateFunctions.calculateNextValidStartTime(); cal.add(Calendar.HOUR_OF_DAY, -1); int hours = (int) c.getSemesterHours(); // While there is another valid start time while (DateFunctions.calculateNextValidStartTime(cal, hours)) { // If the course can be done on that start time if (isTimeslotFreeForCourse(c, cal, hours)) { r = getFreeRoomForTimeslot(rooms, cal, hours); // If there is a free room at that time if (r != null) { WeeklyEvent we = new WeeklyEvent(); we.setEvent(cal, hours, c, r); etm.addWeeklyEvent(we); we.saveToDB(); System.out.println(""); System.out.println("Saved new weekly event:"); System.out.println("Course: " + c.getName()); System.out.println( "From: " + cal.get(Calendar.HOUR_OF_DAY) + "" + DateFunctions.getDayOfWeek(cal)); System.out.println( "To: " + cal.get(Calendar.HOUR_OF_DAY) + hours + "" + DateFunctions.getDayOfWeek(cal)); System.out.println("Room: " + r.getRoomName()); System.out.println(""); return true; } } } return false; }
public boolean isTimeslotFreeForRoom(Room r, Calendar time, int hours) { Calendar endTime = (Calendar) time.clone(); endTime.add(Calendar.HOUR_OF_DAY, hours); for (WeeklyEvent we : r.getWeeklyEvents()) { if (DateFunctions.doDateRangesOverlap( time, endTime, we.getStartTime(), we.getEndTime(), true)) { return false; } } return true; }
public boolean isTimeslotFreeForCourse(Course c, Calendar time, int hours) { List<Room> rooms = findRoomsForCourse(c); Calendar end = (Calendar) time.clone(); end.add(Calendar.HOUR_OF_DAY, hours); for (CurriculumSemester cs : c.getCurriculumSemesters()) { for (Course co : cs.getCourses()) { WeeklyEvent we = co.getWeeklyEvent(); if (we != null && DateFunctions.doDateRangesOverlap( time, end, we.getStartTime(), we.getEndTime(), true)) { return false; } } } return true; }