List of usage examples for java.util Stack push
public E push(E item)
From source file:Main.java
public static void addFragmentStacked(FragmentManager fragmentManager, Fragment fragment, int frameId, String fragmentTag, Stack<Fragment> fragmentStack) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment, fragmentTag); fragmentStack.lastElement().onPause(); transaction.hide(fragmentStack.lastElement()); fragmentStack.push(fragment); transaction.commit();/* w w w . ja v a 2 s. com*/ }
From source file:com.espertech.esper.view.ViewSupport.java
private static boolean findDescendentRecusive(View parentView, Viewable descendentView, Stack<View> stack) { stack.push(parentView); boolean found = false; for (View view : parentView.getViews()) { if (view == descendentView) { return true; }//from w ww . j a v a 2s . com found = findDescendentRecusive(view, descendentView, stack); if (found) { break; } } if (!found) { stack.pop(); return false; } return true; }
From source file:Main.java
public static String getXPath(Node node) { if (null == node) return null; // declarations Node parent = null;//from w w w. j a v a 2 s .c om Stack<Node> hierarchy = new Stack<Node>(); StringBuilder buffer = new StringBuilder(); // push element on stack hierarchy.push(node); parent = node.getParentNode(); while (null != parent && parent.getNodeType() != Node.DOCUMENT_NODE) { // push on stack hierarchy.push(parent); // get parent of parent parent = parent.getParentNode(); } // construct xpath Object obj = null; while (!hierarchy.isEmpty() && null != (obj = hierarchy.pop())) { Node n = (Node) obj; boolean handled = false; // only consider elements if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; // is this the root element? if (buffer.length() == 0) { // root element - simply append element name buffer.append(n.getNodeName()); } else { // child element - append slash and element name buffer.append("/"); buffer.append(n.getNodeName()); if (n.hasAttributes()) { // see if the element has a name or id attribute if (e.hasAttribute("id")) { // id attribute found - use that buffer.append("[@id='" + e.getAttribute("id") + "']"); handled = true; } else if (e.hasAttribute("name")) { // name attribute found - use that buffer.append("[@name='" + e.getAttribute("name") + "']"); handled = true; } } if (!handled) { // no known attribute we could use - get sibling index int prev_siblings = 1; Node prev_sibling = n.getPreviousSibling(); while (null != prev_sibling) { if (prev_sibling.getNodeType() == n.getNodeType()) { if (prev_sibling.getNodeName().equalsIgnoreCase(n.getNodeName())) { prev_siblings++; } } prev_sibling = prev_sibling.getPreviousSibling(); } buffer.append("[" + prev_siblings + "]"); } } } } // return buffer return buffer.toString(); }
From source file:Main.java
public static String getColumnId(int column) { Stack<Character> digits = new Stack<Character>(); int dividant = column; while (dividant > 26) { int remain = dividant % 26; dividant = dividant / 26;/* w w w .j av a 2 s . c o m*/ if (remain == 0) { remain = 26; dividant--; } digits.push((char) ('A' + remain - 1)); } digits.push((char) ('A' + dividant - 1)); StringBuffer buffer = new StringBuffer(); while (!digits.empty()) { buffer.append(digits.pop()); } String columnId = buffer.toString(); return columnId; }
From source file:com.mewmew.fairy.v1.cli.AnnotatedCLI.java
public static <T> AnnotatedCLI getMagicCLI(Class<T> c) { Stack<Class> stack = new Stack<Class>(); Class p = c;//from ww w. ja va2 s . com while (p != Object.class) { stack.push(p); p = p.getSuperclass(); } return new AnnotatedCLI(stack.toArray(new Class[stack.size()])); }
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"); }//www . j av a2s .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:com.baifendian.swordfish.execserver.parameter.placeholder.CalculateUtil.java
/** * ??//w ww . j av a2 s .c o 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
/** 0: number of files/* w ww . j a va 2 s. c o m*/ 1: total length 2: number of directories */ public static void getDirSize(final File f, final long[] l) { if (f.isFile()) { l[0]++; l[1] += f.length(); } else { Stack<File> stk = new Stack<>(); stk.add(f); 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); l[2]++; } else { l[0]++; l[1] += f2.length(); } } } } }
From source file:com.ms.commons.test.math.expression.util.MathExpressionParseUtil.java
private static Stack<String> adjustExpressionStack(Stack<String> expressionStack) { if (expressionStack.size() <= 2) { return expressionStack; }/*from ww w .j a v a2 s. c o m*/ int lastOpPr = Integer.MAX_VALUE; int lowerPrOp = -1; for (int i = (expressionStack.size() - 1); i >= 0; i--) { String expr = expressionStack.get(i); if ((expr.length() == 1) && hasSeparators(expr)) { int opPr = ("*".equals(expr) || "/".equals(expr)) ? 2 : 1; if (opPr < lastOpPr) { lastOpPr = opPr; lowerPrOp = i; } } } if (lowerPrOp != -1) { Stack<String> tempStack = new Stack<String>(); int popCount = expressionStack.size() - lowerPrOp - 1; for (int i = 0; i < popCount; i++) { tempStack.push(expressionStack.pop()); } Collections.reverse(tempStack); expressionStack.push(StringUtils.join(tempStack, "")); } return expressionStack; }
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"); }//w ww .j a v a 2 s. c o m 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; }