+ private static final Character[] openingPars = { '(', '[', '{', '<', 'A',
+ 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
+
+ private static final Character[] closingPars = { ')', ']', '}', '>', 'a',
+ 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
+
+ private static HashSet<Character> openingParsSet = new HashSet<Character>(
+ Arrays.asList(openingPars));
+
+ private static HashSet<Character> closingParsSet = new HashSet<Character>(
+ Arrays.asList(closingPars));
+
+ private static Hashtable<Character, Character> closingToOpening = new Hashtable<Character, Character>()
+ // Initializing final data structure
+ {
+ private static final long serialVersionUID = 1L;
+ {
+ for (int i = 0; i < openingPars.length; i++)
+ {
+ // System.out.println(closingPars[i] + "->" + openingPars[i]);
+ put(closingPars[i], openingPars[i]);
+ }
+ }
+ };
+
+ private static boolean isOpeningParenthesis(char c)
+ {
+ return openingParsSet.contains(c);
+ }
+
+ private static boolean isClosingParenthesis(char c)
+ {
+ return closingParsSet.contains(c);
+ }
+
+ private static char matchingOpeningParenthesis(char closingParenthesis)
+ throws WUSSParseException
+ {
+ if (!isClosingParenthesis(closingParenthesis))
+ {
+ throw new WUSSParseException(
+ MessageManager.formatMessage(
+ "exception.querying_matching_opening_parenthesis_for_non_closing_parenthesis",
+ new String[] { new StringBuffer(closingParenthesis)
+ .toString() }), -1);
+ }
+
+ return closingToOpening.get(closingParenthesis);
+ }
+