List of usage examples for java.util Stack pop
public synchronized E pop()
From source file:com.google.dart.compiler.metrics.Tracer.java
void endImpl(TraceEvent event, String... data) { if (!enabled) { return;/*from ww w.java2 s .c om*/ } if (data.length % 2 == 1) { throw new IllegalArgumentException("Unmatched data argument"); } Stack<TraceEvent> threadPendingEvents = pendingEvents.get(); if (threadPendingEvents.isEmpty()) { throw new IllegalStateException("Tried to end an event that never started!"); } TraceEvent currentEvent = threadPendingEvents.pop(); currentEvent.updateDuration(); while (currentEvent != event && !threadPendingEvents.isEmpty()) { // Missed a closing end for one or more frames! Try to sync back up. currentEvent.addData("Missed", "This event was closed without an explicit call to Event.end()"); currentEvent = threadPendingEvents.pop(); currentEvent.updateDuration(); } if (threadPendingEvents.isEmpty() && currentEvent != event) { currentEvent.addData("Missed", "Fell off the end of the threadPending events"); } if (logGcTime) { addGcEvents(currentEvent); } currentEvent.addData(data); if (logOverheadTime) { addOverheadEvent(currentEvent); } if (threadPendingEvents.isEmpty()) { if (fileLoggingEnabled) { eventsToWrite.add(currentEvent); } } }
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 .j a v a 2 s .c o m .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:net.bulletin.pdi.xero.step.support.XMLChunkerImpl.java
private String pullNextXmlChunkFromTopElementOnStack(XMLChunkerState data) throws KettleException { Stack<String> elementStack = data.getElementStack(); XMLStreamReader xmlStreamReader = data.getXmlStreamReader(); int elementStackDepthOnEntry = elementStack.size(); StringWriter stringWriter = new StringWriter(); try {/*www . j ava 2 s . c om*/ XMLStreamWriter xmlStreamWriter = data.getXmlOutputFactory().createXMLStreamWriter(stringWriter); xmlStreamWriter.writeStartDocument(CharEncoding.UTF_8, "1.0"); // put the current element on because presumably it's the open element for the one // that is being looked for. XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); while (xmlStreamReader.hasNext() & elementStack.size() >= elementStackDepthOnEntry) { switch (xmlStreamReader.next()) { case XMLStreamConstants.END_DOCUMENT: break; // handled below explicitly. case XMLStreamConstants.END_ELEMENT: elementStack.pop(); XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); break; case XMLStreamConstants.START_ELEMENT: elementStack.push(xmlStreamReader.getLocalName()); XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); break; default: XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); break; } } xmlStreamWriter.writeEndDocument(); xmlStreamWriter.close(); } catch (Exception e) { throw new KettleException("unable to process a chunk of the xero xml stream", e); } return stringWriter.toString(); }
From source file:com.baidu.rigel.biplatform.parser.CompileSection.java
private void sectionProcess(Stack<Node> nodes, Node tokenNode, CalculateNode calcNode) { if (nodes.isEmpty()) { if (calcNode == null) { nodes.push(tokenNode);// w w w.jav a 2 s . c o m } else { calcNode.setLeft(tokenNode); nodes.push(calcNode); } } else { // ? if (!nodes.peek().getNodeType().equals(NodeType.Calculate)) { // ?? throw new NotAllowedOperationException("not allowed"); } CalculateNode node = (CalculateNode) nodes.peek(); if (calcNode == null) { node.setRight(tokenNode); return; } if (node.getOperation().getPriority() >= calcNode.getOperation().getPriority()) { node.setRight(tokenNode); calcNode.setLeft(node); // nodes.pop(); } else { calcNode.setLeft(tokenNode); } nodes.push(calcNode); } }
From source file:org.apache.tajo.plan.ExprAnnotator.java
@Override public EvalNode visitBetween(Context ctx, Stack<Expr> stack, BetweenPredicate between) throws TajoException { stack.push(between);/*from w ww . j ava2s . co m*/ EvalNode predicand = visit(ctx, stack, between.predicand()); EvalNode begin = visit(ctx, stack, between.begin()); EvalNode end = visit(ctx, stack, between.end()); stack.pop(); // implicit type conversion DataType widestType = CatalogUtil.getWidestType(convert(predicand.getValueType()).getDataType(), convert(begin.getValueType()).getDataType(), convert(end.getValueType()).getDataType()); BetweenPredicateEval betweenEval = new BetweenPredicateEval(between.isNot(), between.isSymmetric(), predicand, begin, end); betweenEval = (BetweenPredicateEval) convertType(ctx, betweenEval, TypeConverter.convert(widestType)); return betweenEval; }
From source file:org.apache.maven.shared.release.phase.AbstractReleaseTestCase.java
protected List<MavenProject> createReactorProjects(String path, String targetPath, String subpath) throws Exception { File testFile = getTestFile("target/test-classes/projects/" + path + subpath + "/pom.xml"); Stack<File> projectFiles = new Stack<File>(); projectFiles.push(testFile);/*from w w w . j a v a2 s .c o m*/ List<DefaultArtifactRepository> repos = Collections.singletonList( new DefaultArtifactRepository("central", getRemoteRepositoryURL(), new DefaultRepositoryLayout())); Repository repository = new Repository(); repository.setId("central"); repository.setUrl(getRemoteRepositoryURL()); ProfileManager profileManager = new DefaultProfileManager(getContainer()); Profile profile = new Profile(); profile.setId("profile"); profile.addRepository(repository); profileManager.addProfile(profile); profileManager.activateAsDefault(profile.getId()); List<MavenProject> reactorProjects = new ArrayList<MavenProject>(); while (!projectFiles.isEmpty()) { File file = (File) projectFiles.pop(); // Recopy the test resources since they are modified in some tests String filePath = file.getPath(); int index = filePath.indexOf("test-classes") + "test-classes".length() + 1; filePath = filePath.substring(index).replace('\\', '/'); File newFile = getTestFile("target/test-classes/" + StringUtils.replace(filePath, path, targetPath)); FileUtils.copyFile(getTestFile("src/test/resources/" + filePath), newFile); MavenProject project = projectBuilder.build(newFile, localRepository, profileManager); for (Iterator i = project.getModules().iterator(); i.hasNext();) { String module = (String) i.next(); projectFiles.push(new File(file.getParentFile(), module + "/pom.xml")); } reactorProjects.add(project); } ProjectSorter sorter = new ProjectSorter(reactorProjects); reactorProjects = sorter.getSortedProjects(); ArtifactFactory artifactFactory = (ArtifactFactory) lookup(ArtifactFactory.ROLE); ArtifactCollector artifactCollector = (ArtifactCollector) lookup(ArtifactCollector.class.getName()); ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) lookup( ArtifactMetadataSource.ROLE); // pass back over and resolve dependencies - can't be done earlier as the order may not be correct for (Iterator i = reactorProjects.iterator(); i.hasNext();) { MavenProject project = (MavenProject) i.next(); project.setRemoteArtifactRepositories(repos); project.setPluginArtifactRepositories(repos); Artifact projectArtifact = project.getArtifact(); Map managedVersions = createManagedVersionMap( ArtifactUtils.versionlessKey(projectArtifact.getGroupId(), projectArtifact.getArtifactId()), project.getDependencyManagement(), artifactFactory); project.setDependencyArtifacts(project.createArtifacts(artifactFactory, null, null)); ArtifactResolutionResult result = artifactCollector.collect(project.getDependencyArtifacts(), projectArtifact, managedVersions, localRepository, repos, artifactMetadataSource, null, Collections.EMPTY_LIST); project.setArtifacts(result.getArtifacts()); } return reactorProjects; }
From source file:org.openmrs.module.shr.cdahandler.api.impl.CdaImportServiceImpl.java
/** * Import the parsed clinical document//w w w. j av a2 s . c o m * Auto generated method comment * * @param clinicalDocument * @return * @throws DocumentImportException */ @Override public Visit importDocument(ClinicalDocument clinicalDocument) throws DocumentImportException { if (this.m_processor == null) this.m_processor = CdaImporter.getInstance(); // TODO: Store incoming to a temporary table for CDAs (like the HL7 queue) Visit retVal = this.m_processor.processCdaDocument(clinicalDocument); // Notify of successful import if (retVal != null) { Stack<CdaImportSubscriber> toBeNotified = new Stack<CdaImportSubscriber>(); // The generic ones for all Set<CdaImportSubscriber> candidates = this.m_subscribers.get("*"); if (candidates != null) for (CdaImportSubscriber subscriber : candidates) toBeNotified.push(subscriber); // Notify the default always for (II templateId : clinicalDocument.getTemplateId()) { candidates = this.m_subscribers.get(templateId.getRoot()); if (candidates == null) continue; // no candidates for (CdaImportSubscriber subscriber : candidates) if (!toBeNotified.contains(subscriber)) toBeNotified.push(subscriber); } // Notify the found subscribers while (!toBeNotified.isEmpty()) toBeNotified.pop().onDocumentImported(clinicalDocument, retVal); } return retVal; }
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);// ww w .j a v a 2 s . c o 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.shindig.gadgets.parse.nekohtml.NekoSimplifiedHtmlParser.java
private void fixNekoWeirdness(Document document) { // Neko as of versions > 1.9.13 stuffs all leading <script> nodes into <head>. // This breaks all sorts of assumptions in gadgets, notably the existence of document.body. // We can't tell Neko to avoid putting <script> into <head> however, since gadgets // like <Content><script>...</script><style>...</style> will break due to both // <script> and <style> ending up in <body> -- at which point Neko unceremoniously // drops the <style> (and <link>) elements. // Therefore we just search for <script> elements in <head> and stuff them all into // the top of <body>. // This method assumes a normalized document as input. Node html = DomUtil.getFirstNamedChildNode(document, "html"); if (html.getNextSibling() != null && html.getNextSibling().getNodeName().equalsIgnoreCase("html")) { // if a doctype is specified, then the desired root <html> node is wrapped by an <HTML> node // Pull out the <html> root. html = html.getNextSibling();/*from w ww. jav a 2 s.c o m*/ } Node head = DomUtil.getFirstNamedChildNode(html, "head"); if (head == null) { head = document.createElement("head"); html.insertBefore(head, html.getFirstChild()); } NodeList headNodes = head.getChildNodes(); Stack<Node> headScripts = new Stack<Node>(); for (int i = 0; i < headNodes.getLength(); ++i) { Node headChild = headNodes.item(i); if (headChild.getNodeName().equalsIgnoreCase("script")) { headScripts.add(headChild); } } // Remove from head, add to top of <body> in <head> order. Node body = DomUtil.getFirstNamedChildNode(html, "body"); if (body == null) { body = document.createElement("body"); html.insertBefore(body, head.getNextSibling()); } Node bodyFirst = body.getFirstChild(); while (!headScripts.isEmpty()) { Node headScript = headScripts.pop(); head.removeChild(headScript); body.insertBefore(headScript, bodyFirst); bodyFirst = headScript; } }
From source file:NimbleTree.java
/** * A static constructor (is this the right term?) where a lisp-style s-expression * is passed in as a string. This can't be a true constructor because the result * is a tree over String, not a generic tree. *//*from www . j av a 2s . c o m*/ public static NimbleTree<String> makeTreeOverStringFromSExpression(String input) { NimbleTree<String> tree = new NimbleTree<String>(); Stack<TreeNode<String>> previousParents = new Stack<TreeNode<String>>(); // Make sure the string is tokenizable // FIXME allow [] and maybe other delimiters? input = input.replace("(", " ( "); input = input.replace(")", " ) "); StringTokenizer st = new StringTokenizer(input); boolean firstTimeThrough = true; while (st.hasMoreTokens()) { String currTok = st.nextToken().trim(); if (currTok.equals("")) { // Tokenizer gave us an empty token, do nothing. } else if (currTok.equals("(")) { // Get the *next* token and make a new subtree on it. currTok = st.nextToken().trim(); if (firstTimeThrough == true) { // The tree is of the form "(x)" // This is the root node: just set its data firstTimeThrough = false; tree.getRoot().setData(currTok); } else { // This is the root of a new subtree. Save parent, // then set this node to be the new parent. tree.addChild(currTok); tree.getCurrentNode().getEnd().setID(tree.getNodeCount()); previousParents.push(tree.getCurrentNode()); tree.setCurrentNode(tree.getCurrentNode().getEnd()); } } else if (currTok.equals(")")) { // Finished adding children to current parent. Go back // to previous parent (if there was none, it's because // current parent is root, so we're finished anyway). if (!previousParents.empty()) { tree.setCurrentNode(previousParents.pop()); } } else { if (firstTimeThrough == true) { // The tree is of the form "x". // This is to be the root node: just set its data. firstTimeThrough = false; tree.getRoot().setData(currTok); } else { // Add a child node to current parent. tree.addChild(currTok); tree.getCurrentNode().getEnd().setID(tree.getNodeCount()); } } } return tree; }