Example usage for java.util Stack peek

List of usage examples for java.util Stack peek

Introduction

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

Prototype

public synchronized E peek() 

Source Link

Document

Looks at the object at the top of this stack without removing it from the stack.

Usage

From source file:org.nextframework.view.BaseTag.java

@SuppressWarnings("unchecked")
protected Object popAttribute(String name) {
    Stack stack = getStack(name + "_stack");
    Object pop = stack.pop();//from  ww  w .  j a v a 2 s  .  c o  m
    if (!stack.isEmpty()) {
        getRequest().setAttribute(name, stack.peek());
    } else {
        getRequest().setAttribute(name, null);
    }
    return pop;
}

From source file:com.autentia.intra.bean.MenuBean.java

/**
 * Add non-leaf node to current node if it is accesible by current user
 *
 * @param path       path of current node
 * @param creds      current user/*from ww w  .  j a  v  a  2 s  .  co m*/
 * @param neededRole role needed to render the node
 * @param parent     parent node
 * @param cmd        command name
 * @return true if node has been created
 */
private boolean openNode(Stack<TreeNode> path, Principal creds, GrantedAuthority neededRole, String cmd) {
    boolean added = false;

    if (neededRole == null || creds.hasAuthority(neededRole)) {
        String text;
        try {
            text = msg.getString("menu." + cmd);
        } catch (MissingResourceException e) {
            text = "MISSING : " + cmd + " : MISSING";
        }
        TreeNode child = new TreeNodeBase("folder", text, cmd, false);
        path.peek().getChildren().add(child);
        path.push(child);
        added = true;
    }

    log.debug("openNode - " + (added ? "OPEN  " : "IGNORE") + ": " + cmd);
    return added;
}

From source file:com.autentia.intra.bean.MenuBean.java

/**
 * Add leaf node to parent node if it is accesible by current user
 *
 * @param path       path of current node
 * @param creds      current user/*  w  ww .  ja  v  a2 s  .  co  m*/
 * @param neededRole role needed to render the node
 * @param parent     parent node
 * @param cmd        command name
 * @return true if node was added
 */
private boolean addLeaf(Stack<TreeNode> path, Principal creds, GrantedAuthority neededRole, String cmd) {
    boolean added = false;

    if (neededRole == null || creds.hasAuthority(neededRole)) {
        String text;
        try {
            text = msg.getString("menu." + cmd);
        } catch (MissingResourceException e) {
            text = "MISSING : " + cmd + " : MISSING";
        }
        TreeNode child = new TreeNodeBase("document", text, cmd, true);
        path.peek().getChildren().add(child);
        added = true;
    }

    log.debug("addLeaf - " + (added ? "ADD   " : "IGNORE") + ": " + cmd);
    return added;
}

From source file:org.sakaiproject.site.impl.BaseSitePage.java

/**
 * @inheritDoc/*from ww  w. j a va  2s  .c  o  m*/
 */
public Element toXml(Document doc, Stack stack) {
    Element page = doc.createElement("page");
    ((Element) stack.peek()).appendChild(page);

    page.setAttribute("id", getId());
    if (m_title != null)
        page.setAttribute("title", m_title);
    page.setAttribute("layout", Integer.toString(m_layout));
    page.setAttribute("popup", Boolean.valueOf(m_popup).toString());

    // properties
    stack.push(page);
    getProperties().toXml(doc, stack);
    stack.pop();

    // tools
    Element list = doc.createElement("tools");
    page.appendChild(list);
    stack.push(list);
    for (Iterator iTools = getTools().iterator(); iTools.hasNext();) {
        BaseToolConfiguration tool = (BaseToolConfiguration) iTools.next();
        tool.toXml(doc, stack);
    }
    stack.pop();

    return page;
}

From source file:com.sencha.gxt.core.rebind.XTemplateParser.java

public TemplateModel parse(String template) throws UnableToCompleteException {
    // look for parameters or tags (Consider combining into one pattern)
    TemplateModel model = new TemplateModel();
    Stack<ContainerTemplateChunk> stack = new Stack<ContainerTemplateChunk>();
    stack.push(model);/*from w w  w.j ava  2s.c om*/
    Matcher m = NON_LITERAL_PATTERN.matcher(template);
    int lastMatchEnd = 0;
    while (m.find()) {
        // range of the current non-literal
        int begin = m.start(), end = m.end();
        String currentMatch = template.substring(begin, end);

        // if there was content since the last non-literal chunk, track it
        if (lastMatchEnd < begin) {
            ContentChunk c = literal(template.substring(lastMatchEnd, begin));
            stack.peek().children.add(c);
            log(c);
        }

        // move the last match pointer
        lastMatchEnd = end;

        // tpl tag starting
        Matcher tagOpenMatch = TAG_PATTERN.matcher(currentMatch);
        if (tagOpenMatch.matches()) {
            ControlChunk c = new ControlChunk();
            c.controls = new HashMap<String, String>();
            String attrs = tagOpenMatch.group(1).trim();
            Matcher attrMatcher = ATTR_PATTERN.matcher(attrs);
            while (attrMatcher.find()) {
                // should be if or for
                String key = attrMatcher.group(1);
                // must be html-decoded
                String encodedValue = attrMatcher.group(2) == null ? attrMatcher.group(3)
                        : attrMatcher.group(2);
                String value = StringEscapeUtils.unescapeXml(encodedValue);
                c.controls.put(key, value);
            }
            stack.peek().children.add(c);
            stack.push(c);
            log(c);
            continue;
        }

        // tpl tag ending
        Matcher tagCloseMatch = TAG_CLOSE_PATTERN.matcher(currentMatch);
        if (tagCloseMatch.matches()) {
            TemplateChunk c;
            try {
                c = stack.pop();
            } catch (EmptyStackException ex) {
                logger.log(Type.ERROR, "Too many </tpl> tags");
                throw new UnableToCompleteException();
            }
            log(c);
            continue;
        }

        // reference (code)
        Matcher codeMatch = INVOKE_PATTERN.matcher(currentMatch);
        if (codeMatch.matches()) {
            ContentChunk c = new ContentChunk();
            c.type = ContentType.CODE;
            c.content = codeMatch.group(1);
            stack.peek().children.add(c);
            log(c);
            continue;
        }

        // reference (param)
        Matcher paramMatch = PARAM_PATTERN.matcher(currentMatch);
        if (paramMatch.matches()) {
            ContentChunk c = new ContentChunk();
            c.type = ContentType.REFERENCE;
            c.content = paramMatch.group(1);
            stack.peek().children.add(c);
            log(c);
            continue;
        }
    }
    // handle trailing content
    if (lastMatchEnd < template.length()) {
        ContentChunk c = literal(template.substring(lastMatchEnd));
        log(c);
        model.children.add(c);
    }
    if (model != stack.peek()) {
        logger.log(Type.ERROR, "Too few </tpl> tags");
        throw new UnableToCompleteException();
    }
    return model;
}

From source file:org.wso2.carbon.registry.core.jdbc.dataaccess.JDBCDatabaseTransaction.java

private static TransactionEntry getStackedTransactionalEntry() {
    Stack<TransactionEntry> transactionalEntryStack = tStackedTransactionalEntryStack.get();
    if (transactionalEntryStack == null) {
        tStackedTransactionalEntryStack.remove();
        transactionalEntryStack = tStackedTransactionalEntryStack.get();
    }//from ww w . j  av  a  2 s  . com
    return transactionalEntryStack.peek();
}

From source file:com.webcohesion.ofx4j.io.TestBaseOFXReader.java

/**
 * tests using sax to parse an OFX doc.//from  ww  w .  ja v a2  s.c  om
 */
public void testVersion2() throws Exception {
    BaseOFXReader reader = new BaseOFXReader() {
        protected void parseV1FromFirstElement(Reader reader) throws IOException, OFXParseException {
            fail();
        }
    };
    final Map<String, String> headers = new HashMap<String, String>();
    final Stack<Map<String, Object>> aggregateStack = new Stack<Map<String, Object>>();
    TreeMap<String, Object> root = new TreeMap<String, Object>();
    aggregateStack.push(root);

    reader.setContentHandler(new DefaultHandler() {

        @Override
        public void onHeader(String name, String value) {
            LOG.debug(name + ":" + value);
            headers.put(name, value);
        }

        @Override
        public void onElement(String name, String value) {
            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + name + "=" + value);

            aggregateStack.peek().put(name, value);
        }

        @Override
        public void startAggregate(String aggregateName) {
            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + aggregateName + " {");

            TreeMap<String, Object> aggregate = new TreeMap<String, Object>();
            aggregateStack.peek().put(aggregateName, aggregate);
            aggregateStack.push(aggregate);
        }

        @Override
        public void endAggregate(String aggregateName) {
            aggregateStack.pop();

            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + "}");
        }
    });
    reader.parse(BaseOFXReader.class.getResourceAsStream("example-response.ofx2"));
    assertEquals(5, headers.size());
    assertEquals(1, aggregateStack.size());
    assertSame(root, aggregateStack.pop());
}

From source file:com.projity.pm.graphic.model.transform.NodeCacheTransformer.java

private Map<GraphicNode, List<GraphicNode>> extractAssignments(List list) {
    Map<GraphicNode, List<GraphicNode>> map = new HashMap<GraphicNode, List<GraphicNode>>();
    GraphicNode current, last;/* w  ww  .jav a  2 s  . c o  m*/
    Stack<GraphicNode> path = new Stack<GraphicNode>();
    for (ListIterator i = list.listIterator(); i.hasNext();) {
        current = (GraphicNode) i.next();
        if (current.getLevel() == 1) {
            path.clear();
            path.push(current);
            continue;
        }
        while ((last = path.peek()).getLevel() >= current.getLevel())
            path.pop();
        if (current.isAssignment()) {
            GraphicNode task = path.peek();
            List<GraphicNode> ass = map.get(task);
            if (ass == null) {
                ass = new LinkedList<GraphicNode>();
                map.put(task, ass);
            }
            ass.add(current);
            i.remove();
        }
        path.push(current);
    }
    return map;
}

From source file:logica.Estacion.java

/**
 *  Actualiza todas las sub-estaciones y retorna una pila con todas ellas
 * //  ww w  .j av  a  2 s  . c  om
 * @return Pila de PaqueteDatos con las mediciones de toda esta sub red
 */
public Stack<PaqueteDatos> actualizar() {
    // Toda la informacion recibida de las sub-estaciones
    // La informacin recibida de _una_ subestacion se almacena ac
    Stack<PaqueteDatos> newData = new Stack();
    LOGGER.log(Level.INFO, String.format("Actualizando estacion %s %d", clase.toString(), ID));

    medidasPila.clear(); // Limpio la pila

    for (Estacion subestacion : redEstaciones) {
        if (subestacion != null) {
            newData = subestacion.actualizar();

            //                newData.peek().printDatos();    // Para debbugear

            // newData >> data
            if (newData.peek() != null)
                // Copia newData (pila) en la base de medidasPila (otra pila).
                medidasPila.addAll(newData);
        }
    }

    return medidasPila;
}

From source file:fr.openwide.talendalfresco.alfresco.importer.ViewParserBase.java

/**
 * Get parent Node Context/*from  w  w w.ja  v  a 2  s  .c om*/
 * 
 * @param contextStack  context stack
 * @return  node context
 */
private NodeContext peekNodeContext(Stack<ElementContext> contextStack) {
    ElementContext element = contextStack.peek();
    if (element instanceof NodeContext) {
        return (NodeContext) element;
    } else if (element instanceof NodeItemContext) {
        return ((NodeItemContext) element).getNodeContext();
    }
    throw new ImporterException("Internal error: Failed to retrieve node context");
}