public Message updateMessage(Message message) { if (message.getId() <= 0) { return null; } messages.put(message.getId(), message); return message; }
public List<Message> getAllMessagesForYear(int year) { List<Message> messagesForYear = new ArrayList<>(); Calendar cal = Calendar.getInstance(); for (Message message : messages.values()) { cal.setTime(message.getCreated()); if (cal.get(Calendar.YEAR) == year) { messagesForYear.add(message); } } return messagesForYear; }
public Message addMessage(Message message) { message.setId(messages.size() + 1); messages.put(message.getId(), message); return message; }