Code example for Stack

Methods: peek, push, size

0
    @Override 
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        if (isCollectorConsuming(localName)) {
            collector.append('<').append(localName).append('>');
        } 
        else if ((elements.size() == 0)) {
            if (E_TITLE.equals(localName) && (channelTitle == null)) {
                elements.push(E_TITLE);
                startCollecting(E_TITLE);
            } 
            else if (E_LINK.equals(localName) && (channelLink == null)) {
                final String href = attributes.getValue("href");
                final String rel = attributes.getValue("rel");
                if ((channelLink == null) && (href != null) && (!"self".equals(rel))) {
                    channelLink = href;
                } 
                else { 
                    elements.push(E_LINK);
                    startCollecting(E_LINK);
                } 
            } 
            else if ((E_DESCRIPTION.equals(localName) || E_SUBTITLE.equals(localName)) && (channelDescription == null)) {
                elements.push(localName);
                startCollecting(localName);
            } 
            else if (E_ITEM.equals(localName) || E_ENTRY.equals(localName)) {
                elements.push(localName);
                item = new Item();
                final String about = attributes.getValue("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about");
                if (about != null) {
                    item.guid = about;
                } 
            } 
        } 
        else if ((elements.size() == 1) && (E_ITEM.equals(elements.peek()) || E_ENTRY.equals(elements.peek()))) {
            if (E_TITLE.equals(localName)) {
                elements.push(E_TITLE);
                startCollecting(E_TITLE);
            } 
            else if (E_LINK.equals(localName)) {
                final String href = attributes.getValue("href");
                final String rel = attributes.getValue("rel");
                if ((item.link == null) && (href != null) && (!"self".equals(rel))) {
                    item.link = href;
                } 
                else { 
                    elements.push(E_LINK);
                    startCollecting(E_LINK);
                } 
            } 
            else if (E_DESCRIPTION.equals(localName)) {
                elements.push(E_DESCRIPTION);
                startCollecting(E_DESCRIPTION);
            } 
            else if (E_GUID.equals(localName) || E_ID.equals(localName)) {
                elements.push(localName);
                startCollecting(localName);
            } 
            else if (E_PUB_DATE.equals(localName) || "published".equals(localName) || "date".equals(localName)) {
                elements.push(localName);
                startCollecting(localName);
            } 
        } 
    }