/** Given an input string, level, and optionally a tag length, find a matching prefix. */ private PrefixMatch findPrefixMatch( String input, TagLengthList tagLength, LevelTypeList level_type) { List<PrefixMatch> match_list = new ArrayList<PrefixMatch>(); PrefixTree<PrefixMatch> tree = prefix_tree_map.get(level_type); assert tree != null; List<PrefixMatch> list = tree.search(input); if (!list.isEmpty()) { if (tagLength == null) match_list.addAll(list); else { for (PrefixMatch match : list) if (match.getScheme().getTagLength() == tagLength) match_list.add(match); } } if (match_list.isEmpty()) throw new TDTException("No schemes or levels matched the input value"); else if (match_list.size() > 1) throw new TDTException("More than one scheme/level matched the input value"); else return match_list.get(0); }