List of usage examples for java.util Stack peek
public synchronized E peek()
From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java
@Override public TMap readMapBegin() throws TException { //System.out.println("readMapBegin"); // Get the IO Stack Stack<ThriftIO> stack = threadSafeSIOStack.get(); ThriftIO currentIO = stack.peek(); ThriftFieldMetadata thriftFieldMetadata = currentIO.fieldsStack.peek(); // field related to the list MapMetaData mapMetaData = (MapMetaData) thriftFieldMetadata.fieldMetaData.valueMetaData; // extract the DBMap (BasicDbObject) BasicDBObject dbObject = null;/* w ww . j a v a 2s .c om*/ BasicDBObject securedDObject = null; if (thriftFieldMetadata.securedFieldMetaData.isSecured()) { // from the mongoIO securedWrap for a secured map BasicDBObject securedWrap = (BasicDBObject) currentIO.mongoIO.get("securedwrap"); securedDObject = (BasicDBObject) securedWrap .get(Short.toString(currentIO.fieldsStack.peek().tfield.id)); dbObject = securedDObject; } else { // from the mongoIO field for an unsecured map dbObject = (BasicDBObject) currentIO.mongoIO.get(currentIO.fieldsStack.peek().tfield.name); } ThriftIO thriftListIO = null; if (mapMetaData.valueMetaData.isStruct()) { thriftListIO = new ThriftIO(((StructMetaData) mapMetaData.valueMetaData).structClass, dbObject, securedDObject, true, false); } else { thriftListIO = new ThriftIO(null, dbObject, securedDObject, true, false); } thriftListIO.mapIterator = dbObject.entrySet().iterator(); stack.push(thriftListIO); threadSafeSIOStack.set(stack); return new TMap(TType.STRING, TType.STRING, dbObject.size()); }
From source file:com.google.dart.compiler.metrics.Tracer.java
TraceEvent startImpl(EventType type, String... data) { if (!enabled) { return dummyEvent; }/*from w w w.j a v a 2 s . c o m*/ if (data.length % 2 == 1) { throw new IllegalArgumentException("Unmatched data argument"); } Stack<TraceEvent> threadPendingEvents = pendingEvents.get(); TraceEvent parent = null; if (!threadPendingEvents.isEmpty()) { parent = threadPendingEvents.peek(); } else { // reset the thread CPU time base for top-level events (so events can be // properly sequenced chronologically) threadCpuTimeKeeper.resetTimeBase(); } TraceEvent newEvent = new TraceEvent(parent, type, data); // Add a field to the top level event in order to track the base time // so we can re-normalize the data if (threadPendingEvents.size() == 0) { long baseTime = logProcessCpuTime ? processCpuTimeKeeper.zeroTimeMillis() : (logThreadCpuTime ? threadCpuTimeKeeper.zeroTimeMillis() : elapsedTimeKeeper.zeroTimeMillis()); newEvent.addData("baseTime", "" + baseTime); } threadPendingEvents.push(newEvent); return newEvent; }
From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java
private ThriftFieldMetadata peekWriteField() throws TException { Stack<ThriftFieldMetadata> writeStack = threadSafeFieldsStack.get(); if (writeStack.size() > 0) { return writeStack.peek(); } else {/*from www . j a v a 2 s . co m*/ return STOP_THRIFT_FIELD_METADATA; } }
From source file:org.seasar.mayaa.impl.builder.TemplateBuilderImpl.java
protected void doInjection(Template template) { if (template == null) { throw new IllegalArgumentException(); }//from www . j a v a 2 s. c o m saveToCycle(template, template); Stack stack = new Stack(); stack.push(template); SpecificationNode mayaa = SpecificationUtil.createSpecificationNode(QM_MAYAA, template.getSystemID(), 0, true, 0); template.addChildNode(mayaa); Set divided = null; if (isOptimizeEnabled()) { divided = new HashSet(); } walkParsedTree(template, stack, template, divided); if (template.equals(stack.peek()) == false) { throw new IllegalStateException(); } saveToCycle(template, template); }
From source file:org.apache.tajo.plan.rewrite.rules.FilterPushDownRule.java
@Override public LogicalNode visitGroupBy(FilterPushDownContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, GroupbyNode groupbyNode, Stack<LogicalNode> stack) throws TajoException { LogicalNode parentNode = stack.peek(); List<EvalNode> aggrEvals; if (parentNode.getType() == NodeType.HAVING) { aggrEvals = addHavingNode(context, plan, block, null, (HavingNode) parentNode, groupbyNode); } else {//from w w w . j a v a 2 s.co m aggrEvals = addHavingNode(context, plan, block, (UnaryNode) parentNode, null, groupbyNode); } if (aggrEvals != null) { // remove aggregation eval from conext context.pushingDownFilters.removeAll(aggrEvals); } List<EvalNode> notMatched = new ArrayList<>(); // transform Map<EvalNode, EvalNode> transformed = findCanPushdownAndTransform(context, block, groupbyNode, groupbyNode.getChild(), notMatched, null, 0); context.setFiltersTobePushed(transformed.keySet()); LogicalNode current = super.visitGroupBy(context, plan, block, groupbyNode, stack); context.setToOrigin(transformed); context.addFiltersTobePushed(notMatched); return current; }
From source file:org.sakaiproject.chat2.model.impl.ChatEntityProducer.java
/** * {@inheritDoc}/*from w w w .java2s . c om*/ */ public String archive(String siteId, Document doc, Stack stack, String archivePath, List attachments) { //prepare the buffer for the results log StringBuilder results = new StringBuilder(); int channelCount = 0; try { // start with an element with our very own (service) name Element element = doc.createElement(serviceName()); element.setAttribute(VERSION_ATTR, ARCHIVE_VERSION); ((Element) stack.peek()).appendChild(element); stack.push(element); Element chat = doc.createElement(ChatManager.CHAT); List channelList = getChatManager().getContextChannels(siteId, true); if (channelList != null && !channelList.isEmpty()) { Iterator channelIterator = channelList.iterator(); while (channelIterator.hasNext()) { ChatChannel channel = (ChatChannel) channelIterator.next(); Element channelElement = channel.toXml(doc, stack); chat.appendChild(channelElement); channelCount++; } results.append( "archiving " + getLabel() + ": (" + channelCount + ") channels archived successfully.\n"); } else { results.append("archiving " + getLabel() + ": empty chat room archived.\n"); } // archive the chat synoptic tool options archiveSynopticOptions(siteId, doc, chat); ((Element) stack.peek()).appendChild(chat); stack.push(chat); stack.pop(); } catch (Exception any) { logger.warn("archive: exception archiving service: " + serviceName()); } stack.pop(); return results.toString(); }
From source file:song.androidstudy.tracedump.java
public boolean dump(int stackLimit) { if (mTraceRecordList == null) { return false; }/* ww w. j a v a 2 s .co m*/ HashMap<Integer, Integer> knownFrame = new HashMap<Integer, Integer>(mTda.length); int maxStackLevel = 0; HashMap<Integer, Stack<StackFrame>> threadStackMap = null; Stack<StackFrame> threadStack = null; Long endtime, startTime; int i; boolean contextSwitch; // TODO Auto-generated method stub threadStackMap = new HashMap<Integer, Stack<StackFrame>>(mTda.length); for (i = 0; i < mTda.length; i++) { threadStackMap.put(mTda[i].getId(), new Stack<StackFrame>()); knownFrame.put(mTda[i].getId(), -1); } for (TimeLineView.Record record : mTraceRecordList) { TimeLineView.Block block = record.block; TimeLineView.Row row = record.row; MethodData data = block.getMethodData(); threadStack = threadStackMap.get(row.getId()); startTime = block.getStartTime(); endtime = block.getEndTime(); while (!threadStack.empty()) { if (threadStack.peek().endtime <= startTime) { // a function call returned if (threadStack.size() == knownFrame.get(row.getId())) { knownFrame.put(row.getId(), -1); } threadStack.pop(); } else { if (threadStack.peek().endtime < endtime) { System.out.println("stack prediction error!"); } break; } } if (!data.getClassName().equals("(context switch)")) { StackFrame frame = new StackFrame(); frame.className = data.getClassName(); frame.methodName = data.getMethodName(); frame.startTime = startTime; frame.endtime = endtime; contextSwitch = false; threadStack.push(frame); if (knownFrame.get(row.getId()) == -1) { if (knownMethod(data)) { knownFrame.put(row.getId(), threadStack.size()); } } } else { contextSwitch = true; } if (threadStack.size() > maxStackLevel) { maxStackLevel = threadStack.size(); } if (threadStack.size() <= stackLimit) { String name = data.getClassName() + '.' + data.getMethodName(); if (knownFrame.get(row.getId()) == -1 || knownFrame.get(row.getId()) == threadStack.size()) { if (!ignoreMethod(data)) { for (i = 0; i < threadStack.size(); i++) { System.out.print(" "); } System.out.println(name + " ::" + +block.getStartTime() + "::" + block.getEndTime() + "::" + threadStack.size() + "::" + row.getName()); } } } if (contextSwitch) { System.out.println("--------------------------"); } } System.out.println("max stack level is " + maxStackLevel); return true; }
From source file:org.sakaiproject.web.impl.WebServiceImpl.java
public String archive(String siteId, Document doc, Stack stack, String archivePath, List attachments) { StringBuilder results = new StringBuilder(); Base64 codec = new Base64(); try {/*from w w w . j a v a2 s.c o m*/ int count = 0; results.append("archiving " + getLabel() + " context " + Entity.SEPARATOR + siteId + Entity.SEPARATOR + SiteService.MAIN_CONTAINER + ".\n"); // start with an element with our very own (service) name Element element = doc.createElement(SERVICE_NAME); element.setAttribute(VERSION_ATTR, ARCHIVE_VERSION); ((Element) stack.peek()).appendChild(element); stack.push(element); if (siteId != null && siteId.trim().length() > 0) { Element webContentEl = doc.createElement(WEB_CONTENT); Site site = SiteService.getSite(siteId); List sitePages = site.getPages(); if (sitePages != null && !sitePages.isEmpty()) { Iterator pageIter = sitePages.iterator(); while (pageIter.hasNext()) { SitePage currPage = (SitePage) pageIter.next(); List toolList = currPage.getTools(); Iterator toolIter = toolList.iterator(); while (toolIter.hasNext()) { ToolConfiguration toolConfig = (ToolConfiguration) toolIter.next(); // we do not want to archive "special" uses of sakai.iframe, such as worksite info String special = toolConfig.getPlacementConfig().getProperty(SPECIAL_PROP); if (toolConfig.getToolId().equals(TOOL_ID) && special == null) { Element webContentData = doc.createElement(REDIRECT_TAB); count++; String contentUrl = toolConfig.getPlacementConfig() .getProperty(WEB_CONTENT_URL_PROP); String toolTitle = toolConfig.getTitle(); String pageTitle = currPage.getTitle(); String height = toolConfig.getPlacementConfig().getProperty(HEIGHT_PROP); webContentData.setAttribute(NEW_WINDOW, new Boolean(currPage.isPopUp()).toString()); try { String encoded = new String(codec.encode(contentUrl.getBytes("UTF-8")), "UTF-8"); webContentData.setAttribute(WEB_CONTENT_URL, encoded); } catch (Exception e) { M_log.warn("Encode Web Content URL - " + e); } try { String encoded = new String(codec.encode(toolTitle.getBytes("UTF-8")), "UTF-8"); webContentData.setAttribute(WEB_CONTENT_TITLE, encoded); } catch (Exception e) { M_log.warn("Encode Web Content Tool Title - " + e); } if (height != null) { webContentData.setAttribute(HEIGHT_PROP, height); } try { String encoded = new String(codec.encode(pageTitle.getBytes("UTF-8")), "UTF-8"); webContentData.setAttribute(PAGE_TITLE, encoded); } catch (Exception e) { M_log.warn("Encode Web Content Page Title - " + e); } if (height != null) { webContentData.setAttribute(HEIGHT_PROP, height); } webContentEl.appendChild(webContentData); } } } results.append("archiving " + getLabel() + ": (" + count + ") web content items archived successfully.\n"); } else { results.append("archiving " + getLabel() + ": empty web content archived.\n"); } ((Element) stack.peek()).appendChild(webContentEl); stack.push(webContentEl); } stack.pop(); } catch (DOMException e) { M_log.error(e.getMessage(), e); } catch (IdUnusedException e) { M_log.error(e.getMessage(), e); } catch (Exception e) { M_log.error(e.getMessage(), e); } return results.toString(); }
From source file:com.webcohesion.ofx4j.io.nanoxml.TestNanoXMLOFXReader.java
private DefaultHandler getNewDefaultHandler(final Map<String, List<String>> headers, final Stack<Map<String, List<Object>>> aggregateStack) { return new DefaultHandler() { @Override/*from w ww. j a v a 2s . c o m*/ public void onHeader(String name, String value) { LOG.debug(name + ":" + value); List<String> list = headers.get(name); if (list == null) { list = new ArrayList<String>(); headers.put(name, list); } list.add(value); } @Override public void onElement(String name, String value) { LOG.debug("onElement " + aggregateStack.size()); char[] tabs = new char[aggregateStack.size() * 2]; Arrays.fill(tabs, ' '); LOG.debug(new String(tabs) + name + "=" + value); List<Object> list = aggregateStack.peek().get(name); if (list == null) { list = new ArrayList<Object>(); aggregateStack.peek().put(name, list); } list.add(value); } @Override public void startAggregate(String aggregateName) { LOG.debug("startAggregate " + aggregateName + " " + aggregateStack.size()); char[] tabs = new char[aggregateStack.size() * 2]; Arrays.fill(tabs, ' '); LOG.debug(new String(tabs) + aggregateName + " {"); TreeMap<String, List<Object>> aggregate = new TreeMap<String, List<Object>>(); List<Object> list = aggregateStack.peek().get(aggregateName); if (list == null) { list = new ArrayList<Object>(); aggregateStack.peek().put(aggregateName, list); } list.add(aggregate); aggregateStack.push(aggregate); } @Override public void endAggregate(String aggregateName) { LOG.debug("endAggregate " + aggregateName + " " + aggregateStack.size()); aggregateStack.pop(); char[] tabs = new char[aggregateStack.size() * 2]; Arrays.fill(tabs, ' '); LOG.debug(new String(tabs) + "}"); } }; }
From source file:barrysw19.calculon.icc.ICCInterface.java
private List<ResponseBlockLv2> parseBlockResponseLv2(String lvl2String) { List<ResponseBlockLv2> rv = new ArrayList<>(); Stack<StringBuffer> allBlocks = new Stack<>(); for (int i = 0; i < lvl2String.length(); i++) { if (lvl2String.charAt(i) == ('Y' & 0x1F) && lvl2String.charAt(i + 1) == '(') { allBlocks.push(new StringBuffer()); i++;/* w w w. ja va 2 s . c om*/ continue; } if (lvl2String.charAt(i) == ('Y' & 0x1F) && lvl2String.charAt(i + 1) == ')') { rv.add(ResponseBlockLv2.createResponseBlock(allBlocks.pop().toString())); i++; continue; } allBlocks.peek().append(lvl2String.charAt(i)); } LOG.debug(String.valueOf(rv)); return rv; }