/** * 对所有properties的key排序并分组。 * * @param level 分组的级别 * @return 分组列表 */ private List[] getSortedKeys(Map props, int level) { List keys = new ArrayList(props.keySet()); Collections.sort(keys); List groups = new ArrayList(); List group = null; String prefix = null; for (Iterator i = keys.iterator(); i.hasNext(); ) { String key = (String) i.next(); String[] parts = StringUtil.split(key, "."); StringBuffer buffer = new StringBuffer(); for (int j = 0; j < parts.length - 1 && j < level; j++) { if (buffer.length() > 0) { buffer.append('.'); } buffer.append(parts[j]); } String keyPrefix = buffer.toString(); if (!keyPrefix.equals(prefix)) { if (group != null) { groups.add(group); } prefix = keyPrefix; group = new ArrayList(); } group.add(key); } if (group != null && group.size() > 0) { groups.add(group); } return (List[]) groups.toArray(new List[groups.size()]); }