use of java.util.Stack in project OpenAM by OpenRock.
the class ResourceManager method removeRuleFromResourceTree.
private void removeRuleFromResourceTree(String policyName, String resourceName, String serviceTypeName, ServiceType st) throws PolicyException, SSOException {
if (resourceName == null || resourceName.length() == 0) {
resourceName = EMPTY_RESOURCE_NAME;
}
ServiceConfig resources = getResourcesServiceConfig(false);
if (resources == null) {
return;
}
ServiceConfig leafConfig = null;
try {
leafConfig = resources.getSubConfig(serviceTypeName);
} catch (SMSException e1) {
throw new PolicyException(e1);
}
if (leafConfig == null) {
// no resource node for this service type
return;
}
// else, see if the attribute is there and non-empty
Map existingAttrs = null;
existingAttrs = leafConfig.getAttributes();
if ((existingAttrs == null) || (!existingAttrs.containsKey(RESOURCES_XML))) {
return;
}
// else, need to look into the attribute
int n = existingAttrs.size();
Set existingRes = (Set) existingAttrs.get(RESOURCES_XML);
if (existingRes.isEmpty()) {
return;
}
// else, the attribute really contains something
Object[] retVal = getXMLRootNode(existingRes);
Node rootNode = (Node) retVal[0];
boolean modified = matchAndRemoveReferenceNode(rootNode, resourceName, policyName, st, new Stack());
if (!modified) {
return;
}
if (!rootNode.hasChildNodes()) {
try {
leafConfig.removeAttribute(RESOURCES_XML);
if (n == 1) {
resources.removeSubConfig(serviceTypeName);
}
return;
} catch (SMSException e3) {
throw new PolicyException(e3);
}
}
// finally reset the modified xml content
String modifiedResourcesXml = SMSSchema.nodeToString(rootNode);
Map modifiedAttrs = new HashMap();
Set modifiedSet = new HashSet();
modifiedSet.add(modifiedResourcesXml);
modifiedAttrs.put(RESOURCES_XML, modifiedSet);
try {
leafConfig.setAttributes(modifiedAttrs);
} catch (SMSException e4) {
throw new PolicyException(e4);
}
}
use of java.util.Stack in project tesb-studio-se by Talend.
the class SpringConfigurationStyledText method searchNearestOpenedTag.
private String searchNearestOpenedTag(int lastOffset) {
Stack<String> closeTagStack = new Stack<String>();
boolean hasSingleEndTag = false;
for (int i = lastOffset; i >= 0; i--) {
String currentChar = getText(i, i);
if (isCommentBlock(i)) {
continue;
}
if (">".equals(currentChar)) {
if (hasSingleEndTag) {
return null;
}
if (i > 0 && "/".equals(getText(i - 1, i - 1))) {
hasSingleEndTag = true;
i--;
}
continue;
}
if ("<".equals(currentChar)) {
if (hasSingleEndTag) {
hasSingleEndTag = false;
continue;
}
String nextChar = getText(i + 1, i + 1);
if ("/".equals(nextChar)) {
String searchTagName = searchTagName(i + 2, lastOffset);
if (!searchTagName.isEmpty()) {
closeTagStack.push(searchTagName);
}
continue;
}
String currentTagName = searchTagName(i + 1, lastOffset);
if (closeTagStack.isEmpty()) {
return currentTagName.isEmpty() ? null : currentTagName + ">";
} else {
String pop = closeTagStack.pop();
if (!currentTagName.equals(pop)) {
return null;
}
}
}
}
return null;
}
use of java.util.Stack in project voltdb by VoltDB.
the class PlannerTestCase method assertTopDownTree.
/**
* Assert that a plan node tree contains the expected types of plan nodes
* in the order listed, assuming a top-down left-to-right depth-first
* traversal through the child vector. A null plan node type in the list
* will match any plan node or subtree at the corresponding position.
**/
protected static void assertTopDownTree(AbstractPlanNode start, PlanNodeType... nodeTypes) {
Stack<AbstractPlanNode> stack = new Stack<>();
stack.push(start);
for (PlanNodeType type : nodeTypes) {
// Process each node before its children or later siblings.
AbstractPlanNode parent;
try {
parent = stack.pop();
} catch (EmptyStackException ese) {
fail("No node was found in the tree to match node type " + type);
// This dead code hushes warnings.
return;
}
int childCount = parent.getChildCount();
if (type == null) {
// A null type wildcard matches any child TREE or NODE.
System.out.println("DEBUG: Suggestion -- expect " + parent.getPlanNodeType() + " with " + childCount + " direct children.");
continue;
}
assertEquals(type, parent.getPlanNodeType());
// Iterate from the last child to the first.
while (childCount > 0) {
// Push each child to be processed before its parent's
// or its own later (already pushed) siblings.
stack.push(parent.getChild(--childCount));
}
}
assertTrue("Extra plan node(s) (" + stack.size() + ") were found in the tree with no node type to match", stack.isEmpty());
}
use of java.util.Stack in project voltdb by VoltDB.
the class PlannerTestCase method assertExprTopDownTree.
/**
* Assert that an expression tree contains the expected types of expressions
* in the order listed, assuming a top-down left-to-right depth-first
* traversal through left, right, and args children.
* A null expression type in the list will match any expression
* node or tree at the corresponding position.
**/
protected static void assertExprTopDownTree(AbstractExpression start, ExpressionType... exprTypes) {
assertNotNull(start);
Stack<AbstractExpression> stack = new Stack<>();
stack.push(start);
for (ExpressionType type : exprTypes) {
// Process each node before its children or later siblings.
AbstractExpression parent;
try {
parent = stack.pop();
} catch (EmptyStackException ese) {
fail("No expression was found in the tree to match type " + type);
// This dead code hushes warnings.
return;
}
List<AbstractExpression> args = parent.getArgs();
AbstractExpression rightExpr = parent.getRight();
AbstractExpression leftExpr = parent.getLeft();
int argCount = (args == null) ? 0 : args.size();
int childCount = argCount + (rightExpr == null ? 0 : 1) + (leftExpr == null ? 0 : 1);
if (type == null) {
// A null type wildcard matches any child TREE or NODE.
System.out.println("DEBUG: Suggestion -- expect " + parent.getExpressionType() + " with " + childCount + " direct children.");
continue;
}
assertEquals(type, parent.getExpressionType());
// Iterate from the last child to the first.
while (argCount > 0) {
// Push each child to be processed before its parent's
// or its own later siblings (already pushed).
stack.push(parent.getArgs().get(--argCount));
}
if (rightExpr != null) {
stack.push(rightExpr);
}
if (leftExpr != null) {
stack.push(leftExpr);
}
}
assertTrue("Extra expression node(s) (" + stack.size() + ") were found in the tree with no expression type to match", stack.isEmpty());
}
use of java.util.Stack in project pcgen by PCGen.
the class IfCommandTest method testIf04.
/* Test the case where the condition is a true boolean */
public void testIf04() {
final PostfixMathCommandI c = new IfCommand();
final Stack<Boolean> s = new Stack<>();
s.push(true);
s.push(false);
s.push(true);
runIf(s, c);
final Boolean result = s.pop();
is(result, eq(false), "if (true,false,true) returns false");
}
Aggregations