/** * Process prereq keys wrapped in []. If the key is wrapped in [], the prereq will be negated to * check that the prereq is not passed, and the number of required matches is increased by the * number of negated tests. Can handle nested prereqs. * * @param prereq The prereq to be negated. */ private void negateCampaignChoice(Prerequisite prereq) { int modified = 0; for (Prerequisite p : prereq.getPrerequisites()) { if (p.getKind() == null) // PREMULT { negateCampaignChoice(p); } else { String preKey = p.getKey(); if (preKey.startsWith("[") && preKey.endsWith("]")) { preKey = preKey.substring(1, preKey.length() - 1); p.setKey(preKey); p.setOperator(p.getOperator().invert()); ++modified; } } } if (modified > 0) { String oper = prereq.getOperand(); try { oper = Integer.toString(Integer.parseInt(oper) + modified); } catch (NumberFormatException nfe) { oper = "(" + oper + ")+" + Integer.toString(modified); } prereq.setOperand(oper); } }