/** * Remove all context items for the specified subject. * * @param subject Prefix whose items are to be removed. */ public void removeSubject(String subject) { String prefix = normalizePrefix(subject); for (String suffix : getSuffixes(prefix).keySet()) { setItem(prefix + suffix, null); } }
/** * Remove all context items for the specified subject. * * @param subject Prefix whose items are to be removed. */ public void removeSubject(String subject) { String prefix = normalizePrefix(subject); for (String suffix : getSuffixes(prefix).keySet()) { setItem(prefix + suffix, null); } }
/** * Returns a map consisting of suffixes of context items that match the specified prefix. * * @param prefix Item name less any suffix. * @param firstOnly If true, only the first match is returned. Otherwise, all matches are * returned. * @return Map of suffixes whose prefix matches the specified value. The value of each map entry * is the value of the original context item. */ private Map<String, String> getSuffixes(String prefix, Boolean firstOnly) { HashMap<String, String> matches = new HashMap<String, String>(); prefix = normalizePrefix(prefix); int i = prefix.length(); for (String itemName : index.keySet()) { if (itemName.startsWith(prefix)) { String suffix = lookupItemName(itemName, false).substring(i); matches.put(suffix, getItem(itemName)); if (firstOnly) { break; } } } return matches; }
/** * Returns a map consisting of suffixes of context items that match the specified prefix. * * @param prefix Item name less any suffix. * @param firstOnly If true, only the first match is returned. Otherwise, all matches are * returned. * @return Map of suffixes whose prefix matches the specified value. The value of each map entry * is the value of the original context item. */ private Map<String, String> getSuffixes(String prefix, Boolean firstOnly) { HashMap<String, String> matches = new HashMap<>(); prefix = normalizePrefix(prefix); int i = prefix.length(); for (String itemName : index.keySet()) { if (itemName.startsWith(prefix)) { String suffix = lookupItemName(itemName, false).substring(i); matches.put(suffix, getItem(itemName)); if (firstOnly) { break; } } } return matches; }