Example usage for java.util Stack peek

List of usage examples for java.util Stack peek

Introduction

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

Prototype

public synchronized E peek() 

Source Link

Document

Looks at the object at the top of this stack without removing it from the stack.

Usage

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitSimpleTableSubquery(Context ctx, Stack<Expr> stack, SimpleTableSubquery expr)
        throws TajoException {
    if (stack.peek().getType() == OpType.InPredicate) {
        // In the case of in-subquery, stop visiting because the subquery expr is not expression.
        return new SubqueryEval((TableSubQueryNode) ctx.currentBlock.getNodeFromExpr(expr));
    } else {/* w  w  w .  j a v a 2  s .  com*/
        return super.visitSimpleTableSubquery(ctx, stack, expr);
    }
}

From source file:org.apache.oodt.cas.cli.construct.StdCmdLineConstructor.java

public Set<CmdLineOptionInstance> construct(CmdLineIterable<ParsedArg> parsedArgs,
        Set<CmdLineOption> validOptions) throws CmdLineConstructionException {
    HashSet<CmdLineOptionInstance> optionInstances = new HashSet<CmdLineOptionInstance>();

    Stack<CmdLineOptionInstance> groupOptions = new Stack<CmdLineOptionInstance>();
    for (ParsedArg arg : parsedArgs) {

        if (arg.getType().equals(ParsedArg.Type.OPTION)) {

            // check if option is a valid one
            CmdLineOption option = getOptionByName(arg.getName(), validOptions);
            if (option == null) {
                throw new CmdLineConstructionException("Invalid option: '" + arg.getName() + "'");
            }//from   w  w w. j av  a2 s  .  co  m

            // read found option
            CmdLineOptionInstance specifiedOption = getOption(parsedArgs, option);

            // Check if we are currently loading subOptions.
            if (!groupOptions.isEmpty()) {

                CmdLineOptionInstance currentGroup = groupOptions.peek();

                // Check if option is NOT a subOption for current group.
                if (!isSubOption(currentGroup.getOption(), option)) {

                    // Check if current group was expecting more subOptions.
                    Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
                    if (!requiredSubOptions.isEmpty()) {
                        throw new CmdLineConstructionException(
                                "Missing the following required subOptions for '" + currentGroup.getOption()
                                        + "': " + sortOptionsByRequiredStatus(requiredSubOptions));

                    } else if (currentGroup.getSubOptions().isEmpty()) {
                        throw new CmdLineConstructionException(
                                "Must specify a subOption for group option '" + currentGroup.getOption() + "'");

                    } else {

                        // pop group and add to list of specified options.
                        optionInstances.add(groupOptions.pop());
                    }
                    // It is a sub-option...
                } else {

                    // Add option to current group subOptions.
                    currentGroup.addSubOption(specifiedOption);
                    continue;

                }
            }

            if (option instanceof GroupCmdLineOption) {

                // Push group as current group.
                groupOptions.push(specifiedOption);

                if (!parsedArgs.hasNext()) {
                    throw new CmdLineConstructionException(
                            "Must specify a subOption for group option '" + specifiedOption.getOption() + "'");
                }
            } else if (option.isSubOption()) {
                throw new CmdLineConstructionException(
                        "Option '" + option + "' is a subOption, but was used at top level Option");

            } else {

                // Option good to go.
                optionInstances.add(specifiedOption);
            }
        } else {
            throw new CmdLineConstructionException("Invalid argument: '" + arg + "'");
        }
    }
    while (!groupOptions.isEmpty()) {
        CmdLineOptionInstance currentGroup = groupOptions.pop();
        Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
        if (!requiredSubOptions.isEmpty()) {
            throw new CmdLineConstructionException("Missing the following required subOptions for '"
                    + currentGroup.getOption() + "': " + sortOptionsByRequiredStatus(requiredSubOptions));

        } else {
            optionInstances.add(currentGroup);
        }
    }
    return optionInstances;
}

From source file:padl.creator.cppfile.eclipse.plugin.internal.GeneratorHelper.java

private void addFunctionToModelOrMethodToClass(final Accumulator anAccumulator, final ICPPFunction aCPPFunction,
        final IASTStatement aBodyStatement, final Stack<IContainer> someContainers) {

    final IContainer container = someContainers.peek();

    // Yann 2014/04/17: Const-ness
    // It is annoying to manage const-ness so, right now,
    // I remove any trace of it... Could do better?
    // Similarly, I cannot deal with ellipses currently.
    // For some reasons, sometimes CDT adds the string
    // CPPMETHOD at the end of a function signature,
    // when the aCPPFunction is a PDOMCPPMethod.
    final String stringID = String.valueOf(Utils.computeSignature(aCPPFunction));
    final char[] id = stringID.replaceAll("const ", "").replaceAll(", \\.\\.\\.", "")
            .replaceAll(" CPPMETHOD", "").replaceAll("/", "US").replaceAll("#", "NUM").toCharArray();

    final char[] name;
    try {/* w w  w .  ja v  a2s . c  om*/
        name = Utils.getSimpleName(aCPPFunction.getQualifiedNameCharArray());
    } catch (final DOMException e) {
        e.printStackTrace(ProxyConsole.getInstance().errorOutput());
        throw new RuntimeException(e);
    }

    // Yann 2013/07/19: Duplication in case of problem
    // It is possible to have duplicate constituents in the model
    // in case of problematic parameter types, for example:
    //   operator <<(? &, const ? &)
    // is the ID of both
    //   operator <<(A &, const B &)
    // and
    //   operator <<(C &, const D &)
    // if A, B, C, and D are all problematic! So, yes, here it is
    // okay to check for duplication because there would be no
    // way to distinguish one from the other, is there?
    // Although I don't want to create twice the "same"
    // operation, I must add it to the accumulator for
    // later proper retrieval of the operation associated
    // with the ICPPFunction.
    if (container.doesContainConstituentWithID(id)) {
        // Ugly duplication with similar code at the
        // end of this method... TODO Remove duplication
        final IOperation padlFunction = (IOperation) container.getConstituentFromID(id);
        if (container instanceof IFirstClassEntity) {
            anAccumulator.addFunction(aCPPFunction, (IFirstClassEntity) container, padlFunction);
        } else {
            anAccumulator.addFunction(aCPPFunction, null, padlFunction);
        }
        return;
    }

    final char[] returnTypeName = Utils.getInterestingTypeName(aCPPFunction.getType().getReturnType())
            .toCharArray();

    final IOperation padlFunction;
    // Yann 2013/06/27: Method vs. Function
    // Right now, I only build methods (constructor, destructor, and method)
    // when the enclosing first-class entity exists, else I built a function.
    if (aCPPFunction instanceof ICPPConstructor) {
        padlFunction = ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance()).createConstructor(id, name);
        Utils.setVisibility(padlFunction, (ICPPMember) aCPPFunction);
    } else if (aCPPFunction instanceof ICPPMethod && ((ICPPMethod) aCPPFunction).isDestructor()) {

        padlFunction = ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance()).createDestructor(id, name);
        Utils.setVisibility(padlFunction, (ICPPMember) aCPPFunction);
    } else if (aCPPFunction instanceof ICPPMethod) {
        padlFunction = ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance()).createMethod(id, name);
        // Create the return type if it does not exist.
        final IEntity returnTypeEntity = SearchHelper.getExistingContainerOrCreateGhost(this.codeLevelModel,
                someContainers, returnTypeName, false);
        ((IMethod) padlFunction).setReturnType(returnTypeEntity.getName());
        Utils.setVisibility(padlFunction, (ICPPMember) aCPPFunction);
    } else if (aCPPFunction instanceof ICPPFunction) {
        // Global function
        padlFunction = ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance()).createGlobalFunction(id, name);
        ((IGlobalFunction) padlFunction).setReturnType(returnTypeName);
    } else {
        padlFunction = null;
        Utils.reportUnknownType(GeneratorHelper.class, "operation", id, aCPPFunction.getClass());
    }

    padlFunction.setStatic(aCPPFunction.isStatic());

    if (container instanceof IFirstClassEntity) {
        anAccumulator.addFunction(aCPPFunction, (IFirstClassEntity) container, padlFunction);
    } else {
        anAccumulator.addFunction(aCPPFunction, null, padlFunction);
    }

    // Yann 2014/0417: Anti-patterns!
    // I need to set the lines of code of the methods
    // to allow the identification of some anti-patterns
    // like LongMethod and SpaghettiCode. This seems the
    // best place to do so :-)
    Utils.addStatementsToFunction(aBodyStatement, padlFunction);

    container.addConstituent(padlFunction);
}

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

@SuppressWarnings("unchecked")
@Override/*from  w  w w  . j  ava  2s  . 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:org.sakaiproject.tool.rutgers.LinkToolEntityProducer.java

/**
 * {@inheritDoc}/*from  w  w w .  j a  v a2  s  .  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();

    try {
        Site site = SiteService.getSite(siteId);
        // 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 linktool = doc.createElement(LINKTOOL);
        Collection<ToolConfiguration> tools = site.getTools(myToolIds());
        if (tools != null && !tools.isEmpty()) {
            for (ToolConfiguration config : tools) {
                element = doc.createElement(LINKTOOL);

                Attr attr = doc.createAttribute("toolid");
                attr.setValue(config.getToolId());
                element.setAttributeNode(attr);

                attr = doc.createAttribute("name");
                attr.setValue(config.getContainingPage().getTitle());
                element.setAttributeNode(attr);

                Properties props = config.getConfig();
                if (props == null)
                    continue;

                String url = props.getProperty("url", null);
                if (url == null && props != null) {
                    String urlProp = props.getProperty("urlProp", null);
                    if (urlProp != null) {
                        url = ServerConfigurationService.getString(urlProp);
                    }
                }

                attr = doc.createAttribute("url");
                attr.setValue(url);
                element.setAttributeNode(attr);

                String height = "600";
                String heights = props.getProperty("height", "600");
                if (heights != null) {
                    heights = heights.trim();
                    if (heights.endsWith("px"))
                        heights = heights.substring(0, heights.length() - 2).trim();
                    height = heights;
                }

                attr = doc.createAttribute("height");
                attr.setValue(height);
                element.setAttributeNode(attr);

                linktool.appendChild(element);
            }

            results.append("archiving " + getLabel() + ": (" + tools.size()
                    + ") linktool instances archived successfully.\n");

        } else {
            results.append("archiving " + getLabel() + ": no linktools.\n");
        }

        ((Element) stack.peek()).appendChild(linktool);
        stack.push(linktool);

        stack.pop();
    } catch (Exception any) {
        logger.warn("archive: exception archiving service: " + serviceName());
    }

    stack.pop();

    return results.toString();
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

private ThriftIO peekIOStack() throws TException {
    Stack<ThriftIO> stack = threadSafeSIOStack.get();
    return stack.peek();
}

From source file:org.apache.solr.handler.JsonLoader.java

SolrInputDocument parseDoc(int ev) throws IOException {
    Stack<Object> stack = new Stack<Object>();
    Object obj = null;/*  w  w w  .  j  av a  2s .  c  o m*/
    boolean inArray = false;

    if (ev != JSONParser.OBJECT_START) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "object should already be started");
    }

    while (true) {
        //System.out.println( ev + "["+JSONParser.getEventString(ev)+"] "+parser.wasKey() ); //+ parser.getString() );

        switch (ev) {
        case JSONParser.STRING:
            if (parser.wasKey()) {
                obj = stack.peek();
                String v = parser.getString();
                if (obj instanceof SolrInputField) {
                    SolrInputField field = (SolrInputField) obj;
                    if ("boost".equals(v)) {
                        ev = parser.nextEvent();
                        if (ev != JSONParser.NUMBER && ev != JSONParser.LONG && ev != JSONParser.BIGNUMBER) {
                            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                                    "boost should have number! " + JSONParser.getEventString(ev));
                        }
                        field.setBoost((float) parser.getDouble());
                    } else if ("value".equals(v)) {
                        // nothing special...
                        stack.push(field); // so it can be popped
                    } else {
                        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                                "invalid key: " + v + " [" + parser.getPosition() + "]");
                    }
                } else if (obj instanceof SolrInputDocument) {
                    SolrInputDocument doc = (SolrInputDocument) obj;
                    SolrInputField f = doc.get(v);
                    if (f == null) {
                        f = new SolrInputField(v);
                        doc.put(f.getName(), f);
                    }
                    stack.push(f);
                } else {
                    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                            "hymmm [" + parser.getPosition() + "]");
                }
            } else {
                addValToField(stack, parser.getString(), inArray, parser);
            }
            break;

        case JSONParser.LONG:
        case JSONParser.NUMBER:
        case JSONParser.BIGNUMBER:
            addValToField(stack, parser.getNumberChars().toString(), inArray, parser);
            break;

        case JSONParser.BOOLEAN:
            addValToField(stack, parser.getBoolean(), inArray, parser);
            break;

        case JSONParser.NULL:
            parser.getNull();
            /*** if we wanted to remove the field from the document now...
            if (!inArray) {
              Object o = stack.peek();
              // if null was only value in the field, then remove the field
              if (o instanceof SolrInputField) {
                SolrInputField sif = (SolrInputField)o;
                if (sif.getValueCount() == 0) {
                  sdoc.remove(sif.getName());
                }
              }
            }
            ***/

            addValToField(stack, null, inArray, parser);
            break;

        case JSONParser.OBJECT_START:
            if (stack.isEmpty()) {
                stack.push(new SolrInputDocument());
            } else {
                obj = stack.peek();
                if (obj instanceof SolrInputField) {
                    // should alreay be pushed...
                } else {
                    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                            "should not start new object with: " + obj + " [" + parser.getPosition() + "]");
                }
            }
            break;
        case JSONParser.OBJECT_END:
            obj = stack.pop();
            if (obj instanceof SolrInputDocument) {
                return (SolrInputDocument) obj;
            } else if (obj instanceof SolrInputField) {
                // should already be pushed...
            } else {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                        "should not start new object with: " + obj + " [" + parser.getPosition() + "]");
            }
            break;

        case JSONParser.ARRAY_START:
            inArray = true;
            break;

        case JSONParser.ARRAY_END:
            inArray = false;
            stack.pop(); // the val should have done it...
            break;

        default:
            System.out.println("UNKNOWN_EVENT_ID:" + ev);
            break;
        }

        ev = parser.nextEvent();
        if (ev == JSONParser.EOF) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "should finish doc first!");
        }
    }
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

@Override
public TList readListBegin() throws TException {
    //System.out.println("readListBegin");

    // Get the IO Stack
    Stack<ThriftIO> stack = threadSafeSIOStack.get();

    ThriftIO currentIO = stack.peek();
    ThriftFieldMetadata thriftFieldMetadata = currentIO.fieldsStack.peek();

    // field related to the list
    ListMetaData listMetaData = (ListMetaData) thriftFieldMetadata.fieldMetaData.valueMetaData;

    // extract the DBList
    BasicDBList dbList = (BasicDBList) currentIO.mongoIO.get(currentIO.fieldsStack.peek().tfield.name);

    ThriftIO thriftListIO = null;/*from w  ww  . jav  a2  s .com*/
    if (listMetaData.elemMetaData.isStruct()) {
        thriftListIO = new ThriftIO(((StructMetaData) listMetaData.elemMetaData).structClass, dbList, null,
                false, true);
    } else {
        thriftListIO = new ThriftIO(null, dbList, null, false, true);
    }

    stack.push(thriftListIO);
    threadSafeSIOStack.set(stack);

    return new TList(TType.LIST, dbList.size());
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

@Override
public TSet readSetBegin() throws TException {
    //System.out.println("readSetBegin");

    // Get the IO Stack
    Stack<ThriftIO> stack = threadSafeSIOStack.get();

    ThriftIO currentIO = stack.peek();
    ThriftFieldMetadata thriftFieldMetadata = currentIO.fieldsStack.peek();

    // field related to the list
    SetMetaData setMetaData = (SetMetaData) thriftFieldMetadata.fieldMetaData.valueMetaData;

    // extract the DBList
    BasicDBList dbList = (BasicDBList) currentIO.mongoIO.get(currentIO.fieldsStack.peek().tfield.name);

    ThriftIO thriftListIO = null;//  w ww . j av  a2  s  .  c  o m
    if (setMetaData.elemMetaData.isStruct()) {
        thriftListIO = new ThriftIO(((StructMetaData) setMetaData.elemMetaData).structClass, dbList, null,
                false, true);
    } else {
        thriftListIO = new ThriftIO(null, dbList, null, false, true);
    }

    stack.push(thriftListIO);
    threadSafeSIOStack.set(stack);

    return new TSet(TType.SET, dbList.size());
}

From source file:com.google.dart.compiler.metrics.Tracer.java

public void markTimelineImpl(String message) {
    Stack<TraceEvent> threadPendingEvents = pendingEvents.get();
    TraceEvent parent = null;//from www. ja v  a2 s  . c o m
    if (!threadPendingEvents.isEmpty()) {
        parent = threadPendingEvents.peek();
    }
    TraceEvent newEvent = new MarkTimelineEvent(parent);
    threadPendingEvents.push(newEvent);
    newEvent.end("message", message);
}