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> messageForYear = new ArrayList<>(); Calendar cal = Calendar.getInstance(); for (Message message : messages.values()) { cal.setTime(message.getCreated()); if (cal.get(Calendar.YEAR) == year) { messageForYear.add(message); } } return messageForYear; }
public Message addMessage(Message message) { message.setId(messages.size() + 1); messages.put(message.getId(), message); return message; }