protected void handleTagEnd( List<BBCodeItem> bbCodeItems, Stack<String> tags, BBCodeToken bbCodeToken) { int size = 0; if (bbCodeToken != null) { String endTag = bbCodeToken.getEndTag(); for (size = tags.size() - 1; size >= 0; size--) { if (endTag.equals(tags.elementAt(size))) { break; } } } if (size >= 0) { for (int i = tags.size() - 1; i >= size; i--) { BBCodeItem bbCodeItem = new BBCodeItem(TYPE_TAG_END, null, tags.elementAt(i)); bbCodeItems.add(bbCodeItem); } tags.setSize(size); } }
/** * Rewind the current state of the tree walk to the state it was in when mark() was called and it * returned marker. Also, wipe out the lookahead which will force reloading a few nodes but it is * better than making a copy of the lookahead buffer upon mark(). */ public void rewind(int marker) { if (markers == null) { return; } TreeWalkState state = (TreeWalkState) markers.get(marker); absoluteNodeIndex = state.absoluteNodeIndex; currentChildIndex = state.currentChildIndex; currentNode = state.currentNode; previousNode = state.previousNode; // drop node and index stacks back to old size nodeStack.setSize(state.nodeStackSize); indexStack.setSize(state.indexStackSize); head = tail = 0; // wack lookahead buffer and then refill for (; tail < state.lookahead.length; tail++) { lookahead[tail] = state.lookahead[tail]; } release(marker); }
private void performOperation(String operatorToken) { if (stack.size() >= 2) { if (operatorToken.equals("+")) { add(); } else if (operatorToken.equals("-")) { subtract(); } else if (operatorToken.equals("*")) { multiply(); } else if (operatorToken.equals("/")) { divide(); } } else { stack.setSize(0); stack.push(String.format("Not enough operands to perform operation [%s]", operatorToken)); } }
public String pushPop(String startValue, String rpnString) { String returnValue = startValue.toString(); stack.setSize(0); if (rpnString.contains("x")) { rpnString = rpnString.replace("x", startValue); } else { rpnString = String.format("%s,%s", startValue, rpnString); } if (rpnStringContainsValidElements(rpnString)) { for (String token : rpnString.split(",")) { if (token != "") { pushToken(token); } } if (stack.size() == 1) { returnValue = stack.pop(); try { Double resultValue = Double.parseDouble(returnValue); String format = "%f"; if (decimals != null) { format = String.format(Locale.ENGLISH, "%s.%dg", "%", decimals); } returnValue = String.format(format, resultValue); if (returnValue.contains(".")) { returnValue = returnValue.replaceFirst("0+$", ""); returnValue = returnValue.replaceFirst("\\.$", ""); } } catch (NumberFormatException e) { } } else { returnValue = "Error, stack left with multiple values."; } } else { returnValue = String.format("Invalid rpn expression [%s]", rpnString); } return returnValue; }
public void reset() { openElements.setSize(0); valueHandlers.setSize(0); activePatterns.setSize(0); locator = null; }