public CourtScheduleInfo(String filepath) { this.filepath = filepath; this.badConferenceDays = new HashMap<String, List<Integer>>(); this.primaryDays = new HashMap<String, List<Integer>>(); this.secondaryDays = new HashMap<String, List<Integer>>(); this.holidays = new ArrayList<LocalDate>(); DateConstraint.setInfo(this); Match.setInfo(this); }
public DateConstraint createStandardSchedule(String[] description) { DateConstraint standardSchedule = new DateConstraint(); Team noTeam = null; ArrayList<DateConstraint> components = new ArrayList<DateConstraint>(); for (String request : description) { request = request.trim().toLowerCase(); for (int i = 1; i < LONG_DAYS.length; i++) { String longDay = LONG_DAYS[i]; DateConstraint nextComponent = null; if (request.contains(longDay) && request.contains(":")) { // special constraint: [day] before/after [time] // restrict if both on this day AND at this time-- so take the intersection DateConstraint day = parseDateConstraints(longDay, noTeam, new DateConstraint()); DateConstraint time = parseDateConstraints(cleanRequest(request, longDay), noTeam, new DateConstraint()); nextComponent = DateConstraint.getIntersection(day, time); components.add(nextComponent); } } } for (int i = 0; i < components.size(); i += 2) { // this means the description NEEDS to be paired-- the two constraints describing a day need // to be adjacent DateConstraint c1 = components.get(i); DateConstraint c2 = components.get(i + 1); DateConstraint c = DateConstraint.getIntersection(c1, c2); // and then OR all the components together standardSchedule = new DateConstraint(standardSchedule, c); } // wipe holidays for (LocalDate holiday : holidays) { int holidayIndex = standardSchedule.findDate(holiday); standardSchedule.blockDate(holidayIndex); } return standardSchedule; }
public int configure() { raw_lines = slurpConfigFile(this.filepath); if (raw_lines.size() == 0) { error( true, "Could not read anything from the configuration file." + EOL + "Expected the configuration file to be found at: " + FileSystems.getDefault().getPath(filepath).toAbsolutePath()); } String[] scheduleDescription = new String[0]; for (String line : raw_lines) { if (line.startsWith(";", 0) || line.trim().length() == 0) { // this line is a comment or empty line continue; } String[] lineComponents = line.split("="); if (lineComponents.length < 2) { System.out.println("could not interpret line: " + line); continue; } String key = lineComponents[0].trim(); String value = lineComponents[1].trim(); if (key.equals("conference_start")) { this.conferenceStartDate = parseDateString(value); } else if (key.equals("conference_end")) { this.conferenceEndDate = parseDateString(value); } else if (key.equals("court_count")) { this.numberOfCourts = Integer.parseInt(value); } else if (key.equals("timeslots_count")) { this.numberOfTimeSlotsPerDay = Integer.parseInt(value); } else if (key.equals("timeslot_duration_minutes")) { this.timeslotDurationInMinutes = Integer.parseInt(value); } else if (key.equals("timeslots_start")) { this.timeslotMidnightOffsetInMinutes = timeStringToMinutes(value); } else if (key.startsWith("conference")) { this.parseConferenceDays(value); } else if (key.startsWith("holiday")) { if (!value.contains("-")) { // one date holidays.add(LocalDate.parse(value, DateConstraint.dateFormat)); } else { // date range LocalDate start = LocalDate.parse(value.substring(0, value.indexOf("-")), DateConstraint.dateFormat); LocalDate end = LocalDate.parse(value.substring(value.indexOf("-") + 1), DateConstraint.dateFormat); LocalDate next = start; while (next.isBefore(end)) { holidays.add(next); next = next.plusDays(1); } holidays.add(end); } } else if (key.startsWith("schedule_description")) { scheduleDescription = value.split(", "); } else if (key.startsWith("input_file")) { inputFileLocation = value; } else if (key.startsWith("output_folder")) { outputFolderLocation = value; } } DateConstraint.setStandardDates(this.createStandardSchedule(scheduleDescription)); return 0; }