private String sort(MemoriCommand command, GoogleSync googleSync) {
    Boolean[] f_values = command.getMemoriField();

    for (int i = 0; i < f_values.length; i++) {
      if (f_values[i] == Boolean.TRUE) {
        if (i == 0) {
          memoriCalendar.sort(MemoriEvent.nameComparator);
        } else if (i == 1) {
          memoriCalendar.sort(MemoriEvent.startDateComparator);
        } else if (i == 2) {
          memoriCalendar.sort(MemoriEvent.endDateComparator);
        } else if (i == 3) {
          memoriCalendar.sort(MemoriEvent.descriptionComparator);
        } else {
          memoriCalendar.sort(MemoriEvent.locationComparator);
        }
      }
    }
    return MESSAGE_SORT;
  }
  private String search(MemoriCommand command, GoogleSync googleSync) {
    String text = command.getName();
    MemoriEvent taskLine;
    MemoriEvent displayText;
    for (int i = 0; i < memoriCalendar.size(); i++) {
      taskLine = memoriCalendar.get(i);
      String name = taskLine.getName();
      String description = taskLine.getDescription();
      String location = taskLine.getLocation();
      if (command.getStart() != null) {
        if (command.getStart() == taskLine.getStart()) {
          displayText = memoriCalendar.get(i);
          searchedList.add(displayText);
        }
      } else {
        if (command.getEnd() != null) {
          if (command.getEnd() == taskLine.getEnd()) {
            displayText = memoriCalendar.get(i);
            searchedList.add(displayText);
          }
        } else {
          if ((name.contains(text)) || (description.contains(text)) || (location.contains(text))) {
            displayText = memoriCalendar.get(i);
            searchedList.add(displayText);
          }
        }
      }
    }

    if (!searchedList.isEmpty()) {
      String paddedNameHeader = padRight(NAME_HEADER, MemoriEvent.NAME_CUT_OFF);
      String paddedStartHeader = padRight(START_HEADER, MemoriEvent.DATE_FORMAT.length());
      String output =
          String.format(
              DISPLAY_FORMAT, INDEX_HEADER, paddedNameHeader, paddedStartHeader, END_HEADER);
      int i = 1;
      for (MemoriEvent e : searchedList) {
        String index = padRight(Integer.toString(i), INDEX_HEADER.length());
        output += index + " " + e.display() + "\n";
        i++;
      }
      return output;
    } else {
      return MESSAGE_INVALID_KEYWORD;
    }
  }
  public String add(MemoriCommand command, GoogleSync googleSync) {
    if (maxIdSet == false) findMaxId();
    maxId++;
    MemoriEvent event =
        new MemoriEvent(
            command.getName(),
            command.getStart(),
            command.getEnd(),
            maxId,
            "google",
            command.getDescription(),
            command.getLocation());

    memoriCalendar.add(event);
    googleSync.executeCommand(event, command);

    return MESSAGE_ADD;
  }
  private String read(MemoriCommand command) {
    MemoriEvent displayText;
    if (memoriCalendar.isEmpty()) {
      return MESSAGE_EMPTYFILE;
    } else {
      int index = command.getIndex();

      if (memoriCalendar.size() < index) {
        return LINE_INDEX_DOES_NOT_EXISTS;
      } else {
        displayText = memoriCalendar.get(index - 1);
        return displayText.read();
      }
    }
  }
  private String delete(MemoriCommand command, GoogleSync googleSync) {
    MemoriEvent event;
    if (memoriCalendar.isEmpty()) {
      return MESSAGE_EMPTYFILE;
    } else {
      int index = command.getIndex();
      // to implement getIndex in MemoriCommand that returns a String

      if (memoriCalendar.size() < index) {
        return LINE_INDEX_DOES_NOT_EXISTS;
      } else {
        event = memoriCalendar.get(index - 1);
        memoriCalendar.remove(index - 1);
        googleSync.executeCommand(event, command);
        return String.format(MESSAGE_DELETE);
      }
    }
  }
 public String execute(MemoriCommand command, GoogleSync googleSync) {
   switch (command.getType()) {
     case ADD:
       return add(command, googleSync);
     case UPDATE:
       return update(command, googleSync);
     case DELETE:
       return delete(command, googleSync);
     case READ:
       return read(command);
     case SORT:
       return sort(command, googleSync);
     case SEARCH:
       return search(command, googleSync);
     default:
       return "invalid";
   }
 }
  private String update(MemoriCommand command, GoogleSync googleSync) {
    MemoriEvent originalEvent;
    if (memoriCalendar.isEmpty()) {
      return MESSAGE_EMPTYFILE;
    } else {
      int index = command.getIndex();

      if (memoriCalendar.size() < index) {
        return LINE_INDEX_DOES_NOT_EXISTS;
      } else {
        originalEvent = memoriCalendar.get(index - 1);
        originalEvent.update(
            command.getName(),
            command.getStart(),
            command.getEnd(),
            command.getDescription(),
            command.getLocation());
        googleSync.executeCommand(originalEvent, command);
        return String.format(MESSAGE_UPDATE, index);
      }
    }
  }