QuerySuggestionSource implements SuggestionSource<SearchSuggestion> { protected int countParenthesisBalance(String rest) { boolean inSingleQuote = false; boolean inDoubleQuote = false; final char[] chars = rest.toCharArray(); int balance = 0; for (char c : chars) { if (c == '"' && !inSingleQuote) { inDoubleQuote = !inDoubleQuote; } else if (c == '\'' && !inDoubleQuote) { inSingleQuote = !inSingleQuote; } else if (c == '(' && !inSingleQuote && !inDoubleQuote) { balance++; } else if (c == ')' && !inSingleQuote && !inDoubleQuote) { balance--; } } return balance; } QuerySuggestionSource(List<SuggestionQuery> history); @Override List<SearchSuggestion> getSuggestions(SuggestionQuery q); String getLastValue(String s); static void main(String[] args);  }
@Test(dataProvider = "balance", enabled = false) public void testCountParenthesisBalance(String s, int expected) { Assert.assertEquals(underTest.countParenthesisBalance(s), expected); }