### Question:
URITemplate { public static int compareTemplates(URITemplate t1, URITemplate t2) { int l1 = t1.getLiteralChars().length(); int l2 = t2.getLiteralChars().length(); int result = l1 < l2 ? 1 : l1 > l2 ? -1 : 0; if (result == 0) { int g1 = t1.getVariables().size(); int g2 = t2.getVariables().size(); result = g1 < g2 ? 1 : g1 > g2 ? -1 : 0; if (result == 0) { int gCustom1 = t1.getCustomVariables().size(); int gCustom2 = t2.getCustomVariables().size(); result = gCustom1 < gCustom2 ? 1 : gCustom1 > gCustom2 ? -1 : 0; if (result == 0) { result = t1.getPatternValue().compareTo(t2.getPatternValue()); } } } return result; } URITemplate(String theTemplate); String getLiteralChars(); String getValue(); String getPatternValue(); List<String> getVariables(); List<String> getCustomVariables(); boolean match(String uri, MultivaluedMap<String, String> templateVariableToValue); String substitute(List<String> values); String substitute(Map<String, ? extends Object> valuesMap,
                             Set<String> encodePathSlashVars,
                             boolean allowUnresolved); String encodeLiteralCharacters(boolean isQuery); static URITemplate createTemplate(Path path); static URITemplate createTemplate(String pathValue); static URITemplate createExactTemplate(String pathValue); static int compareTemplates(URITemplate t1, URITemplate t2); static final String TEMPLATE_PARAMETERS; static final String LIMITED_REGEX_SUFFIX; static final String FINAL_MATCH_GROUP; }### Answer:
@Test public void testCompareRegExTemplates() { URITemplate t1 = new URITemplate("{entitySetName}{optionalParens: (\\(\\))?}"); URITemplate t2 = new URITemplate("{entitySetName}{id: \\(.+?\\)}"); assertTrue(URITemplate.compareTemplates(t1, t2) < 0); assertTrue(URITemplate.compareTemplates(t2, t1) > 0); assertEquals(0, URITemplate.compareTemplates(t2, t2)); }
@Test public void testCompareNumberOfLiteralCharacters() { URITemplate t1 = new URITemplate("/foo"); URITemplate t2 = new URITemplate("/bar"); URITemplate t3 = new URITemplate("/foo/bar"); assertEquals(0, URITemplate.compareTemplates(t1, t1)); assertTrue(URITemplate.compareTemplates(t1, t3) > 0); assertTrue(URITemplate.compareTemplates(t3, t1) < 0); assertEquals(Integer.signum(URITemplate.compareTemplates(t1, t2)), -Integer.signum(URITemplate.compareTemplates(t2, t1))); }