submap()

Mapから、指定したプリフィックスのキーと値を取得する。
プロパティファイルでマッピングの定義をするときとかに使う。


private static Map submap(Map map, String prefix, boolean hasPrefix) {
Map submap = new HashMap();
Iterator keys = map.keySet().iterator();

while (keys.hasNext()) {
String key = (String) keys.next();

if (key.startsWith(prefix)) {
String value = map.get(key);

if (!hasPrefix) {
key = key.substring(prefix.length());
}

submap.put(key, value);
}
}

return submap;
}