@Test(expected = SelectorParseException.class) public void testNestedDollarSignThrowsExceptionWhenNotExpected() { this.selectionConverter.convert(":(foo:($))"); }
public Map<String, Object> convert(String selectorString) throws SelectorParseException { Map<String, Object> converted = new HashMap<String, Object>(); Matcher matcher = SELECTOR_PATTERN.matcher(selectorString); if (matcher.find()) { int groups = matcher.groupCount(); for (int i = 0; i < groups; i++) { String data = matcher.group(i + 1); while (!data.isEmpty()) { int indexOfComma = data.indexOf(","); int indexOfParen = data.indexOf("("); if (indexOfComma == -1 && indexOfParen == -1) { parseKeyAndAddValueToMap(data, converted); data = ""; } else if (indexOfComma == -1) { String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1); addKeyValueToMap(key, convert(value), converted); data = ""; } else if (indexOfParen == -1) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else if (indexOfComma < indexOfParen) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else { int endOfSubMap = getMatchingClosingParenIndex(data, indexOfParen); String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1, endOfSubMap + 1); addKeyValueToMap(key, convert(value), converted); data = data.substring(endOfSubMap + 1); if (data.startsWith(",")) { data = data.substring(1); } } } } } else { throw new SelectorParseException("Invalid selector syntax"); } return converted; }
Selector2MapOfMaps implements SelectionConverter { public Map<String, Object> convert(String selectorString) throws SelectorParseException { Map<String, Object> converted = new HashMap<String, Object>(); Matcher matcher = SELECTOR_PATTERN.matcher(selectorString); if (matcher.find()) { int groups = matcher.groupCount(); for (int i = 0; i < groups; i++) { String data = matcher.group(i + 1); while (!data.isEmpty()) { int indexOfComma = data.indexOf(","); int indexOfParen = data.indexOf("("); if (indexOfComma == -1 && indexOfParen == -1) { parseKeyAndAddValueToMap(data, converted); data = ""; } else if (indexOfComma == -1) { String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1); addKeyValueToMap(key, convert(value), converted); data = ""; } else if (indexOfParen == -1) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else if (indexOfComma < indexOfParen) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else { int endOfSubMap = getMatchingClosingParenIndex(data, indexOfParen); String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1, endOfSubMap + 1); addKeyValueToMap(key, convert(value), converted); data = data.substring(endOfSubMap + 1); if (data.startsWith(",")) { data = data.substring(1); } } } } } else { throw new SelectorParseException("Invalid selector syntax"); } return converted; } }
Selector2MapOfMaps implements SelectionConverter { public Map<String, Object> convert(String selectorString) throws SelectorParseException { Map<String, Object> converted = new HashMap<String, Object>(); Matcher matcher = SELECTOR_PATTERN.matcher(selectorString); if (matcher.find()) { int groups = matcher.groupCount(); for (int i = 0; i < groups; i++) { String data = matcher.group(i + 1); while (!data.isEmpty()) { int indexOfComma = data.indexOf(","); int indexOfParen = data.indexOf("("); if (indexOfComma == -1 && indexOfParen == -1) { parseKeyAndAddValueToMap(data, converted); data = ""; } else if (indexOfComma == -1) { String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1); addKeyValueToMap(key, convert(value), converted); data = ""; } else if (indexOfParen == -1) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else if (indexOfComma < indexOfParen) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else { int endOfSubMap = getMatchingClosingParenIndex(data, indexOfParen); String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1, endOfSubMap + 1); addKeyValueToMap(key, convert(value), converted); data = data.substring(endOfSubMap + 1); if (data.startsWith(",")) { data = data.substring(1); } } } } } else { throw new SelectorParseException("Invalid selector syntax"); } return converted; } Selector2MapOfMaps();  Selector2MapOfMaps(boolean errorOnDollarSign); }
Selector2MapOfMaps implements SelectionConverter { public Map<String, Object> convert(String selectorString) throws SelectorParseException { Map<String, Object> converted = new HashMap<String, Object>(); Matcher matcher = SELECTOR_PATTERN.matcher(selectorString); if (matcher.find()) { int groups = matcher.groupCount(); for (int i = 0; i < groups; i++) { String data = matcher.group(i + 1); while (!data.isEmpty()) { int indexOfComma = data.indexOf(","); int indexOfParen = data.indexOf("("); if (indexOfComma == -1 && indexOfParen == -1) { parseKeyAndAddValueToMap(data, converted); data = ""; } else if (indexOfComma == -1) { String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1); addKeyValueToMap(key, convert(value), converted); data = ""; } else if (indexOfParen == -1) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else if (indexOfComma < indexOfParen) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else { int endOfSubMap = getMatchingClosingParenIndex(data, indexOfParen); String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1, endOfSubMap + 1); addKeyValueToMap(key, convert(value), converted); data = data.substring(endOfSubMap + 1); if (data.startsWith(",")) { data = data.substring(1); } } } } } else { throw new SelectorParseException("Invalid selector syntax"); } return converted; } Selector2MapOfMaps();  Selector2MapOfMaps(boolean errorOnDollarSign); Map<String, Object> convert(String selectorString); }
Selector2MapOfMaps implements SelectionConverter { public Map<String, Object> convert(String selectorString) throws SelectorParseException { Map<String, Object> converted = new HashMap<String, Object>(); Matcher matcher = SELECTOR_PATTERN.matcher(selectorString); if (matcher.find()) { int groups = matcher.groupCount(); for (int i = 0; i < groups; i++) { String data = matcher.group(i + 1); while (!data.isEmpty()) { int indexOfComma = data.indexOf(","); int indexOfParen = data.indexOf("("); if (indexOfComma == -1 && indexOfParen == -1) { parseKeyAndAddValueToMap(data, converted); data = ""; } else if (indexOfComma == -1) { String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1); addKeyValueToMap(key, convert(value), converted); data = ""; } else if (indexOfParen == -1) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else if (indexOfComma < indexOfParen) { String value = data.substring(0, indexOfComma); parseKeyAndAddValueToMap(value, converted); data = data.substring(indexOfComma + 1); } else { int endOfSubMap = getMatchingClosingParenIndex(data, indexOfParen); String key = data.substring(0, indexOfParen - 1); String value = data.substring(indexOfParen - 1, endOfSubMap + 1); addKeyValueToMap(key, convert(value), converted); data = data.substring(endOfSubMap + 1); if (data.startsWith(",")) { data = data.substring(1); } } } } } else { throw new SelectorParseException("Invalid selector syntax"); } return converted; } Selector2MapOfMaps();  Selector2MapOfMaps(boolean errorOnDollarSign); Map<String, Object> convert(String selectorString); static final String SELECTOR_REGEX_STRING; static final Pattern SELECTOR_PATTERN; }