Example usage for java.util Stack Stack

List of usage examples for java.util Stack Stack

Introduction

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

Prototype

public Stack() 

Source Link

Document

Creates an empty Stack.

Usage

From source file:edu.kit.dama.mdm.dataorganization.impl.jpa.DataOrganizerImpl.java

/**
 * Build a tree for a digital object id from a list of DataOrganizationNode
 * obtained from a data source.//from w  w w  .  j  ava 2s .c o m
 *
 * @param nodes The list of nodes.
 * @param digitalObjectID The digital object id the tree is associated with.
 *
 * @return The tree.
 */
private FileTree buildTree(List<DataOrganizationNode> nodes, DigitalObjectId digitalObjectID) {

    FileTree tree = null;
    if (!nodes.isEmpty()) {
        Stack<DataOrganizationNode> stack = new Stack<>();
        DataOrganizationNode node = nodes.get(0);
        if (!(node instanceof CollectionNode)) {
            return null;
        }
        tree = new FileTree((CollectionNode) node);
        tree.setDigitalObjectId(digitalObjectID);
        node = tree;
        stack.push(node);
        DataOrganizationNode nextNode;
        for (int i = 1; i < nodes.size(); ++i) {
            nextNode = nodes.get(i);
            while (stack.peek().getStepNoLeaved() < nextNode.getStepNoLeaved()) {
                stack.pop();
            }
            node = stack.peek();
            ((CollectionNode) node).addChild(nextNode);
            stack.push(nextNode);
        }
    }
    return tree;
}

From source file:com.baifendian.swordfish.execserver.parameter.placeholder.CalculateUtil.java

/**
 * ???// w w  w  .  ja  v a2  s.c o  m
 *
 * @param inOrderList
 * @return ??
 */
private static List<String> getPostOrder(List<String> inOrderList) {
    List<String> result = new ArrayList<>();
    Stack<String> stack = new Stack<>();

    for (int i = 0; i < inOrderList.size(); i++) {
        if (Character.isDigit(inOrderList.get(i).charAt(0))) {
            result.add(inOrderList.get(i));
        } else {
            switch (inOrderList.get(i).charAt(0)) {
            case '(':
                stack.push(inOrderList.get(i));
                break;
            case ')':
                while (!stack.peek().equals("(")) {
                    result.add(stack.pop());
                }
                stack.pop();
                break;
            default:
                while (!stack.isEmpty() && compare(stack.peek(), inOrderList.get(i))) {
                    result.add(stack.pop());
                }
                stack.push(inOrderList.get(i));
                break;
            }
        }
    }

    while (!stack.isEmpty()) {
        result.add(stack.pop());
    }

    return result;
}

From source file:org.ojai.json.impl.JsonStreamDocumentReader.java

JsonStreamDocumentReader(JsonDocumentStream stream) {
    containerStack = new Stack<ContainerContext>();
    cachedTokens = new LinkedList<JsonToken>();
    documentStream = stream;/*from  w  w w. ja va 2s  . c  om*/
    mapLevel = 0;
    eor = false;
}

From source file:org.mitre.jdbc.datasource.util.SqlFileParser.java

/**
 * Constructor takes a Spring {@link Resource}
 * //w  w w. j av  a  2  s .  com
 * @param resource
 *            the initial file to parse
 */
public SqlFileParser(Resource resource) {
    stateStack = new Stack<State>();
    this.resource = resource;
}

From source file:de.se_rwth.langeditor.util.Misc.java

public static <T> Stream<T> preorder(T start, Function<T, Collection<? extends T>> generatingFunction) {
    List<T> elements = new ArrayList<>();
    Stack<T> stack = new Stack<>();
    stack.push(start);// www .  ja  v  a2  s  .c  om
    T currentElement;
    while (!stack.isEmpty()) {
        currentElement = stack.pop();
        elements.add(currentElement);
        stack.addAll(generatingFunction.apply(currentElement));
    }
    return elements.stream();
}

From source file:edu.uci.ics.jung.algorithms.cluster.BicomponentClusterer.java

/**
* Extracts the bicomponents from the graph.
* @param theGraph the graph whose bicomponents are to be extracted
* @return the <code>ClusterSet</code> of bicomponents
*//*from  w ww. jav  a 2  s . c om*/
public Set<Set<V>> transform(UndirectedGraph<V, E> theGraph) {
    Set<Set<V>> bicomponents = new LinkedHashSet<Set<V>>();

    if (theGraph.getVertices().isEmpty())
        return bicomponents;

    // initialize DFS number for each vertex to 0
    dfs_num = new HashMap<V, Number>();
    for (V v : theGraph.getVertices()) {
        dfs_num.put(v, 0);
    }

    for (V v : theGraph.getVertices()) {
        if (dfs_num.get(v).intValue() == 0) // if we haven't hit this vertex yet...
        {
            high = new HashMap<V, Number>();
            stack = new Stack<E>();
            parents = new HashMap<V, V>();
            converse_depth = theGraph.getVertexCount();
            // find the biconnected components for this subgraph, starting from v
            findBiconnectedComponents(theGraph, v, bicomponents);

            // if we only visited one vertex, this method won't have
            // ID'd it as a biconnected component, so mark it as one
            if (theGraph.getVertexCount() - converse_depth == 1) {
                Set<V> s = new HashSet<V>();
                s.add(v);
                bicomponents.add(s);
            }
        }
    }

    return bicomponents;
}

From source file:architecture.common.util.profiling.Profiler.java

public Profiler() {
    stack = new Stack<ProfileInstance>();
}

From source file:com.espertech.esper.event.util.JSONRendererImpl.java

/**
 * Ctor./*from w w  w.j  av a2  s.com*/
 * @param eventType type of event(s)
 * @param options rendering options
 */
public JSONRendererImpl(EventType eventType, JSONRenderingOptions options) {
    EventPropertyRenderer propertyRenderer = null;
    EventPropertyRendererContext propertyRendererContext = null;
    if (options.getRenderer() != null) {
        propertyRenderer = options.getRenderer();
        propertyRendererContext = new EventPropertyRendererContext(eventType, true);
    }

    rendererOptions = new RendererMetaOptions(options.isPreventLooping(), false, propertyRenderer,
            propertyRendererContext);
    meta = new RendererMeta(eventType, new Stack<EventTypePropertyPair>(), rendererOptions);
}

From source file:app.web.Application2ITCase.java

@Test
public void testApplication() {
    //goToHomepage();
    selenium.open(APPLICATION_HOMEPAGE);
    Stack<Action> actionStack = new Stack<Action>();
    actionStack.push(Action.open(APPLICATION_HOMEPAGE));
    testPageRecursively(actionStack);/*from w w w .j  av a2  s  . co  m*/
}

From source file:app.web.ApplicationITCase.java

@Test
public void testApplication() {
    //goToHomepage();
    selenium.open(APPLICATION_HOMEPAGE);
    Stack<URL> locationStack = new Stack<URL>();
    locationStack.push(toLocationPath(APPLICATION_HOMEPAGE));
    testPageRecursively(locationStack);//from  w  w  w.j av  a  2 s.  c  o  m
}