Example usage for java.util Calendar WEDNESDAY

List of usage examples for java.util Calendar WEDNESDAY

Introduction

In this page you can find the example usage for java.util Calendar WEDNESDAY.

Prototype

int WEDNESDAY

To view the source code for java.util Calendar WEDNESDAY.

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Wednesday.

Usage

From source file:org.unitime.timetable.solver.TimetableDatabaseLoader.java

public void loadRoomAvailability(RoomAvailabilityInterface availability, Date[] startEnd) {
    iProgress.setPhase("Loading room availability...", iRooms.size());
    int firstDOY = iSession.getDayOfYear(1, iSession.getPatternStartMonth());
    int lastDOY = iSession.getDayOfYear(0, iSession.getPatternEndMonth() + 1);
    int size = lastDOY - firstDOY;
    Calendar c = Calendar.getInstance(Locale.US);
    Formats.Format<Date> df = Formats.getDateFormat(Formats.Pattern.DATE_PATTERN);
    int sessionYear = iSession.getSessionStartYear();
    for (Enumeration e = iRooms.elements(); e.hasMoreElements();) {
        RoomConstraint room = (RoomConstraint) e.nextElement();
        iProgress.incProgress();/*  www.  j av  a 2s .  c  o  m*/
        if (!room.getConstraint())
            continue;
        Collection<TimeBlock> times = getRoomAvailability(availability, room, startEnd[0], startEnd[1]);
        if (times == null)
            continue;
        for (TimeBlock time : times) {
            iProgress.debug(room.getName() + " not available due to " + time);
            int dayCode = 0;
            c.setTime(time.getStartTime());
            int m = c.get(Calendar.MONTH);
            int d = c.get(Calendar.DAY_OF_MONTH);
            if (c.get(Calendar.YEAR) < sessionYear)
                m -= (12 * (sessionYear - c.get(Calendar.YEAR)));
            if (c.get(Calendar.YEAR) > sessionYear)
                m += (12 * (c.get(Calendar.YEAR) - sessionYear));
            BitSet weekCode = new BitSet(size);
            int offset = iSession.getDayOfYear(d, m) - firstDOY;
            if (offset < 0 || offset >= size)
                continue;
            weekCode.set(offset);
            switch (c.get(Calendar.DAY_OF_WEEK)) {
            case Calendar.MONDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_MON];
                break;
            case Calendar.TUESDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_TUE];
                break;
            case Calendar.WEDNESDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_WED];
                break;
            case Calendar.THURSDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_THU];
                break;
            case Calendar.FRIDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_FRI];
                break;
            case Calendar.SATURDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_SAT];
                break;
            case Calendar.SUNDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_SUN];
                break;
            }
            int startSlot = (c.get(Calendar.HOUR_OF_DAY) * 60 + c.get(Calendar.MINUTE)
                    - Constants.FIRST_SLOT_TIME_MIN) / Constants.SLOT_LENGTH_MIN;
            c.setTime(time.getEndTime());
            int endSlot = (c.get(Calendar.HOUR_OF_DAY) * 60 + c.get(Calendar.MINUTE)
                    - Constants.FIRST_SLOT_TIME_MIN) / Constants.SLOT_LENGTH_MIN;
            if (endSlot == 0 && c.get(Calendar.DAY_OF_MONTH) != d)
                endSlot = 288; // next day midnight
            int length = endSlot - startSlot;
            if (length <= 0)
                continue;
            TimeLocation timeLocation = new TimeLocation(dayCode, startSlot, length, 0, 0, null,
                    df.format(time.getStartTime()), weekCode, 0);
            List<TimeLocation> timeLocations = new ArrayList<TimeLocation>(1);
            timeLocations.add(timeLocation);
            RoomLocation roomLocation = new RoomLocation(room.getResourceId(), room.getName(),
                    room.getBuildingId(), 0, room.getCapacity(), room.getPosX(), room.getPosY(),
                    room.getIgnoreTooFar(), room);
            List<RoomLocation> roomLocations = new ArrayList<RoomLocation>(1);
            roomLocations.add(roomLocation);
            Lecture lecture = new Lecture(new Long(--iFakeLectureId), null, null, time.getEventName(),
                    timeLocations, roomLocations, 1, new Placement(null, timeLocation, roomLocations), 0, 0,
                    1.0);
            lecture.setNote(time.getEventType());
            Placement p = (Placement) lecture.getInitialAssignment();
            lecture.setBestAssignment(p, 0);
            lecture.setCommitted(true);
            room.setNotAvailable(p);
            getModel().addVariable(p.variable());
        }
    }
}

From source file:org.unitime.timetable.solver.TimetableDatabaseLoader.java

public void loadInstructorAvailability(RoomAvailabilityInterface availability, Date[] startEnd) {
    iProgress.setPhase("Loading instructor availability...", getModel().getInstructorConstraints().size());
    int firstDOY = iSession.getDayOfYear(1, iSession.getPatternStartMonth());
    int lastDOY = iSession.getDayOfYear(0, iSession.getPatternEndMonth() + 1);
    int size = lastDOY - firstDOY;
    Calendar c = Calendar.getInstance(Locale.US);
    Formats.Format<Date> df = Formats.getDateFormat(Formats.Pattern.DATE_PATTERN);
    int sessionYear = iSession.getSessionStartYear();
    for (InstructorConstraint instructor : getModel().getInstructorConstraints()) {
        iProgress.incProgress();//w  w w  . j  a  va 2s .c  o m
        Collection<TimeBlock> times = getInstructorAvailability(availability, instructor, startEnd[0],
                startEnd[1]);
        if (times == null)
            continue;
        for (TimeBlock time : times) {
            iProgress.debug(instructor.getName() + " not available due to " + time);
            int dayCode = 0;
            c.setTime(time.getStartTime());
            int m = c.get(Calendar.MONTH);
            int d = c.get(Calendar.DAY_OF_MONTH);
            if (c.get(Calendar.YEAR) < sessionYear)
                m -= (12 * (sessionYear - c.get(Calendar.YEAR)));
            if (c.get(Calendar.YEAR) > sessionYear)
                m += (12 * (c.get(Calendar.YEAR) - sessionYear));
            BitSet weekCode = new BitSet(size);
            int offset = iSession.getDayOfYear(d, m) - firstDOY;
            if (offset < 0 || offset >= size)
                continue;
            weekCode.set(offset);
            switch (c.get(Calendar.DAY_OF_WEEK)) {
            case Calendar.MONDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_MON];
                break;
            case Calendar.TUESDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_TUE];
                break;
            case Calendar.WEDNESDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_WED];
                break;
            case Calendar.THURSDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_THU];
                break;
            case Calendar.FRIDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_FRI];
                break;
            case Calendar.SATURDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_SAT];
                break;
            case Calendar.SUNDAY:
                dayCode = Constants.DAY_CODES[Constants.DAY_SUN];
                break;
            }
            int startSlot = (c.get(Calendar.HOUR_OF_DAY) * 60 + c.get(Calendar.MINUTE)
                    - Constants.FIRST_SLOT_TIME_MIN) / Constants.SLOT_LENGTH_MIN;
            c.setTime(time.getEndTime());
            int endSlot = (c.get(Calendar.HOUR_OF_DAY) * 60 + c.get(Calendar.MINUTE)
                    - Constants.FIRST_SLOT_TIME_MIN) / Constants.SLOT_LENGTH_MIN;
            if (endSlot == 0 && c.get(Calendar.DAY_OF_MONTH) != d)
                endSlot = 288; // next day midnight
            int length = endSlot - startSlot;
            if (length <= 0)
                continue;
            TimeLocation timeLocation = new TimeLocation(dayCode, startSlot, length, 0, 0, null,
                    df.format(time.getStartTime()), weekCode, 0);
            List<TimeLocation> timeLocations = new ArrayList<TimeLocation>(1);
            timeLocations.add(timeLocation);
            Lecture lecture = new Lecture(new Long(--iFakeLectureId), null, null, time.getEventName(),
                    timeLocations, new ArrayList<RoomLocation>(), 0,
                    new Placement(null, timeLocation, (RoomLocation) null), 0, 0, 1.0);
            lecture.setNote(time.getEventType());
            Placement p = (Placement) lecture.getInitialAssignment();
            lecture.setBestAssignment(p, 0);
            lecture.setCommitted(true);
            instructor.setNotAvailable(p);
            getModel().addVariable(p.variable());
        }
    }
}