@Test(expected = SelectorParseException.class) public void testUnbalancedParens2() throws SelectorParseException { Selector2MapOfMaps.getMatchingClosingParenIndex(")", 0); }
protected static int getMatchingClosingParenIndex(String string, int openParenIndex) throws SelectorParseException { int balance = 0; for (int i = openParenIndex; i < string.length(); i++) { switch(string.charAt(i)) { case '(' : balance++; break; case ')' : balance--; if (balance == 0) { return i; } else if (balance < 0) { throw new SelectorParseException("Invalid parentheses"); } } } throw new SelectorParseException("Unbalanced parentheses"); }
Selector2MapOfMaps implements SelectionConverter { protected static int getMatchingClosingParenIndex(String string, int openParenIndex) throws SelectorParseException { int balance = 0; for (int i = openParenIndex; i < string.length(); i++) { switch(string.charAt(i)) { case '(' : balance++; break; case ')' : balance--; if (balance == 0) { return i; } else if (balance < 0) { throw new SelectorParseException("Invalid parentheses"); } } } throw new SelectorParseException("Unbalanced parentheses"); } }
Selector2MapOfMaps implements SelectionConverter { protected static int getMatchingClosingParenIndex(String string, int openParenIndex) throws SelectorParseException { int balance = 0; for (int i = openParenIndex; i < string.length(); i++) { switch(string.charAt(i)) { case '(' : balance++; break; case ')' : balance--; if (balance == 0) { return i; } else if (balance < 0) { throw new SelectorParseException("Invalid parentheses"); } } } throw new SelectorParseException("Unbalanced parentheses"); } Selector2MapOfMaps();  Selector2MapOfMaps(boolean errorOnDollarSign); }
Selector2MapOfMaps implements SelectionConverter { protected static int getMatchingClosingParenIndex(String string, int openParenIndex) throws SelectorParseException { int balance = 0; for (int i = openParenIndex; i < string.length(); i++) { switch(string.charAt(i)) { case '(' : balance++; break; case ')' : balance--; if (balance == 0) { return i; } else if (balance < 0) { throw new SelectorParseException("Invalid parentheses"); } } } throw new SelectorParseException("Unbalanced parentheses"); } Selector2MapOfMaps();  Selector2MapOfMaps(boolean errorOnDollarSign); Map<String, Object> convert(String selectorString); }
Selector2MapOfMaps implements SelectionConverter { protected static int getMatchingClosingParenIndex(String string, int openParenIndex) throws SelectorParseException { int balance = 0; for (int i = openParenIndex; i < string.length(); i++) { switch(string.charAt(i)) { case '(' : balance++; break; case ')' : balance--; if (balance == 0) { return i; } else if (balance < 0) { throw new SelectorParseException("Invalid parentheses"); } } } throw new SelectorParseException("Unbalanced parentheses"); } Selector2MapOfMaps();  Selector2MapOfMaps(boolean errorOnDollarSign); Map<String, Object> convert(String selectorString); static final String SELECTOR_REGEX_STRING; static final Pattern SELECTOR_PATTERN; }