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:net.bulletin.pdi.xero.step.support.XMLChunkerImpl.java

@Override
public String pullNextXmlChunk() throws KettleException {
    Stack<String> elementStack = xmlChunkerState.getElementStack();
    XMLStreamReader xmlStreamReader = xmlChunkerState.getXmlStreamReader();

    try {// w w  w .  j  a  va 2s. c o  m

        while (xmlStreamReader.hasNext()) {

            switch (xmlStreamReader.next()) {

            case XMLStreamConstants.END_DOCUMENT:
                return null;

            case XMLStreamConstants.END_ELEMENT:
                elementStack.pop();
                break;

            case XMLStreamConstants.START_ELEMENT:
                elementStack.push(xmlStreamReader.getLocalName());

                if (actualElementStackHasExpectedElements(xmlChunkerState)) {
                    return pullNextXmlChunkFromTopElementOnStack(xmlChunkerState);
                }

                break;

            }

        }
    } catch (Exception e) {
        throw new KettleException("a problem has arisen reading the xero xml stream", e);
    }

    return null;
}

From source file:net.sf.eventgraphj.centrality.EgoNetworkBetweennessCentrality.java

protected void computeBetweenness(Queue<V> queue, Transformer<E, ? extends Number> edge_weights) {
    for (V v : graph.getVertices()) {
        // initialize the betweenness data for this new vertex
        for (V s : graph.getVertices())
            this.vertex_data.put(s, new BetweennessData());

        //         if (v.equals(new Integer(0)))
        //            System.out.println("pause");

        vertex_data.get(v).numSPs = 1;//from   ww w .j av  a 2s  . c  o  m
        vertex_data.get(v).distance = 0;

        Stack<V> stack = new Stack<V>();
        //            Buffer<V> queue = new UnboundedFifoBuffer<V>();
        //            queue.add(v);
        queue.offer(v);

        while (!queue.isEmpty()) {
            //                V w = queue.remove();
            V w = queue.poll();
            stack.push(w);
            BetweennessData w_data = vertex_data.get(w);
            for (E e : graph.getOutEdges(w)) {
                // TODO (jrtom): change this to getOtherVertices(w, e)
                V x = graph.getOpposite(w, e);
                if (x.equals(w))
                    continue;
                double wx_weight = edge_weights.transform(e).doubleValue();

                //                for(V x : graph.getSuccessors(w)) 
                //                {
                //                   if (x.equals(w))
                //                      continue;

                // FIXME: the other problem is that I need to 
                // keep putting the neighbors of things we've just 
                // discovered in the queue, if they're undiscovered or
                // at greater distance.

                // FIXME: this is the problem, right here, I think: 
                // need to update position in queue if distance changes
                // (which can only happen with weighted edges).
                // for each outgoing edge e from w, get other end x
                // if x not already visited (dist x < 0)
                //   set x's distance to w's dist + edge weight
                //   add x to queue; pri in queue is x's dist
                // if w's dist + edge weight < x's dist 
                //   update x's dist
                //   update x in queue (MapBinaryHeap)
                //   clear x's incoming edge list
                // if w's dist + edge weight = x's dist
                //   add e to x's incoming edge list

                BetweennessData x_data = vertex_data.get(x);
                double x_potential_dist = w_data.distance + wx_weight;
                if (x_potential_dist > this.egoNetworkSize)
                    continue;

                if (x_data.distance < 0) {
                    //                        queue.add(x);
                    //                        vertex_data.get(x).distance = vertex_data.get(w).distance + 1;
                    x_data.distance = x_potential_dist;
                    queue.offer(x);
                }

                // note:
                // (1) this can only happen with weighted edges
                // (2) x's SP count and incoming edges are updated below 
                if (x_data.distance > x_potential_dist) {
                    x_data.distance = x_potential_dist;
                    // invalidate previously identified incoming edges
                    // (we have a new shortest path distance to x)
                    x_data.incomingEdges.clear();
                    // update x's position in queue
                    ((MapBinaryHeap<V>) queue).update(x);
                }
                //                  if (vertex_data.get(x).distance == vertex_data.get(w).distance + 1) 
                // 
                //                    if (x_data.distance == x_potential_dist) 
                //                    {
                //                        x_data.numSPs += w_data.numSPs;
                ////                        vertex_data.get(x).predecessors.add(w);
                //                        x_data.incomingEdges.add(e);
                //                    }
            }
            for (E e : graph.getOutEdges(w)) {
                V x = graph.getOpposite(w, e);
                if (x.equals(w))
                    continue;
                double e_weight = edge_weights.transform(e).doubleValue();
                BetweennessData x_data = vertex_data.get(x);
                double x_potential_dist = w_data.distance + e_weight;
                if (x_data.distance == x_potential_dist) {
                    x_data.numSPs += w_data.numSPs;
                    //                        vertex_data.get(x).predecessors.add(w);
                    x_data.incomingEdges.add(e);
                }
            }
        }
        while (!stack.isEmpty()) {
            V x = stack.pop();

            //              for (V w : vertex_data.get(x).predecessors) 
            for (E e : vertex_data.get(x).incomingEdges) {
                V w = graph.getOpposite(x, e);
                double partialDependency = vertex_data.get(w).numSPs / vertex_data.get(x).numSPs
                        * (1.0 + vertex_data.get(x).dependency);
                vertex_data.get(w).dependency += partialDependency;
                //                  E w_x = graph.findEdge(w, x);
                //                  double w_x_score = edge_scores.get(w_x).doubleValue();
                //                  w_x_score += partialDependency;
                //                  edge_scores.put(w_x, w_x_score);
                double e_score = edge_scores.get(e).doubleValue();
                edge_scores.put(e, e_score + partialDependency);
            }
            if (!x.equals(v)) {
                double x_score = vertex_scores.get(x).doubleValue();
                x_score += vertex_data.get(x).dependency;
                vertex_scores.put(x, x_score);
            }
        }
    }

    if (graph instanceof UndirectedGraph) {
        for (V v : graph.getVertices()) {
            double v_score = vertex_scores.get(v).doubleValue();
            v_score /= 2.0;
            vertex_scores.put(v, v_score);
        }
        for (E e : graph.getEdges()) {
            double e_score = edge_scores.get(e).doubleValue();
            e_score /= 2.0;
            edge_scores.put(e, e_score);
        }
    }

    vertex_data.clear();
}

From source file:com.amazonaws.services.kinesis.scaling.StreamScaler.java

private Stack<ShardHashInfo> getOpenShardStack(String streamName) throws Exception {
    // populate the stack with the current set of shards
    Stack<ShardHashInfo> shardStack = new Stack<>();
    List<ShardHashInfo> shards = new ArrayList<>(StreamScalingUtils
            .getOpenShards(this.kinesisClient, streamName, SortOrder.DESCENDING, null).values());
    for (ShardHashInfo s : shards) {
        shardStack.push(s);
    }//from  ww w .jav a  2 s. c  o  m

    return shardStack;
}

From source file:org.apache.hadoop.hive.ql.parse.TezCompiler.java

private void connect(Operator<?> o, AtomicInteger index, Stack<Operator<?>> nodes,
        Map<Operator<?>, Integer> indexes, Map<Operator<?>, Integer> lowLinks,
        Set<Set<Operator<?>>> components) {

    indexes.put(o, index.get());/*ww  w  .  j  a  v  a2  s  .  co  m*/
    lowLinks.put(o, index.get());
    index.incrementAndGet();
    nodes.push(o);

    List<Operator<?>> children;
    if (o instanceof AppMasterEventOperator) {
        children = new ArrayList<Operator<?>>();
        children.addAll(o.getChildOperators());
        TableScanOperator ts = ((DynamicPruningEventDesc) o.getConf()).getTableScan();
        LOG.debug("Adding special edge: " + o.getName() + " --> " + ts.toString());
        children.add(ts);
    } else {
        children = o.getChildOperators();
    }

    for (Operator<?> child : children) {
        if (!indexes.containsKey(child)) {
            connect(child, index, nodes, indexes, lowLinks, components);
            lowLinks.put(o, Math.min(lowLinks.get(o), lowLinks.get(child)));
        } else if (nodes.contains(child)) {
            lowLinks.put(o, Math.min(lowLinks.get(o), indexes.get(child)));
        }
    }

    if (lowLinks.get(o).equals(indexes.get(o))) {
        Set<Operator<?>> component = new HashSet<Operator<?>>();
        components.add(component);
        Operator<?> current;
        do {
            current = nodes.pop();
            component.add(current);
        } while (current != o);
    }
}

From source file:com.opengamma.master.portfolio.ManageablePortfolioNode.java

/**
 * Finds the stack of nodes from the tree below this node by identifier.
 * /*w ww .  j  a  va2 s.com*/
 * @param stack  the stack of nodes, not null
 * @param nodeObjectId  the node object identifier, not null
 * @return the node with the identifier, null if not found
 */
private Stack<ManageablePortfolioNode> findNodeStackByObjectId0(final Stack<ManageablePortfolioNode> stack,
        final ObjectId nodeObjectId) {
    stack.push(this);
    if (getUniqueId().equalObjectId(nodeObjectId)) {
        return stack;
    }
    for (ManageablePortfolioNode childNode : getChildNodes()) {
        Stack<ManageablePortfolioNode> found = childNode.findNodeStackByObjectId0(stack, nodeObjectId);
        if (found != null) {
            return found;
        }
    }
    stack.pop();
    return null;
}

From source file:FunctionParser.MathExp2SPARQL.java

private String prefixToInfix(Stack<String> stack, Stack<String> infixstack) {
    String s;//from   w  w w.j ava 2 s  . c om
    while (!stack.isEmpty()) {
        s = stack.pop();

        if (opmap.containsValue(s)) {
            String pop1 = infixstack.pop();
            String pop2 = infixstack.pop();
            //System.out.println(pop1 + s +pop2);
            if (s.equals("=="))
                s = "=";
            String nelem = "( " + pop1 + " " + s + " " + pop2 + " )";
            infixstack.push(nelem);
        } else if (s.equals("CEIL")) {
            String nelem = "CEIL" + infixstack.pop();
            infixstack.push(nelem);
        } else {
            infixstack.add(s);
        }
    }

    return infixstack.toString();
}

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.
 *//*w  w w . ja  va  2 s .  c om*/
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;
}

From source file:forestry.core.gui.GuiAlyzer.java

protected final void drawAnalyticsPageClassification(IIndividual individual) {

    startPage();/*from   w  w w. ja v  a2s  .  c o m*/

    drawLine(StringUtil.localize("gui.alyzer.classification") + ":", 12);
    newLine();

    Stack<IClassification> hierarchy = new Stack<IClassification>();
    IClassification classification = individual.getGenome().getPrimary().getBranch();
    while (classification != null) {

        if (classification.getScientific() != null && !classification.getScientific().isEmpty())
            hierarchy.push(classification);
        classification = classification.getParent();
    }

    boolean overcrowded = hierarchy.size() > 5;
    int x = 12;
    IClassification group = null;

    while (!hierarchy.isEmpty()) {

        group = hierarchy.pop();
        if (overcrowded && group.getLevel().isDroppable())
            continue;

        drawLine(group.getScientific(), x, group.getLevel().getColour());
        drawLine(group.getLevel().name(), 155, group.getLevel().getColour());
        newLine();
        x += 10;
    }

    // Add the species name
    String binomial = individual.getGenome().getPrimary().getBinomial();
    if (group != null && group.getLevel() == EnumClassLevel.GENUS)
        binomial = group.getScientific().substring(0, 1) + ". " + binomial.toLowerCase(Locale.ENGLISH);

    drawLine(binomial, x, 0xebae85);
    drawLine("SPECIES", 155, 0xebae85);

    newLine();
    newLine();
    drawLine(StringUtil.localize("gui.alyzer.authority") + ": "
            + individual.getGenome().getPrimary().getAuthority(), 12);
    if (AlleleManager.alleleRegistry.isBlacklisted(individual.getIdent())) {
        String extinct = ">> " + StringUtil.localize("gui.alyzer.extinct").toUpperCase() + " <<";
        fontRendererObj.drawStringWithShadow(extinct,
                adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth(extinct),
                adjustToFactor(guiTop + getLineY()), fontColor.get("gui.beealyzer.dominant"));
    }

    newLine();
    String description = individual.getGenome().getPrimary().getDescription();
    if (StringUtils.isBlank(description) || description.startsWith("for.description."))
        drawSplitLine(StringUtil.localize("gui.alyzer.nodescription"), 12, 208, 0x666666);
    else {
        String tokens[] = description.split("\\|");
        drawSplitLine(tokens[0], 12, 208, 0x666666);
        if (tokens.length > 1)
            fontRendererObj.drawStringWithShadow("- " + tokens[1],
                    adjustToFactor(guiLeft + 208) - fontRendererObj.getStringWidth("- " + tokens[1]),
                    adjustToFactor(guiTop + 145 - 14), 0x99cc32);
    }

    endPage();

}

From source file:de.tap.easy_xkcd.fragments.comics.FavoritesFragment.java

public void importFavorites(Intent intent) {
    String filePath = intent.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
    try {/* w w w  . j  av a  2s  .  c  o m*/
        File file = new File(filePath);
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String line;

        Stack<Integer> newFavorites = new Stack<>();
        while ((line = bufferedReader.readLine()) != null) {
            String[] numberTitle = line.split(" - ");
            int number = Integer.parseInt(numberTitle[0]);
            if (Arrays.binarySearch(favorites, number) < 0) {
                newFavorites.push(number);
                databaseManager.setFavorite(number, true);
                if (number <= ((MainActivity) getActivity()).getDatabaseManager().getHighestInDatabase())
                    ((MainActivity) getActivity()).getDatabaseManager().setFavorite(number, true);
            }
            if (!prefHelper.fullOfflineEnabled()) {
                new DownloadImageTask(newFavorites).execute();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getActivity(), "Import failed", Toast.LENGTH_SHORT).show();
    }
}

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++;/*from  w ww .j  a  v  a  2s  .  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;
}