String (final String path, final TreeMap<String, String> after2before) { String current = path; // backwards for (String key : after2before.descendingKeySet()) { if (Url.isAncestor(key, current)) { final String relativePath = Url.getRelative(key, current); current = Url.append(after2before.get(key), relativePath); } } return current; }