Search in sources :

Example 66 with Stack

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);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) Stack(java.util.Stack) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 67 with Stack

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;
}
Also used : Point(org.eclipse.swt.graphics.Point) Stack(java.util.Stack)

Example 68 with Stack

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());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Example 69 with Stack

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());
}
Also used : EmptyStackException(java.util.EmptyStackException) AbstractExpression(org.voltdb.expressions.AbstractExpression) ExpressionType(org.voltdb.types.ExpressionType) Stack(java.util.Stack)

Example 70 with Stack

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");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) Stack(java.util.Stack)

Aggregations

Stack (java.util.Stack)300 HashSet (java.util.HashSet)50 ArrayList (java.util.ArrayList)47 File (java.io.File)29 IOException (java.io.IOException)23 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 View (android.view.View)18 Set (java.util.Set)17 List (java.util.List)16 LinkedList (java.util.LinkedList)15 ViewGroup (android.view.ViewGroup)14 Map (java.util.Map)13 Iterator (java.util.Iterator)12 Document (org.w3c.dom.Document)11 ImageView (android.widget.ImageView)10 Matcher (java.util.regex.Matcher)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9