### Question:
OtherContextPredicate { public String adjustForQuery(){ if (path.matches("^.*other_context\\[.*\\].*")){ Pattern pattern = Pattern.compile("other_context\\[(.*?)\\]"); Matcher matcher = pattern.matcher(path); if (matcher.find()) { path = path.substring(0, matcher.start() + "other_context[".length() - 1) + (matcher.end() == path.length() ? "" : path.substring(matcher.end())); } } return path; } OtherContextPredicate(String path); String adjustForQuery();  }### Answer:
@Test public void testPath(){ String queryPath = "context/other_context[at0001]"; assertEquals("context/other_context", new OtherContextPredicate(queryPath).adjustForQuery()); queryPath = "context/other_context[at0001]/items[at0003]/value/value"; assertEquals("context/other_context/items[at0003]/value/value", new OtherContextPredicate(queryPath).adjustForQuery()); }