Example usage for java.util Stack pop

List of usage examples for java.util Stack pop

Introduction

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

Prototype

public synchronized E pop() 

Source Link

Document

Removes the object at the top of this stack and returns that object as the value of this function.

Usage

From source file:com.trenako.web.infrastructure.SearchRequestUrlParser.java

/**
 * Parses the {@code path} string, matching the {@code SearchCriteria} property names.
 * <p>/*w  w w  . j  av  a2s.  co  m*/
 * This method is able to manage paths with wrong sequences, in this case
 * the values outside the correct sequence are simply ignored.
 * </p>
 *
 * @param path the {@code path} string
 * @return a {@code Map} with the extracted values
 */
public static Map<String, String> parseUrl(String path) {
    Assert.notNull(path, "Path must be not null");

    Map<String, String> values = new HashMap<>();
    Stack<String> stack = new Stack<>();
    String[] tokens = path.split("/");
    for (String tk : tokens) {
        if (SEARCH_CRITERIA_KEYS.contains(tk)) {
            if (!stack.isEmpty()) {
                // a different key name was found, but no value was provided
                // (ie /key1/key2/value2)
                stack.pop();
            }
            stack.push(tk);
        } else {
            if (!stack.isEmpty()) {
                // match this value with the key name in the stack
                values.put(stack.pop(), tk);
            }
        }
    }

    return values;
}

From source file:Main.java

public static StringBuilder listFilesByName(File f, String lineSep) {
    Log.d("listFileByName f", "" + f);
    StringBuilder sb = new StringBuilder();
    if (f != null) {
        final Stack<File> stk = new Stack<>();
        if (f.isDirectory()) {
            stk.push(f);//from  w  ww. j a  v a  2 s. co m
        } else {
            sb.append(f.getAbsolutePath()).append(": ").append(f.length()).append(" bytes.").append(lineSep);
        }
        File fi = null;
        File[] fs;
        while (stk.size() > 0) {
            fi = stk.pop();
            fs = fi.listFiles();
            for (File f2 : fs) {
                if (f2.isDirectory()) {
                    stk.push(f2);
                } else {
                    sb.append(f2.getAbsolutePath()).append(": ").append(f2.length()).append(" bytes.")
                            .append(lineSep);
                }
            }
        }

    }
    return sb;
}

From source file:org.apache.oodt.cas.filemgr.versioning.VersioningUtils.java

public static List<String> getURIsFromDir(File dirRoot) {
    List<String> uris;

    if (dirRoot == null) {
        throw new IllegalArgumentException("null");
    }/*from   w  w  w  .ja v a  2  s  .co m*/
    if (!dirRoot.isDirectory()) {
        dirRoot = dirRoot.getParentFile();
    }

    uris = new Vector<String>();

    Stack<File> stack = new Stack<File>();
    stack.push(dirRoot);
    while (!stack.isEmpty()) {
        File dir = stack.pop();
        // add the reference for the dir
        // except if it's the rootDir, then, skip it
        if (!dir.equals(dirRoot)) {
            uris.add(dir.toURI().toString());
        }

        File[] files = dir.listFiles(FILE_FILTER);

        if (files != null) {
            for (File file : files) {
                // add the file references
                uris.add(file.toURI().toString());
            }
        }

        File[] subdirs = dir.listFiles(DIR_FILTER);
        if (subdirs != null) {
            for (File subdir : subdirs) {
                stack.push(subdir);
            }
        }
    }

    return uris;
}

From source file:org.apache.oodt.cas.filemgr.versioning.VersioningUtils.java

public static List<Reference> getReferencesFromDir(File dirRoot) {
    List<Reference> references;

    if (dirRoot == null) {
        throw new IllegalArgumentException("null");
    }/*ww w.jav a2s .c om*/
    if (!dirRoot.isDirectory()) {
        dirRoot = dirRoot.getParentFile();
    }

    references = new Vector<Reference>();

    Stack<File> stack = new Stack<File>();
    stack.push(dirRoot);
    while (!stack.isEmpty()) {
        File dir = stack.pop();
        // add the reference for the dir
        // except if it's the rootDir, then, skip it
        if (!dir.equals(dirRoot)) {
            try {
                Reference r = new Reference();
                r.setOrigReference(dir.toURL().toExternalForm());
                r.setFileSize(dir.length());
                references.add(r);
            } catch (MalformedURLException e) {
                LOG.log(Level.SEVERE, e.getMessage());
                LOG.log(Level.WARNING, "MalformedURLException when generating reference for dir: " + dir);
            }
        }

        File[] files = dir.listFiles(FILE_FILTER);

        if (files != null) {
            for (File file : files) {
                // add the file references
                try {
                    Reference r = new Reference();
                    r.setOrigReference(file.toURL().toExternalForm());
                    r.setFileSize(file.length());
                    references.add(r);
                } catch (MalformedURLException e) {
                    LOG.log(Level.SEVERE, e.getMessage());
                    LOG.log(Level.WARNING, "MalformedURLException when generating reference for file: " + file);
                }

            }
            File[] subdirs = dir.listFiles(DIR_FILTER);
            if (subdirs != null) {
                for (File subdir : subdirs) {
                    stack.push(subdir);
                }
            }
        }
    }

    return references;
}

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

/**
 * ??/*  w  w  w.ja va  2s . co m*/
 *
 * @param postOrder
 * @return 
 */
private static Integer calculate(List<String> postOrder) {
    Stack<Integer> stack = new Stack<>();
    for (int i = 0; i < postOrder.size(); i++) {
        if (Character.isDigit(postOrder.get(i).charAt(0))) {
            stack.push(Integer.parseInt(postOrder.get(i)));
        } else {
            Integer back = stack.pop();
            Integer front = 0;
            char op = postOrder.get(i).charAt(0);
            if (!(op == 'P' || op == 'S')) { // ?? "?" 
                front = stack.pop();
            }

            Integer res = 0;
            switch (postOrder.get(i).charAt(0)) {
            case 'P':
                res = front + back;
                break;
            case 'S':
                res = front - back;
                break;
            case '+':
                res = front + back;
                break;
            case '-':
                res = front - back;
                break;
            case '*':
                res = front * back;
                break;
            case '/':
                res = front / back;
                break;
            }
            stack.push(res);
        }
    }

    return stack.pop();
}

From source file:Main.java

public static void replaceFragment(FragmentManager fragmentManager, int frameId, Fragment fragmentToShow,
        String fragmentTag, Stack<Fragment> fragmentStack) {
    if (fragmentToShow == null) {
        return;/*from www .jav a2s.c o m*/
    }

    List<Fragment> fragmentList = fragmentManager.getFragments();
    for (Fragment fragment : fragmentList) {
        if (fragment == null) {
            continue;
        }
        fragmentManager.beginTransaction().remove(fragment).commit();

        if (!fragmentStack.empty()) {
            fragmentStack.pop();
        }
    }

    fragmentManager.beginTransaction().add(frameId, fragmentToShow, fragmentTag).commit();

    fragmentStack.push(fragmentToShow);
}

From source file:Main.java

public static String getNodeHierarchy(Node node) {

    StringBuffer sb = new StringBuffer();
    if (node != null) {
        Stack<Node> st = new Stack<Node>();
        st.push(node);//from   ww w . jav  a  2  s.  c  om

        Node parent = node.getParentNode();

        while ((parent != null) && (parent.getNodeType() != Node.DOCUMENT_NODE)) {

            st.push(parent);

            parent = parent.getParentNode();
        }

        // constructs node hierarchy
        Node n = null;
        while (!st.isEmpty() && null != (n = st.pop())) {

            if (n instanceof Element) {
                Element e = (Element) n;

                if (sb.length() == 0) {
                    sb.append(e.getTagName());
                } else {
                    sb.append("/" + e.getTagName());
                }
            }

        }
    }
    return sb.toString();

}

From source file:com.itmanwuiso.checksums.FileDuplicateChecker.java

private static void createTaskes(String pathname, Stack<File> fStack) {
    if (null == fStack) {
        fStack = new Stack<File>();
    }/*  w w w  . j a  v a  2s.c o m*/

    File f = new File(pathname);
    fStack.push(f);

    while (!fStack.isEmpty()) {

        File currentFile = fStack.pop();
        File[] listOfFiles = null;

        // if is the current file a dir
        if (currentFile.isDirectory()) {
            listOfFiles = currentFile.listFiles();
        } else if (currentFile.isFile()) {
            createTaske(currentFile);
            continue;
        }

        // if the currentFile isn't a dir
        // or if the dir is empty
        if (listOfFiles == null || listOfFiles.length == 0) {
            continue;
        }

        for (int i = 0; i < listOfFiles.length; i++) {
            File cFile = listOfFiles[i];

            if (cFile.isFile()) {
                createTaske(cFile);
            } else if (recursive && cFile.isDirectory()) {
                fStack.push(cFile);
            }
        }
    }
}

From source file:com.jetbrains.pluginUtils.xml.JDOMXIncluder.java

public static List<Content> resolve(@NotNull Element original, @Nullable String base) throws XIncludeException {
    Stack<String> bases = new Stack<String>();
    if (base != null)
        bases.push(base);//www  .  j  a  v a  2s.  com

    List<Content> result = resolve(original, bases);
    bases.pop();
    return result;

}

From source file:Main.java

private static <T> void combine(Stack<T> elementStack, List<List<T>> listWithLists,
        List<List<T>> combinations) {
    if (elementStack.size() == listWithLists.size()) {
        combinations.add(new ArrayList<T>(elementStack));
    } else {/*from w  w w .  j  a v a2  s .c o m*/
        List<T> currentList = listWithLists.get(elementStack.size());

        for (T item : currentList) {
            elementStack.push(item);
            combine(elementStack, listWithLists, combinations);
            elementStack.pop();
        }
    }
}