public static Map getPreferencePriorityEvents() { HashMap map = new HashMap(); List h = getPreferenceList(PREFS_HIGHPRIORITY_EVENTS); List m = getPreferenceList(PREFS_MEDIUMPRIORITY_EVENTS); List l = getPreferenceList(PREFS_LOWPRIORITY_EVENTS); // preferences not set, read from sakai.properties if (h == null && m == null && l == null) { h = getDefaultListFromSakaiProperties(PREFS_HIGHPRIORITY_EVENTS); m = getDefaultListFromSakaiProperties(PREFS_MEDIUMPRIORITY_EVENTS); l = getDefaultListFromSakaiProperties(PREFS_LOWPRIORITY_EVENTS); } if (h == null) h = new ArrayList(); if (m == null) m = new ArrayList(); if (l == null) l = new ArrayList(); // make sure all available events are listed // no pass-by-reference in java, must use a work-around... List temp = new ArrayList(); temp.addAll(EventTypes.getEventTypes()); PairList lists = new PairList(h, temp); lists = validateEventList(lists); h = lists.dataList; lists.dataList = m; lists = validateEventList(lists); m = lists.dataList; lists.dataList = l; lists = validateEventList(lists); l = lists.dataList; // add all non-specified events to low priority list l.addAll(lists.tempList); // sort lists // Collections.sort(h); // Collections.sort(m); // Collections.sort(l); map.put(PREFS_HIGHPRIORITY_EVENTS, h); map.put(PREFS_MEDIUMPRIORITY_EVENTS, m); map.put(PREFS_LOWPRIORITY_EVENTS, l); return map; }
/** * Foreach 'list' entry A, remove it from 'temp'. If A doesn't exist in 'temp', remove it from * 'list'. * * @param list A event priority List. * @param temp A List with all events. */ private static PairList validateEventList(PairList lists) { List temp = lists.tempList; List list = lists.dataList; if (list == null) { return lists; } List toRemoveFromList = new ArrayList(); Iterator iL = list.iterator(); while (iL.hasNext()) { Object e = iL.next(); if (temp.contains(e)) temp.remove(e); else toRemoveFromList.add(e); } Iterator iR = toRemoveFromList.iterator(); while (iR.hasNext()) { Object e = iR.next(); list.remove(e); } lists.dataList = list; lists.tempList = temp; return lists; }