Esempio n. 1
0
  public String getDaysString() {
    StringBuilder daysStringBuilder = new StringBuilder("[");

    for (Day day : days) {
      daysStringBuilder.append(day.toString()).append(",");
    }

    String result =
        daysStringBuilder.length() > 0
            ? daysStringBuilder.substring(0, daysStringBuilder.length() - 1)
            : "";

    return result.length() > 0 ? result + "]" : "";
  }
Esempio n. 2
0
  /**
   * Constructor to build Section from JSON
   *
   * @param jsonObject JSON Object must have the following keys present:
   *     <ul>
   *       <li>"CourseNumber" - integer, unique to all classes, UTA Class ID Number
   *       <li>"Section" - integer, unique within course, UTA Section Number
   *       <li>"Room" - String, room the section will meet in
   *       <li>"Instructor" - String, list of instructors for section
   *       <li>"MeetingTime" - String, time the lecture period will begin to time the lecture period
   *           will end
   *       <li>"MeetingDays" - String, JSON Array of days class will be meeting
   *       <li>"Status" - String, current class status (OPEN, CLOSED, WAIT_LIST)
   *           <ul/>
   * @param sourceCourse Course this section belongs to. Used primarily to recreate JSON.
   * @throws JSONException
   */
  Section(JSONObject jsonObject, Course sourceCourse) throws JSONException {

    this.setSectionID(Integer.parseInt(jsonObject.getString("CourseNumber")));

    this.setSectionNumber(Integer.parseInt(jsonObject.getString("Section")));

    this.setRoom(jsonObject.getString("Room"));

    this.setInstructors(jsonObject.getString("Instructor"));

    String times[] = jsonObject.getString("MeetingTime").split("-");
    Log.i("New Start Time", times[0]);
    if (times[0].equalsIgnoreCase("UNKNOWN/TBA")) {
      startTime = (new TimeShort(0, 0));
      endTime = (new TimeShort(0, 0));
    } else if (!times[0].equalsIgnoreCase("TBA")) {
      startTime = (new TimeShort(times[0]));
      endTime = (new TimeShort(times[1]));
    } else {
      startTime = (new TimeShort(0, 0));
      endTime = (new TimeShort(0, 0));
    }

    JSONArray jsonDaysArray = jsonObject.getJSONArray("MeetingDays");
    Log.i("New Section Days List", jsonDaysArray.toString());

    days = new ArrayList<>(jsonDaysArray.length());

    for (int index = jsonDaysArray.length(); index != 0; index--) {
      Day temp = Day.valueOf(jsonDaysArray.getString(index - 1));
      days.add(temp);
      Log.i("New Section Day", days.get(days.size() - 1).toString());
    }
    Collections.reverse(days);
    Log.i("New Section #of Days", ((Integer) days.size()).toString());
    for (Day day : days) {
      Log.i("Day in Section", day.toString());
    }
    Log.i("New Section Days", days.toString());

    this.setStatus(
        ClassStatus.valueOf(jsonObject.getString("Status").toUpperCase().replace(" ", "_")));

    this.setSourceCourse(sourceCourse);
  }
Esempio n. 3
0
 /**
  * Outputs a JSONObject matching the JSONObject used in {@link #Section(JSONObject, Course)}.
  *
  * @return JSONObject
  */
 public JSONObject toJSON() {
   JSONObject section = new JSONObject();
   JSONArray days = new JSONArray();
   for (Day day : this.days) {
     days.put(day.toString());
   }
   Log.i("Section toJSON DAYS", days.toString());
   try {
     section.put("MeetingTime", getTimeString());
     section.put("CourseNumber", getSectionID());
     section.put("Section", getSectionNumber());
     section.put("Instructor", getInstructors());
     section.put("Room", getRoom());
     section.put("Status", getStatus());
     section.put("MeetingDays", days);
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return section;
 }