コード例 #1
0
  /** Method to export data like rooms, capacity and meetings array in json format into a file */
  protected static String exportData(ArrayList<Room> roomList) {

    JSONObject json = new JSONObject();

    for (Room room : roomList) {
      json.put("RoomName", room.getName());
      json.put("Capacity", room.getCapacity());
      JSONArray meetings = new JSONArray();

      for (Meeting m : room.getMeetings()) {
        meetings.add(m.toString());
      }
      json.put("Meetings", meetings);

      // write data to a file
      File fileName = new File("src/File/result.json");
      try (PrintWriter file = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)))) {
        file.write(json.toJSONString());
        file.write("\n");
        file.flush();
        file.close();
      } catch (IOException e) {
        logger.error("Exception in export method:", e);
      }
      logger.info("Data exported successfully");
    }
    return "";
  }
コード例 #2
0
  /**
   * this method is used to check the availability of rooms based on start date and time
   *
   * @param roomList : Contains the details of room
   * @param avDate : contains the start date
   * @return
   */
  protected static String availableRooms(ArrayList<Room> roomList, String avDate) {
    System.out.println("--Available Rooms--");
    for (Room room : roomList) {
      ArrayList<Meeting> sDate = room.getMeetings();
      String listString = "";

      for (Meeting s : sDate) {
        listString += s + "\t";
      }
      String[] spDate = listString.split(";");

      if (spDate[0] == "" || spDate[0] == avDate) {
        System.out.println(room.getName());
      }
    }
    return "";
  }