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:com.blogspot.jadecalyx.webtools.jcPageObjectHelper.java

private Stack<jcPageObjectSet> expandLookupDetails(List<jcPageObjectSet> returnSet,
        List<jcPageObjectSet> incomingSet) {
    if (returnSet == null) {
        returnSet = new Stack<>();
    }/*w ww  .j  ava2  s  .c o  m*/
    while (incomingSet.size() > 0) {
        jcPageObjectSet currSet = incomingSet.get(incomingSet.size() - 1);
        incomingSet.remove(incomingSet.size() - 1);
        if (currSet.GetType().equals("css")) {
            returnSet.add(currSet);
        } else {
            if (currSet.GetType().equals("handle")) {
                List<jcPageObjectSet> expandedSet = GetLookupDetails(currSet.GetDetails());
                while (expandedSet.size() > 0) {
                    returnSet.add(expandedSet.get(expandedSet.size() - 1));
                    expandedSet.remove(expandedSet.size() - 1);
                }
            }
        }
    }
    Stack<jcPageObjectSet> orderedReturnSet = new Stack<>();
    while (returnSet.size() > 0) {
        orderedReturnSet.push(returnSet.get(returnSet.size() - 1));
        returnSet.remove(returnSet.size() - 1);
    }
    //return orderedReturnSet;
    return orderedReturnSet;
}

From source file:com.google.gwt.site.markdown.MarkupWriter.java

public void writeHTML(MDNode node, String html) throws TranslaterException {
    if (node.isFolder()) {
        throw new IllegalArgumentException();
    }/*from   www .j ava 2 s.  c  o m*/

    Stack<MDParent> stack = new Stack<MDParent>();

    MDParent tmp = node.getParent();
    stack.add(tmp);

    while (tmp.getParent() != null) {
        tmp = tmp.getParent();
        stack.add(tmp);
    }

    // get rootnode from stack
    stack.pop();

    File currentDir = rootFile;
    ensureDirectory(currentDir);
    while (!stack.isEmpty()) {
        MDParent pop = stack.pop();
        currentDir = new File(currentDir, pop.getName());
        ensureDirectory(currentDir);
    }

    String fileName = node.getName().substring(0, node.getName().length() - ".md".length()) + ".html";
    File fileToWrite = new File(currentDir, fileName);

    try {
        Util.writeStringToFile(fileToWrite, html);
    } catch (IOException e) {
        throw new TranslaterException("can not write markup to file: '" + fileToWrite + "'", e);

    }
}

From source file:com.vrem.wifianalyzer.wifi.graphutils.GraphColors.java

GraphColors() {
    graphColors = new Stack<>();
    availableGraphColors = new ArrayList<>();
}

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 w w w  .j  a  va2s .  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:NimbleTree.java

/** Creates a new instance of NimbleTree */
public NimbleTree() {
    this.root = newNode();
    this.currentNode = this.root;
    this.nodeCount = 1;
    this.root.setID(this.nodeCount);
    this.depth = 0;
    this.currentLevel = 0;
    //Important to make a new stack
    this.freeNodes = new Stack<TreeNode<E>>();
    this.maxStackSize = 10;
}

From source file:com.sqewd.open.dal.core.persistence.db.EntityHelper.java

public static void setEntity(final StructEntityReflect enref, final HashMap<String, AbstractEntity> entities,
        final ResultSet rs) throws Exception {
    Class<?> type = Class.forName(enref.Class);
    Object obj = type.newInstance();
    if (!(obj instanceof AbstractEntity))
        throw new Exception("Unsupported Entity type [" + type.getCanonicalName() + "]");
    AbstractEntity entity = (AbstractEntity) obj;
    AbstractJoinGraph gr = AbstractJoinGraph.lookup(type);

    for (StructAttributeReflect attr : enref.Attributes) {
        Stack<KeyValuePair<Class<?>>> path = new Stack<KeyValuePair<Class<?>>>();
        Class<?> at = attr.Field.getType();
        KeyValuePair<Class<?>> ak = new KeyValuePair<Class<?>>();
        ak.setValue(entity.getClass());//from  ww  w  .j a v  a2s.  c  om
        ak.setKey(attr.Column);
        path.push(ak);

        if (attr.Reference == null || attr.Reference.Type != EnumRefereceType.One2Many) {
            setColumnValue(rs, attr, entity, gr, path);
        } else if (attr.Reference != null) {
            // Object ao = createListInstance(entity, attr);
            Class<?> rt = Class.forName(attr.Reference.Class);
            Object ro = rt.newInstance();
            if (!(ro instanceof AbstractEntity))
                throw new Exception(
                        "Reference [" + attr.Column + "] is of invalid type. [" + at.getCanonicalName()
                                + "] does not extend from [" + AbstractEntity.class.getCanonicalName() + "]");
            AbstractEntity ae = (AbstractEntity) getColumnValue(rs, attr, entity, gr, path);
            addListValue(ae, entity, attr);
        }

    }
    String key = entity.getEntityKey();
    if (!entities.containsKey(key)) {
        entities.put(entity.getEntityKey(), entity);
    } else {
        AbstractEntity target = entities.get(key);
        for (StructAttributeReflect attr : enref.Attributes) {
            if (attr.Reference.Type == EnumRefereceType.One2Many) {
                copyToList(entity, target, attr);
            }
        }
    }
}

From source file:com.wavemaker.json.AlternateJSONTransformer.java

public static Object toObject(JSONState jsonState, Object obj, Class<?> klass) {

    TypeState typeState = jsonState.getTypeState();
    FieldDefinition fieldDefinition = ReflectTypeUtils.getFieldDefinition(klass, typeState, false, null);

    return toObjectInternal(jsonState, obj, obj, fieldDefinition, typeState, 0, new Stack<String>());
}

From source file:com.sfs.whichdoctor.xml.writer.XmlWriter.java

/**
 * Create an XmlWriter.//  www.ja  v a2s .c  o m
 */
public XmlWriter() {
    this.sb = new StringBuffer();
    this.closed = true;
    this.stack = new Stack<String>();
}

From source file:com.webcohesion.ofx4j.io.tagsoup.TestTagSoupOFXReader.java

/**
 * tests using sax to parse an OFX doc./*from   w  ww. j av  a2s  . c  o  m*/
 */
public void testVersion1() throws Exception {
    TagSoupOFXReader reader = new TagSoupOFXReader();
    final Map<String, String> headers = new HashMap<String, String>();
    final Stack<Map<String, Object>> aggregateStack = new Stack<Map<String, Object>>();
    TreeMap<String, Object> root = new TreeMap<String, Object>();
    aggregateStack.push(root);

    reader.setContentHandler(new DefaultHandler() {

        @Override
        public void onHeader(String name, String value) {
            LOG.debug(name + ":" + value);
            headers.put(name, value);
        }

        @Override
        public void onElement(String name, String value) {
            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + name + "=" + value);

            aggregateStack.peek().put(name, value);
        }

        @Override
        public void startAggregate(String aggregateName) {
            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + aggregateName + " {");

            TreeMap<String, Object> aggregate = new TreeMap<String, Object>();
            aggregateStack.peek().put(aggregateName, aggregate);
            aggregateStack.push(aggregate);
        }

        @Override
        public void endAggregate(String aggregateName) {
            aggregateStack.pop();

            char[] tabs = new char[aggregateStack.size() * 2];
            Arrays.fill(tabs, ' ');
            LOG.debug(new String(tabs) + "}");
        }
    });
    reader.parse(TestNanoXMLOFXReader.class.getResourceAsStream("example-response.ofx"));
    assertEquals(9, headers.size());
    assertEquals(1, aggregateStack.size());
    assertSame(root, aggregateStack.pop());
}

From source file:com.voa.weixin.task.TaskManager.java

private TaskManager() {
    pool = Executors.newFixedThreadPool(30);
    pauseTasks = new Stack<Task>();
    isGetToken = false;
}