コード例 #1
0
 public void addMessage(Message message) {
   data.add(message);
   Message last = data.get(data.size() - 1);
   if (last.getText().length() > MESSAGE_LENGTH) {
     System.out.println(RED + "WARNING: long message (more than 140 symbols)." + END);
   }
   System.out.println("Successfully added: " + last.getFormattedMessage());
   log("ADD " + last.getId() + " " + last.getAuthor() + " " + last.getText());
   saveMessagesToJsonFile(MESSAGES_EXTERNAL_STORAGE);
 }
コード例 #2
0
 private void searchByAuthor(String author) throws Exception {
   System.out.println("BY AUTHOR: " + author);
   int counter = 0;
   for (Message i : data) {
     if (i.getAuthor().equals(author)) {
       System.out.println(i.getFormattedMessage());
       counter++;
     }
   }
   if (counter == 0) {
     System.out.println("nothing found");
     log("SEARCH by author: " + author + ", nothing found");
   } else {
     log("SEARCH by author: " + author + ", found: " + counter);
   }
 }