Example usage for java.util Stack pop

List of usage examples for java.util Stack pop

Introduction

In this page you can find the example usage for java.util Stack pop.

Prototype

public synchronized E pop() 

Source Link

Document

Removes the object at the top of this stack and returns that object as the value of this function.

Usage

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitConcatenate(Context ctx, Stack<Expr> stack, BinaryOperator expr) throws TajoException {
    stack.push(expr);/*w  w  w. ja  va 2 s  .c om*/
    EvalNode lhs = visit(ctx, stack, expr.getLeft());
    EvalNode rhs = visit(ctx, stack, expr.getRight());
    stack.pop();

    if (lhs.getValueType().kind() != TajoDataTypes.Type.TEXT) {
        lhs = convertType(ctx, lhs, Text);
    }
    if (rhs.getValueType().kind() != TajoDataTypes.Type.TEXT) {
        rhs = convertType(ctx, rhs, Text);
    }

    return new BinaryEval(EvalType.CONCATENATE, lhs, rhs);
}

From source file:com.opengamma.master.portfolio.ManageablePortfolioNode.java

/**
 * Finds the stack of nodes from the tree below this node by identifier.
 * /*  www.  ja v a  2s. c  o m*/
 * @param stack  the stack of nodes, not null
 * @param nodeObjectId  the node object identifier, not null
 * @return the node with the identifier, null if not found
 */
private Stack<ManageablePortfolioNode> findNodeStackByObjectId0(final Stack<ManageablePortfolioNode> stack,
        final ObjectId nodeObjectId) {
    stack.push(this);
    if (getUniqueId().equalObjectId(nodeObjectId)) {
        return stack;
    }
    for (ManageablePortfolioNode childNode : getChildNodes()) {
        Stack<ManageablePortfolioNode> found = childNode.findNodeStackByObjectId0(stack, nodeObjectId);
        if (found != null) {
            return found;
        }
    }
    stack.pop();
    return null;
}

From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java

/**
 * Returns the set of tags at the top of the stack. Return an empty set if the stack is empty. This should never
 * occur, but some badly-formatted RTF documents seem to lead to this situation.
 * /*from  w w w.  j a  v  a2 s. com*/
 * @param state
 * @param pop
 * @return
 */
private Map<String, Integer> safeState(Stack<Map<String, Integer>> state, boolean pop) {
    if (!state.isEmpty()) {
        if (pop) {
            return state.pop();
        } else {
            return state.peek();
        }
    } else {
        gLogger.error("State was empty.");
        return new HashMap<String, Integer>();
    }
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitInPredicate(Context ctx, Stack<Expr> stack, InPredicate expr) throws TajoException {
    stack.push(expr);//from  w w w .j  a  v  a 2s.  com
    EvalNode lhs = visit(ctx, stack, expr.getLeft());
    ValueSetEval valueSetEval = (ValueSetEval) visit(ctx, stack, expr.getInValue());
    stack.pop();

    Pair<EvalNode, EvalNode> pair = convertTypesIfNecessary(ctx, lhs, valueSetEval);

    return new InEval(pair.getFirst(), (ValueSetEval) pair.getSecond(), expr.isNot());
}

From source file:org.alfresco.filesys.repo.CifsHelper.java

private void addDescendents(List<NodeRef> pathRootNodeRefs, Stack<String> pathElements, List<NodeRef> results) {
    if (pathElements.isEmpty()) {
        // if this method is called with an empty path element stack, then the
        // current context nodes are the results to be added
        results.addAll(pathRootNodeRefs);
        return;/* www.ja v a  2s.  c  om*/
    }

    // take the first path element off the stack
    String pathElement = pathElements.pop();

    // iterate over each path root node
    for (NodeRef pathRootNodeRef : pathRootNodeRefs) {
        // deal with cyclic relationships by not traversing down any node already in the results
        if (results.contains(pathRootNodeRef)) {
            continue;
        }
        // get direct descendents along the path
        List<NodeRef> directDescendents = getDirectDescendents(pathRootNodeRef, pathElement);
        // recurse onto the descendents
        addDescendents(directDescendents, pathElements, results);
    }

    // restore the path element stack
    pathElements.push(pathElement);
}

From source file:org.apache.cocoon.components.treeprocessor.variables.PreparedVariableResolver.java

public final String resolve(InvokeContext context, Map objectModel) throws PatternException {
    List mapStack = null; // get the stack only when necessary - lazy inside the loop
    int stackSize = 0;

    if (needsMapStack) {
        if (context == null) {
            throw new PatternException("Need an invoke context to resolve " + this);
        }/*from w  w w  . ja  va  2 s .c o m*/
        mapStack = context.getMapStack();
        stackSize = mapStack.size();
    }

    Stack stack = new Stack();

    for (Iterator i = tokens.iterator(); i.hasNext();) {
        Token token = (Token) i.next();
        Token last;
        switch (token.getType()) {
        case TEXT:
            if (stack.empty()) {
                stack.push(new Token(EXPR, token.getStringValue()));
            } else {
                last = (Token) stack.peek();
                if (last.hasType(EXPR)) {
                    last.merge(token);
                } else {
                    stack.push(new Token(EXPR, token.getStringValue()));
                }
            }
            break;
        case CLOSE:
            Token expr = (Token) stack.pop();
            Token lastButOne = (Token) stack.pop();
            Token result;
            if (expr.hasType(COLON)) { // i.e. nothing was specified after the colon
                stack.pop(); // Pop the OPEN
                result = processModule(lastButOne, EMPTY_TOKEN, objectModel, context, mapStack, stackSize);
            } else if (lastButOne.hasType(COLON)) {
                Token module = (Token) stack.pop();
                stack.pop(); // Pop the OPEN
                result = processModule(module, expr, objectModel, context, mapStack, stackSize);
            } else {
                result = processVariable(expr, mapStack, stackSize);
            }
            if (stack.empty()) {
                stack.push(result);
            } else {
                last = (Token) stack.peek();
                if (last.hasType(EXPR)) {
                    last.merge(result);
                } else {
                    stack.push(result);
                }
            }
            break;
        case OPEN:
        case COLON:
        case ANCHOR_VAR:
        case THREADSAFE_MODULE:
        case STATEFUL_MODULE:
        case ROOT_SITEMAP_VARIABLE:
        default: {
            stack.push(token);
            break;
        }
        }
    }
    if (stack.size() != 1) {
        throw new PatternException("Evaluation error in expression: " + originalExpr);
    }
    return ((Token) stack.pop()).getStringValue();
}

From source file:org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet.java

protected void withModule(ModuleDefinition def, Stack<ModuleDefinition> parents, WithModule with) {
    long moduleStart = System.currentTimeMillis();
    if (def == null)
        return;//from  ww  w  .ja v a2  s .  c  o m

    if (!shouldLoad(def)) {
        log.info("Excluding context [{}] based on configuration", def.getName());
        return;
    }

    count++;

    with.with(def, parents);

    if (messagePrefix != null) {
        CONSOLE_LOG.info("[{}/{}] [{}ms] [{}ms] {} {}", count, total, (System.currentTimeMillis() - start),
                (System.currentTimeMillis() - moduleStart), messagePrefix, def.getName());
    }

    parents.push(def);

    for (ModuleDefinition child : def.getChildren()) {
        withModule(child, parents, with);
    }

    parents.pop();
}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

public int countgenes(Node trunk) {
    java.util.Stack c = new java.util.Stack();
    int ret = 0;//from   w  w  w  .  j  ava2 s . c  o  m
    c.push(trunk);
    Node tr = trunk;

    if (trunk == null) {
        System.out.print("\n!No trunk\n");
    }

    while (!c.empty()) {
        tr = (Node) c.pop();

        if (tr.merged) {
            c.push(tr.left);
            c.push(tr.right);
        } else {
            ret++;
        }
    }

    return ret;
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

public EvalNode visitCommonComparison(Context ctx, Stack<Expr> stack, BinaryOperator expr)
        throws TajoException {
    stack.push(expr);//from ww  w. j a  v a 2 s .c o  m
    EvalNode left = visit(ctx, stack, expr.getLeft());
    EvalNode right = visit(ctx, stack, expr.getRight());
    stack.pop();

    EvalType evalType;
    switch (expr.getType()) {
    case Equals:
        evalType = EvalType.EQUAL;
        break;
    case NotEquals:
        evalType = EvalType.NOT_EQUAL;
        break;
    case LessThan:
        evalType = EvalType.LTH;
        break;
    case LessThanOrEquals:
        evalType = EvalType.LEQ;
        break;
    case GreaterThan:
        evalType = EvalType.GTH;
        break;
    case GreaterThanOrEquals:
        evalType = EvalType.GEQ;
        break;
    default:
        throw new IllegalStateException("Wrong Expr Type: " + expr.getType());
    }

    return createBinaryNode(ctx, evalType, left, right);
}

From source file:gdt.jgui.entity.edge.JBondsPanel.java

/**
 * Response on the call from another context
 * @param console the main console/* www.  j  av a 2s.  c om*/
 * @param locator$ the locator string
 */
@Override
public void response(JMainConsole console, String locator$) {
    //   System.out.println("JEdgeEditor:response:"+Locator.remove(locator$,Locator.LOCATOR_ICON ));
    try {
        Properties locator = Locator.toProperties(locator$);
        String action$ = locator.getProperty(JRequester.REQUESTER_ACTION);
        entihome$ = locator.getProperty(Entigrator.ENTIHOME);
        Entigrator entigrator = console.getEntigrator(entihome$);
        String text$ = locator.getProperty(JTextEditor.TEXT);
        if (ACTION_NEW_ENTITY.equals(action$)) {
            Sack newEntity = entigrator.ent_new("edge", text$);
            newEntity.createElement("field");
            newEntity.putElementItem("field", new Core(null, "Edge", text$));
            newEntity.createElement("fhandler");
            newEntity.putElementItem("fhandler",
                    new Core(null, EdgeHandler.class.getName(), EdgeHandler.EXTENSION_KEY));
            newEntity.putElementItem("fhandler", new Core(null, FieldsHandler.class.getName(), null));
            newEntity.createElement("jfacet");
            newEntity.putElementItem("jfacet", new Core("gdt.jgui.entity.edge.JEdgeFacetAddItem",
                    EdgeHandler.class.getName(), "gdt.jgui.entity.edge.JEdgeFacetOpenItem"));
            newEntity.putAttribute(new Core(null, "icon", "edge.png"));
            entigrator.save(newEntity);
            entigrator.ent_assignProperty(newEntity, "fields", text$);
            entigrator.ent_assignProperty(newEntity, "edge", text$);
            String icons$ = entihome$ + "/" + Entigrator.ICONS;
            Support.addHandlerIcon(JBondsPanel.class, "edge.png", icons$);
            newEntity = entigrator.ent_reindex(newEntity);
            reindex(console, entigrator, newEntity);
            JEntityFacetPanel efp = new JEntityFacetPanel();
            String efpLocator$ = efp.getLocator();
            efpLocator$ = Locator.append(efpLocator$, Locator.LOCATOR_TITLE, newEntity.getProperty("label"));
            efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$);
            efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, newEntity.getKey());
            efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_LABEL,
                    newEntity.getProperty("label"));
            JEntityPrimaryMenu.reindexEntity(console, efpLocator$);
            Stack<String> s = console.getTrack();
            s.pop();
            console.setTrack(s);
            JConsoleHandler.execute(console, efpLocator$);
            return;
        }
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }

}