Example usage for java.util Stack push

List of usage examples for java.util Stack push

Introduction

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

Prototype

public E push(E item) 

Source Link

Document

Pushes an item onto the top of this stack.

Usage

From source file:com.sqewd.open.dal.core.persistence.db.AbstractDbPersister.java

private List<AbstractEntity> read(final String query, final Class<?> type, final int limit,
        final Connection conn) throws Exception {
    // Make sure the type for the class is available.
    StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(type);
    boolean joinedList = AbstractJoinGraph.hasJoinedList(enref);

    SQLQuery parser = new SQLQuery(type);

    String selectsql = parser.parse(query, limit);
    Statement stmnt = conn.createStatement();
    List<AbstractEntity> entities = new ArrayList<AbstractEntity>();
    HashMap<String, AbstractEntity> refindx = null;

    try {//from ww  w .j a v  a  2s.c  om
        log.debug("SELECT SQL [" + selectsql + "]");
        ResultSet rs = stmnt.executeQuery(selectsql);
        try {
            if (joinedList) {
                refindx = new HashMap<String, AbstractEntity>();
            }

            while (rs.next()) {

                if (!joinedList) {
                    AbstractJoinGraph gr = AbstractJoinGraph.lookup(type);

                    Object obj = type.newInstance();
                    if (!(obj instanceof AbstractEntity))
                        throw new Exception("Unsupported Entity type [" + type.getCanonicalName() + "]");
                    AbstractEntity entity = (AbstractEntity) obj;
                    Stack<KeyValuePair<Class<?>>> path = new Stack<KeyValuePair<Class<?>>>();
                    KeyValuePair<Class<?>> cls = new KeyValuePair<Class<?>>();
                    cls.setValue(entity.getClass());
                    path.push(cls);
                    EntityHelper.setEntity(entity, rs, gr, path);
                    entities.add(entity);
                } else {
                    EntityHelper.setEntity(enref, refindx, rs);
                }
            }
        } finally {
            if (rs != null && !rs.isClosed()) {
                rs.close();
            }
        }
        if (joinedList) {
            for (String key : refindx.keySet()) {
                entities.add(refindx.get(key));
            }
        }
        return entities;
    } finally {
        if (stmnt != null && !stmnt.isClosed()) {
            stmnt.close();
        }
    }
}

From source file:org.apache.jasper.JspC.java

/**
 * Locate all jsp files in the webapp. Used if no explicit
 * jsps are specified./* w  w w .j  a v  a2s  . c om*/
 */
public void scanFiles(File base) throws JasperException {
    Stack dirs = new Stack();
    dirs.push(base);
    if (extensions == null) {
        extensions = new Vector();
        extensions.addElement("jsp");
        extensions.addElement("jspx");
    }
    while (!dirs.isEmpty()) {
        String s = dirs.pop().toString();
        //System.out.println("--" + s);
        File f = new File(s);
        if (f.exists() && f.isDirectory()) {
            String[] files = f.list();
            String ext;
            for (int i = 0; i < files.length; i++) {
                File f2 = new File(s, files[i]);
                //System.out.println(":" + f2.getPath());
                if (f2.isDirectory()) {
                    dirs.push(f2.getPath());
                    //System.out.println("++" + f2.getPath());
                } else {
                    String path = f2.getPath();
                    String uri = path.substring(uriRoot.length());
                    ext = files[i].substring(files[i].lastIndexOf('.') + 1);
                    if (extensions.contains(ext) || jspConfig.isJspPage(uri)) {
                        //System.out.println(s + "?" + files[i]);
                        pages.addElement(path);
                    } else {
                        //System.out.println("not done:" + ext);
                    }
                }
            }
        }
    }
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

private JPopupMenu getCollapsePopupMenu() {
    //System.out.println("JEntityDigestDisplay:getCollapsePopupMenu:selection="+Locator.remove(selection$, Locator.LOCATOR_ICON));
    JPopupMenu popup = new JPopupMenu();
    JMenuItem collapseItem = new JMenuItem("Collapse");
    popup.add(collapseItem);/*from   ww  w . j a  va2  s  . co m*/
    collapseItem.setHorizontalTextPosition(JMenuItem.RIGHT);
    collapseItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
                int cnt = node.getChildCount();
                Stack<DefaultMutableTreeNode> s = new Stack<DefaultMutableTreeNode>();
                if (cnt > 0) {
                    DefaultMutableTreeNode child;
                    for (int i = 0; i < cnt; i++) {
                        child = (DefaultMutableTreeNode) node.getChildAt(i);
                        s.push(child);
                    }
                }
                while (!s.isEmpty())
                    tree.collapsePath(new TreePath(s.pop().getPath()));
            } catch (Exception ee) {
            }
        }
    });
    return popup;
}

From source file:org.apache.axis2.deployment.util.Utils.java

public static String getPath(String parent, String childPath) {
    Stack parentStack = new Stack();
    Stack childStack = new Stack();
    if (parent != null) {
        String[] values = parent.split("/");
        if (values.length > 0) {
            for (String value : values) {
                parentStack.push(value);
            }//from  w  w  w  . j  a  v  a  2 s .  com
        }
    }
    String[] values = childPath.split("/");
    if (values.length > 0) {
        for (String value : values) {
            childStack.push(value);
        }
    }
    String filepath = "";
    while (!childStack.isEmpty()) {
        String value = (String) childStack.pop();
        if ("..".equals(value)) {
            parentStack.pop();
        } else if (!"".equals(value)) {
            if ("".equals(filepath)) {
                filepath = value;
            } else {
                filepath = value + "/" + filepath;
            }
        }
    }
    while (!parentStack.isEmpty()) {
        String value = (String) parentStack.pop();
        if (!"".equals(value)) {
            filepath = value + "/" + filepath;
        }
    }
    return filepath;
}

From source file:org.sakaiproject.signup.tool.entityproviders.SignupEntityProducer.java

@SuppressWarnings("unchecked")
@Override/*from www  .j av  a  2  s  .  c  om*/
public String archive(String siteId, Document doc, Stack stack, String archivePath, List attachments) {

    String currentUserId = getSakaiFacade().getCurrentUserId();
    StringBuilder results = new StringBuilder();

    results.append("archiving " + getLabel() + Entity.SEPARATOR + siteId + Entity.SEPARATOR
            + SiteService.MAIN_CONTAINER + ".\n");

    Element rootElement = doc.createElement(SignupMeetingService.class.getName());
    ((Element) stack.peek()).appendChild(rootElement); //<org.sakaiproject>
    stack.push(rootElement);

    List<SignupMeeting> allMeetings = getSignupMeetingService().getAllSignupMeetings(siteId, currentUserId);

    if (allMeetings.size() > 0) {
        Element meetingListElement = this.copyFileProcessor.toXml("meetingList", doc, stack); //<meetingList>

        //adds meetings
        for (int i = 0; allMeetings.size() > i; i++) {
            try {
                SignupMeeting meeting = allMeetings.get(i);

                Element meetingElement = this.copyFileProcessor.toXml("meeting", doc, stack); //<meeting>
                Element titleElement = this.copyFileProcessor.toXml("title", doc, stack); //<title>
                Element locElement = this.copyFileProcessor.toXml("location", doc, stack); //<location>
                Element descElement = this.copyFileProcessor.toXml("description", doc, stack); //<description>
                Element meetingTypeElement = this.copyFileProcessor.toXml("meetingType", doc, stack); //<meetingType>
                Element creatorIdElement = this.copyFileProcessor.toXml("creatorId", doc, stack); //<creatorId>

                titleElement.appendChild(doc.createTextNode(meeting.getTitle())); //title
                locElement.appendChild(doc.createTextNode(meeting.getLocation())); //location
                descElement.appendChild(doc.createTextNode(meeting.getDescription())); //description
                meetingTypeElement.appendChild(doc.createTextNode(meeting.getMeetingType())); //meetingType
                creatorIdElement.appendChild(doc.createTextNode(meeting.getCreatorUserId())); //creatorId

                meetingElement.appendChild(titleElement);
                meetingElement.appendChild(locElement);
                meetingElement.appendChild(descElement);
                meetingElement.appendChild(meetingTypeElement);
                meetingElement.appendChild(creatorIdElement);

                if (meeting.isRecurredMeeting()) {
                    Element recurElement = this.copyFileProcessor.toXml("recurrenceType", doc, stack); //<recurrenceType>
                    recurElement.appendChild(doc.createTextNode(meeting.getRepeatType())); //recurrence
                    meetingElement.appendChild(recurElement);
                }

                Element timeslotListElement = this.copyFileProcessor.toXml("timeslotList", doc, stack); //<timeslotList>
                meetingElement.appendChild(timeslotListElement);

                List<SignupTimeslot> timeslots = meeting.getSignupTimeSlots(); //get the timeslots

                //adds timeslots to timeslotList
                for (int j = 0; j < timeslots.size(); j++) {
                    SignupTimeslot timeslot = timeslots.get(j);
                    List<SignupAttendee> attendees = timeslot.getAttendees();

                    Element timeslotElement = CopyFileProcessor.timeslotToXml(timeslot, doc, stack); //<timeslot>
                    timeslotListElement.appendChild(timeslotElement);

                    if (attendees.size() > 0) {
                        Element attendeeListElement = this.copyFileProcessor.toXml("attendeeList", doc, stack); //<attendeeList>
                        timeslotElement.appendChild(attendeeListElement);

                        //adds attendees and attendeeIds
                        for (int q = 0; q < attendees.size(); q++) {
                            SignupAttendee attendee = (SignupAttendee) attendees.get(q);
                            Element attendeeElement = this.copyFileProcessor.toXml("attendee", doc, stack); //<attendee>
                            Element attendeeIdElement = this.copyFileProcessor.toXml("attendeeId", doc, stack); //<attendeeId>
                            Element attendeeSiteIdElement = this.copyFileProcessor.toXml("attendeeSiteId", doc,
                                    stack); //<attendeeSiteId>

                            attendeeIdElement.appendChild(doc.createTextNode(attendee.getAttendeeUserId()));
                            attendeeSiteIdElement.appendChild(doc.createTextNode(attendee.getSignupSiteId()));
                            attendeeElement.appendChild(attendeeIdElement);
                            attendeeElement.appendChild(attendeeSiteIdElement);
                            attendeeListElement.appendChild(attendeeElement);
                        } //attendee loop end
                    } //if any attendee end
                } //timeslot loop end

                //if there are any attachments
                if (meeting.hasSignupAttachments()) {
                    Element attachmentListElement = this.copyFileProcessor.toXml("attachmentList", doc, stack); //<attachmentList>
                    List<SignupAttachment> allAttachments = meeting.getSignupAttachments();
                    meetingElement.appendChild(attachmentListElement);

                    //adds attachments
                    for (int m = 0; m < allAttachments.size(); m++) {
                        SignupAttachment attachment = allAttachments.get(m);

                        Element attachmentElement = this.copyFileProcessor.toXml("attachment", doc, stack); //<attachment>
                        Element attachmentUrlElement = this.copyFileProcessor.toXml("attachmentUrl", doc,
                                stack); //<attachmentUrl>
                        Element attachmentName = this.copyFileProcessor.toXml("attachmentName", doc, stack); //<attachmentName>
                        attachmentUrlElement.appendChild(doc.createTextNode(attachment.getResourceId()));
                        attachmentName.appendChild(doc.createTextNode(attachment.getFilename()));
                        attachmentElement.appendChild(attachmentUrlElement);
                        attachmentElement.appendChild(attachmentName);
                        attachmentListElement.appendChild(attachmentElement);
                    }
                }

                List<SignupSite> allSitesInMeeting = meeting.getSignupSites();

                Element availableToElement = this.copyFileProcessor.toXml("availableTo", doc, stack); //<availableTo>
                Element siteListElement = this.copyFileProcessor.toXml("siteList", doc, stack); //<siteList>
                availableToElement.appendChild(siteListElement);
                meetingElement.appendChild(availableToElement);

                for (int n = 0; n < allSitesInMeeting.size(); n++) {
                    SignupSite site = allSitesInMeeting.get(n);

                    Element siteElement = this.copyFileProcessor.toXml("site", doc, stack); //<site>
                    Element siteIdElement = this.copyFileProcessor.toXml("siteId", doc, stack); //<siteId>
                    siteIdElement.appendChild(doc.createTextNode(site.getSiteId()));
                    siteElement.appendChild(siteIdElement);
                    siteListElement.appendChild(siteElement);

                    //if there are groups
                    if (site.getSignupGroups().size() > 0) {
                        List<SignupGroup> allGroupsInSite = site.getSignupGroups();
                        Element groupListElement = this.copyFileProcessor.toXml("groupList", doc, stack); //<groupList>
                        siteElement.appendChild(groupListElement);

                        //adds groups
                        for (int g = 0; g < allGroupsInSite.size(); g++) {
                            SignupGroup group = allGroupsInSite.get(g);

                            Element groupElement = this.copyFileProcessor.toXml("group", doc, stack); //<group>
                            Element groupIdElement = this.copyFileProcessor.toXml("groupId", doc, stack); //<groupId>

                            groupIdElement.appendChild(doc.createTextNode(group.getGroupId()));
                            groupElement.appendChild(groupIdElement);
                            groupListElement.appendChild(groupElement);
                        }
                    } //signupGroups if end
                } //allSites for-loop end

                //add meetings to root
                meetingListElement.appendChild(meetingElement);
                rootElement.appendChild(meetingListElement);

            } catch (Exception e) {
                log.warn(e.getMessage());
            }
        } //main for-loop end
    }
    stack.pop();
    return results.toString();
}

From source file:edu.isi.karma.er.helper.SPARQLGeneratorUtil.java

private String checkParentMarked(TriplesMap triple, HashMap<TriplesMap, String> markedTriples, String var1) {
    Stack<String> stk = new Stack<>();
    ParentMapingInfo parentTriple = this.ParentMapingInfoList.get(triple.getSubject().getId());
    boolean markedParent = false;
    int count = 1;
    String previous = var1;
    while (parentTriple != null) {
        String predicate = parentTriple.predicate.getTemplate().toString();

        if (markedTriples.get(parentTriple.parent) == null) {

            markedTriples.put(parentTriple.parent, "Z" + count);
            String rdfsTypes = parentTriple.parent.getSubject().getRdfsType().get(0).toString();
            this.prefix_list.put("pref" + "Z" + count, rdfsTypes);
            stk.push(" ?Z" + count + " a pref" + "Z" + count + ": .");
            stk.push(" ?" + markedTriples.get(parentTriple.parent) + " " + predicate + " ?" + previous + " . ");
        } else {//from ww w  . java2 s  .c o  m
            stk.push(" ?" + markedTriples.get(parentTriple.parent) + " " + predicate + " ?" + previous + " . ");
            markedParent = true;
            break;
        }
        previous = markedTriples.get(parentTriple.parent);
        parentTriple = this.ParentMapingInfoList.get(parentTriple.parent.getSubject().getId());
        if (parentTriple == null) {
            break;
        }
        var1 = markedTriples.get(parentTriple.parent);
        //         if(markedTriples.containsKey(parentTriple.parent)) {
        //            markedParent = true;
        //            stk.push(" ?" + markedTriples.get(parentTriple.parent) + " " + 
        //                  predicate + " ?"+var1 + " . ");
        //            break;
        //         }
    }

    if (markedParent) {
        return StringUtils.join(stk, " ");
    }
    return "";
}

From source file:org.apache.tajo.engine.planner.rewrite.FilterPushDownRule.java

@Override
public LogicalNode visitFilter(FilterPushDownContext context, LogicalPlan plan, LogicalPlan.QueryBlock block,
        SelectionNode selNode, Stack<LogicalNode> stack) throws PlanningException {
    context.pushingDownFilters/*from  w  w  w  .ja  v a  2  s.  c  om*/
            .addAll(Sets.newHashSet(AlgebraicUtil.toConjunctiveNormalFormArray(selNode.getQual())));

    stack.push(selNode);
    visit(context, plan, block, selNode.getChild(), stack);
    stack.pop();

    if (context.pushingDownFilters.size() == 0) {
        // remove the selection operator if there is no search condition after selection push.
        LogicalNode node = stack.peek();
        if (node instanceof UnaryNode) {
            UnaryNode unary = (UnaryNode) node;
            unary.setChild(selNode.getChild());
        } else {
            throw new InvalidQueryException("Unexpected Logical Query Plan");
        }
    } else { // if there remain search conditions

        // check if it can be evaluated here
        Set<EvalNode> matched = TUtil.newHashSet();
        for (EvalNode eachEval : context.pushingDownFilters) {
            if (LogicalPlanner.checkIfBeEvaluatedAtThis(eachEval, selNode)) {
                matched.add(eachEval);
            }
        }

        // if there are search conditions which can be evaluated here,
        // push down them and remove them from context.pushingDownFilters.
        if (matched.size() > 0) {
            selNode.setQual(
                    AlgebraicUtil.createSingletonExprFromCNF(matched.toArray(new EvalNode[matched.size()])));
            context.pushingDownFilters.removeAll(matched);
        }
    }

    return selNode;
}

From source file:com.jsmartframework.web.manager.TagHandler.java

@SuppressWarnings("unchecked")
protected void pushDelegateTagParent() {
    Stack<RefAction> actionStack = (Stack<RefAction>) getMappedValue(DELEGATE_TAG_PARENT);
    if (actionStack == null) {
        actionStack = new Stack<RefAction>();
        actionStack.push(new RefAction());
        addMappedValue(DELEGATE_TAG_PARENT, actionStack);
    } else {/*from  w w  w  . j  av  a  2 s .  c o m*/
        actionStack.push(new RefAction());
    }
}

From source file:com.mirth.connect.connectors.file.FileReceiver.java

private FileInfo[] listFilesRecursively(Set<String> visitedDirectories, Stack<String> directoryStack)
        throws Exception {
    while (!directoryStack.isEmpty()) {
        // Get the current directory
        String fromDir = directoryStack.pop();

        if (!visitedDirectories.contains(fromDir)) {
            visitedDirectories.add(fromDir);

            // Add any subdirectories to the stack
            List<String> directories = listDirectories(fromDir);

            for (int i = directories.size() - 1; i >= 0; i--) {
                directoryStack.push(directories.get(i));
            }/* w w w.ja va2  s  .  c o  m*/

            // Return the files from the current directory
            return listFiles(fromDir);
        }
    }

    return null;
}

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

/**
 * This is the main loop of the RTF parser.
 *///from   w  ww  .j  a  v a  2 s .c om
//CSOFF:
@Override
protected void setDocumentContent(IDocument document, InputStream contentStream, String encoding)
        throws CoreException {
    RTFDocument rtfDocument = (RTFDocument) document;
    StringBuilder text = new StringBuilder();
    Map<String, Integer> currentTags = new HashMap<String, Integer>();
    currentTags.put(UNICOUNT, 1);
    Stack<Map<String, Integer>> state = new Stack<Map<String, Integer>>();
    state.push(currentTags);

    try {
        int c = contentStream.read();
        while (c != -1) {
            char ch = (char) c;
            if (ch == BACKSLASH) {
                ParserPair pair = handleControl(contentStream, safeState(state));
                handleControlCommand(pair.fString, text, safeState(state), rtfDocument);
                c = pair.fChar;
            } else if (ch == LEFT_BRACE) {
                ParserPair pair = handleGroup(contentStream, state, text, rtfDocument);
                c = pair.fChar;
            } else if (ch == RIGHT_BRACE) {
                handleEndGroup(contentStream, state, text, rtfDocument);
                c = contentStream.read();
            } else {
                if (!in(ch, SPACES)) {
                    text.append(ch);
                } else if (equal(ch, SPACE_CHAR)) {
                    text.append(ch);
                }
                c = contentStream.read();
            }

        }

    } catch (Exception e) {
        gLogger.error("Error while parsing a rtf file.", e); //$NON-NLS-1$
    }

    rtfDocument.set(text.toString());
}