import java.util.Map; import java.util.List; import java.util.HashMap; import java.util.ArrayList; import java.util.Collections; /** * @author Tomas Sedmik * @version 08 12 2009 */ public class DiaryImpl implements Diary { private Map> diary = new HashMap>(); /** * Adds new event to the diary. * @param Event event to added to the diary. * @throws IllegalArgumentException: * */ public void addEvent(Event event) throws IllegalArgumentException { if (event == null) { IllegalArgumentException exc = new IllegalArgumentException("argument is null"); throw exc; } if (event.getTime() == null) { IllegalArgumentException exc = new IllegalArgumentException("argument has time null"); throw exc; } if (event.getTime().isEmpty()) { IllegalArgumentException exc = new IllegalArgumentException("argument has invalid time value"); throw exc; } if (!diary.containsKey(event.getTime())) { List eventList = new ArrayList(); eventList.add(event); diary.put(event.getTime(), eventList); } else { List eventList = diary.get(event.getTime()); eventList.add(event); } } /** * Returns all event with time sets to the date. * @param date present date * @return unmodifiable list with events those * have time set to the date */ public List getEvents(String date) { if ((date != null) && (!date.isEmpty())) { return Collections.unmodifiableList(diary.get(date)); } return null; } /** * Returns all events in the diary. * @return list of all events */ public List getAllEvents() { List allEvents = new ArrayList(); for (String key : diary.keySet()) { allEvents.addAll(diary.get(key)); } return allEvents; } }