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:ParenMatcher.java

public void run() {
    StyledDocument doc = getStyledDocument();
    String text = "";
    int len = doc.getLength();
    try {//ww w  .  jav a 2 s  .c  o  m
        text = doc.getText(0, len);
    } catch (BadLocationException ble) {
    }
    java.util.Stack stack = new java.util.Stack();
    for (int j = 0; j < text.length(); j += 1) {
        char ch = text.charAt(j);
        if (ch == '(' || ch == '[' || ch == '{') {
            int depth = stack.size();
            stack.push("" + ch + j); // push a String containg the char and
            // the offset
            AttributeSet aset = matchAttrSet[depth % matchAttrSet.length];
            doc.setCharacterAttributes(j, 1, aset, false);
        }
        if (ch == ')' || ch == ']' || ch == '}') {
            String peek = stack.empty() ? "." : (String) stack.peek();
            if (matches(peek.charAt(0), ch)) { // does it match?
                stack.pop();
                int depth = stack.size();
                AttributeSet aset = matchAttrSet[depth % matchAttrSet.length];
                doc.setCharacterAttributes(j, 1, aset, false);
            } else { // mismatch
                doc.setCharacterAttributes(j, 1, badAttrSet, false);
            }
        }
    }

    while (!stack.empty()) { // anything left in the stack is a mismatch
        String pop = (String) stack.pop();
        int offset = Integer.parseInt(pop.substring(1));
        doc.setCharacterAttributes(offset, 1, badAttrSet, false);
    }
}

From source file:org.bpmscript.web.view.JavascriptView.java

/**
 * @see org.springframework.web.servlet.view.AbstractView#renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from   w  ww  .  j  av a 2s  .c o m*/
@SuppressWarnings("unchecked")
@Override
protected void renderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    Locale locale = RequestContextUtils.getLocale(request);
    Context cx = new ContextFactory().enterContext();
    try {
        // create scripting environment (i.e. load everything)
        ScriptableObject scope = new Global(cx);
        cx.putThreadLocal(Global.LIBRARY_ASSOCIATION_QUEUE, libraryAssociationQueue);
        ScriptableObject.putProperty(scope, "log", Context.javaToJS(log, scope));
        ScriptableObject.putProperty(scope, "request", Context.javaToJS(request, scope));
        ScriptableObject.putProperty(scope, "response", Context.javaToJS(response, scope));
        ScriptableObject.putProperty(scope, "base", Context.javaToJS(request.getContextPath(), scope));
        ScriptableObject.putProperty(scope, "locale", Context.javaToJS(locale, scope));
        Set<Map.Entry> entrySet = model.entrySet();
        for (Map.Entry<String, Object> entry : entrySet) {
            ScriptableObject.putProperty(scope, entry.getKey(),
                    mapToJsConverter.convertObject(scope, entry.getValue()));
        }
        Stack<String> sourceStack = new Stack<String>();
        sourceStack.push(configResource);
        cx.putThreadLocal(Global.SOURCE_STACK, sourceStack);
        if (libraryAssociationQueue != null) {
            cx.putThreadLocal(Global.LIBRARY_ASSOCIATION_QUEUE, libraryAssociationQueue);
        }
        Script configScript = javascriptSourceCache.getScript(
                new String(StreamUtils
                        .getBytes(getApplicationContext().getResource(configResource).getInputStream())),
                configResource);
        configScript.exec(cx, scope);
        sourceStack.pop();

        sourceStack.push(getUrl());
        Script script = javascriptSourceCache.getScript(
                new String(
                        StreamUtils.getBytes(getApplicationContext().getResource(getUrl()).getInputStream())),
                getUrl());
        Object result = script.exec(cx, scope);
        response.getWriter().write(result.toString());
        // not sure if this is necessary
        response.getWriter().flush();
    } finally {
        Context.exit();
    }
}

From source file:org.apache.hadoop.util.ConfTest.java

private static List<NodeInfo> parseConf(InputStream in) throws XMLStreamException {
    QName configuration = new QName("configuration");
    QName property = new QName("property");

    List<NodeInfo> nodes = new ArrayList<NodeInfo>();
    Stack<NodeInfo> parsed = new Stack<NodeInfo>();

    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLEventReader reader = factory.createXMLEventReader(in);

    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        if (event.isStartElement()) {
            StartElement currentElement = event.asStartElement();
            NodeInfo currentNode = new NodeInfo(currentElement);
            if (parsed.isEmpty()) {
                if (!currentElement.getName().equals(configuration)) {
                    return null;
                }/*  w  w  w  .  j  a va 2 s  .  c  o  m*/
            } else {
                NodeInfo parentNode = parsed.peek();
                QName parentName = parentNode.getStartElement().getName();
                if (parentName.equals(configuration)
                        && currentNode.getStartElement().getName().equals(property)) {
                    @SuppressWarnings("unchecked")
                    Iterator<Attribute> it = currentElement.getAttributes();
                    while (it.hasNext()) {
                        currentNode.addAttribute(it.next());
                    }
                } else if (parentName.equals(property)) {
                    parentNode.addElement(currentElement);
                }
            }
            parsed.push(currentNode);
        } else if (event.isEndElement()) {
            NodeInfo node = parsed.pop();
            if (parsed.size() == 1) {
                nodes.add(node);
            }
        } else if (event.isCharacters()) {
            if (2 < parsed.size()) {
                NodeInfo parentNode = parsed.pop();
                StartElement parentElement = parentNode.getStartElement();
                NodeInfo grandparentNode = parsed.peek();
                if (grandparentNode.getElement(parentElement) == null) {
                    grandparentNode.setElement(parentElement, event.asCharacters());
                }
                parsed.push(parentNode);
            }
        }
    }

    return nodes;
}

From source file:org.apache.hadoop.hbase.backup.mapreduce.MapReduceBackupMergeJob.java

/**
 * Converts path before copying//w  ww  . j  a  va2 s .com
 * @param p path
 * @param backupDirPath backup root
 * @return converted path
 */
protected Path convertToDest(Path p, Path backupDirPath) {
    String backupId = backupDirPath.getName();
    Stack<String> stack = new Stack<String>();
    String name = null;
    while (true) {
        name = p.getName();
        if (!name.equals(backupId)) {
            stack.push(name);
            p = p.getParent();
        } else {
            break;
        }
    }
    Path newPath = new Path(backupDirPath.toString());
    while (!stack.isEmpty()) {
        newPath = new Path(newPath, stack.pop());
    }
    return newPath;
}

From source file:co.anarquianegra.rockolappServidor.mundo.ListaReproductor.java

/**
 * Agrega canciones de un usuario a la lista de reproduccion grande
 * notifica a la interfaz para mostrar un mensaje de que han
 * sido aadidas las canciones//w w  w . j  a v  a  2  s  .  c o m
 * @param canciones
 * @param infoUsuario informacion del usuario
 */
synchronized public void agregarLista(Stack<Cancion> canciones, String infoUsuario) {
    for (int i = 0; i < canciones.size(); i++) {
        Cancion c = (Cancion) canciones.get(i);
    }
    while (!canciones.empty()) {
        try {
            listaReproduccion.add(canciones.pop());
        } catch (UnsupportedOperationException e) {
            System.out.println("Erro agregar cancion: " + e.toString());
        }
    }
    if (mediaPlayer == null && playing)
        reproducir();
    else if (mediaPlayer != null && mediaPlayer.getStatus().equals(Status.DISPOSED) && playing)
        reproducir();
    cantidadConexionesPositivas++;
}

From source file:com.bluepowermod.part.tube.TubeLogic.java

public void clearNodeCaches() {

    List<PneumaticTube> clearedTubes = new ArrayList<PneumaticTube>();
    Stack<PneumaticTube> todoTubes = new Stack<PneumaticTube>();

    clearNodeCache();/*from w w  w. j ava 2  s .co  m*/
    boolean firstRun = true;
    todoTubes.push(tube);

    while (!todoTubes.isEmpty()) {
        PneumaticTube tube = todoTubes.pop();
        if (tube.getParent() != null && tube.getWorld() != null) {
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                PneumaticTube neighbor = tube.getPartCache(d);
                if (neighbor != null) {
                    if (!clearedTubes.contains(neighbor)) {
                        neighbor.getLogic().clearNodeCache();
                        clearedTubes.add(neighbor);
                        if (firstRun || !neighbor.isCrossOver)
                            todoTubes.push(neighbor);
                    }
                }
            }
        }
        firstRun = false;
    }

}

From source file:fr.inria.oak.paxquery.common.xml.navigation.NavigationTreePattern.java

/**
 * Gives fresh numbers to all nodes in a tree pattern.
 * /*from  ww  w. ja  v  a  2  s  . c om*/
 */
public void renumberNodes() {
    Stack<NavigationTreePatternNode> st = new Stack<NavigationTreePatternNode>();
    st.push(this.root);
    while (!st.empty()) {
        NavigationTreePatternNode pn = st.pop();
        if (pn.getNodeCode() == -1) {
            // nothing
            //Parameters.logger.debug("-1 node! Left unchanged");
        } else {
            pn.setNodeCode(NavigationTreePatternNode.globalNodeCounter.getAndIncrement());
        }
        Iterator<NavigationTreePatternEdge> ie = pn.getEdges().iterator();
        while (ie.hasNext()) {
            st.push(ie.next().n2);
        }
    }
}

From source file:fr.inria.oak.paxquery.common.xml.navigation.NavigationTreePattern.java

/**
 * Same as {@link #renumberNodes()}, but it starts the numbering from the localCounter.
 * //  w  w w.ja  v  a 2 s . co  m
 * @author Konstantinos KARANASOS
 */
public void renumberNodes(int localCounter) {
    Stack<NavigationTreePatternNode> st = new Stack<NavigationTreePatternNode>();
    st.push(this.root);
    while (!st.empty()) {
        NavigationTreePatternNode pn = st.pop();
        if (pn.getNodeCode() == -1) {
            // nothing
            //Parameters.logger.debug("-1 node! Left unchanged");
        } else {
            pn.setNodeCode(localCounter);
            localCounter++;
        }
        Iterator<NavigationTreePatternEdge> ie = pn.getEdges().iterator();
        while (ie.hasNext()) {
            st.push(ie.next().n2);
        }
    }
}

From source file:com.webcohesion.ofx4j.io.nanoxml.TestNanoXMLOFXReader.java

/**
 * tests using sax to parse an OFX doc.// w ww .  j  a  v  a  2 s  .c o m
 */
public void testVersion1() throws Exception {
    NanoXMLOFXReader reader = new NanoXMLOFXReader();
    final Map<String, List<String>> headers = new HashMap<String, List<String>>();
    final Stack<Map<String, List<Object>>> aggregateStack = new Stack<Map<String, List<Object>>>();
    TreeMap<String, List<Object>> root = new TreeMap<String, List<Object>>();
    aggregateStack.push(root);

    reader.setContentHandler(getNewDefaultHandler(headers, aggregateStack));
    reader.parse(TestNanoXMLOFXReader.class.getResourceAsStream("example-response.ofx"));
    assertEquals(9, headers.size());
    assertEquals(1, aggregateStack.size());
    assertSame(root, aggregateStack.pop());

    TreeMap<String, List<Object>> OFX = (TreeMap<String, List<Object>>) root.remove("OFX").get(0);
    assertNotNull(OFX);

    TreeMap<String, List<Object>> SIGNONMSGSRSV1 = (TreeMap<String, List<Object>>) OFX.remove("SIGNONMSGSRSV1")
            .get(0);
    assertNotNull(SIGNONMSGSRSV1);
    TreeMap<String, List<Object>> SONRS = (TreeMap<String, List<Object>>) SIGNONMSGSRSV1.remove("SONRS").get(0);
    assertNotNull(SONRS);
    TreeMap<String, List<Object>> STATUS = (TreeMap<String, List<Object>>) SONRS.remove("STATUS").get(0);
    assertNotNull(STATUS);
    assertEquals("0", STATUS.remove("CODE").get(0).toString().trim());
    assertEquals("INFO", STATUS.remove("SEVERITY").get(0).toString().trim());
    assertTrue(STATUS.isEmpty());
    assertEquals("20071015021529.000[-8:PST]", SONRS.remove("DTSERVER").get(0).toString().trim());
    assertEquals("ENG", SONRS.remove("LANGUAGE").get(0).toString().trim());
    assertEquals("19900101000000", SONRS.remove("DTACCTUP").get(0).toString().trim());
    TreeMap<String, List<Object>> FI = (TreeMap<String, List<Object>>) SONRS.remove("FI").get(0);
    assertEquals("Bank&Cd", FI.remove("ORG").get(0).toString().trim());
    assertEquals("01234", FI.remove("FID").get(0).toString().trim());
    assertTrue(FI.isEmpty());
    assertTrue(SONRS.isEmpty());
    assertTrue(SIGNONMSGSRSV1.isEmpty());

    TreeMap<String, List<Object>> BANKMSGSRSV1 = (TreeMap<String, List<Object>>) OFX.remove("BANKMSGSRSV1")
            .get(0);
    TreeMap<String, List<Object>> STMTTRNRS = (TreeMap<String, List<Object>>) BANKMSGSRSV1.remove("STMTTRNRS")
            .get(0);
    assertEquals("23382938", STMTTRNRS.remove("TRNUID").get(0).toString().trim());
    STATUS = (TreeMap<String, List<Object>>) STMTTRNRS.remove("STATUS").get(0);
    assertNotNull(STATUS);
    assertEquals("0", STATUS.remove("CODE").get(0).toString().trim());
    assertEquals("INFO", STATUS.remove("SEVERITY").get(0).toString().trim());
    assertTrue(STATUS.isEmpty());
    TreeMap<String, List<Object>> STMTRS = (TreeMap<String, List<Object>>) STMTTRNRS.remove("STMTRS").get(0);
    assertEquals("USD", STMTRS.remove("CURDEF").get(0).toString().trim());
    TreeMap<String, List<Object>> BANKACCTFROM = (TreeMap<String, List<Object>>) STMTRS.remove("BANKACCTFROM")
            .get(0);
    assertEquals("SAVINGS", BANKACCTFROM.remove("ACCTTYPE").get(0).toString().trim());
    assertEquals("098-121", BANKACCTFROM.remove("ACCTID").get(0).toString().trim());
    assertEquals("987654321", BANKACCTFROM.remove("BANKID").get(0).toString().trim());
    assertTrue(BANKACCTFROM.isEmpty());
    TreeMap<String, List<Object>> BANKTRANLIST = (TreeMap<String, List<Object>>) STMTRS.remove("BANKTRANLIST")
            .get(0);
    assertEquals("20070101", BANKTRANLIST.remove("DTSTART").get(0).toString().trim());
    assertEquals("20071015", BANKTRANLIST.remove("DTEND").get(0).toString().trim());
    TreeMap<String, List<Object>> STMTTRN = (TreeMap<String, List<Object>>) BANKTRANLIST.remove("STMTTRN")
            .get(0);
    assertEquals("CREDIT", STMTTRN.remove("TRNTYPE").get(0).toString().trim());
    assertEquals("20070329", STMTTRN.remove("DTPOSTED").get(0).toString().trim());
    assertEquals("20070329", STMTTRN.remove("DTUSER").get(0).toString().trim());
    assertEquals("150.00", STMTTRN.remove("TRNAMT").get(0).toString().trim());
    assertEquals("980310001", STMTTRN.remove("FITID").get(0).toString().trim());
    assertEquals("TRANSFER", STMTTRN.remove("NAME").get(0).toString().trim());
    assertEquals("Transfer from checking &<> etc.", STMTTRN.remove("MEMO").get(0).toString().trim());
    assertTrue(STMTTRN.isEmpty());
    assertTrue(BANKTRANLIST.isEmpty());
    TreeMap<String, List<Object>> LEDGERBAL = (TreeMap<String, List<Object>>) STMTRS.remove("LEDGERBAL").get(0);
    assertEquals("5250.00", LEDGERBAL.remove("BALAMT").get(0).toString().trim());
    assertEquals("20071015021529.000[-8:PST]", LEDGERBAL.remove("DTASOF").get(0).toString().trim());
    assertTrue(LEDGERBAL.isEmpty());
    TreeMap<String, List<Object>> AVAILBAL = (TreeMap<String, List<Object>>) STMTRS.remove("AVAILBAL").get(0);
    assertEquals("5250.00", AVAILBAL.remove("BALAMT").get(0).toString().trim());
    assertEquals("20071015021529.000[-8:PST]", AVAILBAL.remove("DTASOF").get(0).toString().trim());
    assertTrue(AVAILBAL.isEmpty());
    assertTrue(LEDGERBAL.isEmpty());
    assertTrue(STMTRS.isEmpty());
    assertTrue(STMTTRNRS.isEmpty());
    assertTrue(BANKMSGSRSV1.isEmpty());

    assertTrue(OFX.isEmpty());
    assertTrue(root.isEmpty());
}

From source file:gdt.jgui.entity.procedure.JProcedurePanel.java

/**
 * Execute the response locator.//from  w  ww. j  a  v a  2  s . c o  m
 * @param console the main console.
 * @param locator$ the response locator.
 * 
 */
@Override
public void response(JMainConsole console, String locator$) {
    try {
        Properties locator = Locator.toProperties(locator$);
        String action$ = locator.getProperty(JRequester.REQUESTER_ACTION);
        if (ACTION_CREATE_PROCEDURE.equals(action$)) {
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
            String text$ = locator.getProperty(JTextEditor.TEXT);
            Entigrator entigrator = console.getEntigrator(entihome$);
            Sack procedure = entigrator.ent_new("procedure", text$);
            procedure = entigrator.ent_assignProperty(procedure, "procedure", procedure.getProperty("label"));
            procedure = entigrator.ent_assignProperty(procedure, "folder", procedure.getProperty("label"));
            procedure.putAttribute(new Core(null, "icon", "procedure.png"));
            entigrator.save(procedure);
            File folderHome = new File(entihome$ + "/" + procedure.getKey());
            if (!folderHome.exists())
                folderHome.mkdir();
            createSource(procedure.getKey());
            createProjectFile(procedure.getKey());
            createClasspathFile(procedure.getKey());
            entigrator.saveHandlerIcon(getClass(), "procedure.png");
            entityKey$ = procedure.getKey();
            JProcedurePanel pp = new JProcedurePanel();
            String ppLocator$ = pp.getLocator();
            ppLocator$ = Locator.append(ppLocator$, Entigrator.ENTIHOME, entihome$);
            ppLocator$ = Locator.append(ppLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JEntityPrimaryMenu.reindexEntity(console, ppLocator$);
            Stack<String> s = console.getTrack();
            s.pop();
            console.setTrack(s);
            JConsoleHandler.execute(console, ppLocator$);
            return;
        }
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }

}