List of usage examples for java.util Stack push
public E push(E item)
From source file:opennlp.tools.parse_thicket.kernel_interface.BracesProcessor.java
public static boolean isBalanced(String s) { int count = 0; Stack<Character> stack = new Stack<Character>(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == L_PAREN) { stack.push(L_PAREN); count++;//from www .jav a 2s .c o m } else if (s.charAt(i) == L_BRACE) { stack.push(L_BRACE); count++; } else if (s.charAt(i) == L_BRACKET) { stack.push(L_BRACKET); count++; } else if (s.charAt(i) == R_PAREN) { if (stack.isEmpty()) return false; if (stack.pop() != L_PAREN) return false; } else if (s.charAt(i) == R_BRACE) { if (stack.isEmpty()) return false; if (stack.pop() != L_BRACE) return false; } else if (s.charAt(i) == R_BRACKET) { if (stack.isEmpty()) return false; if (stack.pop() != L_BRACKET) return false; } // ignore all other characters } return (stack.isEmpty()); }
From source file:app.web.CrawlerITCase.java
/** * FIXME move to Page//from w w w. ja va 2 s . c o m * @param page * @param location * @return */ private static boolean hasBeenThereBefore(Page page, URL location) { Stack<URL> locationStack = page.getLocationStack(); URL currentLocation = locationStack.pop(); boolean bool = locationStack.contains(location); locationStack.push(currentLocation); return bool; }
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 .ja v a 2s.c om*/ List<T> currentList = listWithLists.get(elementStack.size()); for (T item : currentList) { elementStack.push(item); combine(elementStack, listWithLists, combinations); elementStack.pop(); } } }
From source file:com.thoughtworks.go.util.FileUtil.java
public static File normalize(final String path) { Stack s = new Stack(); String[] dissect = dissect(path); s.push(dissect[0]); StringTokenizer tok = new StringTokenizer(dissect[1], File.separator); while (tok.hasMoreTokens()) { String thisToken = tok.nextToken(); if (".".equals(thisToken)) { continue; }/*w ww . j a va2s. co m*/ if ("..".equals(thisToken)) { if (s.size() < 2) { // Cannot resolve it, so skip it. return new File(path); } s.pop(); } else { // plain component s.push(thisToken); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.size(); i++) { if (i > 1) { // not before the filesystem root and not after it, since root // already contains one sb.append(File.separatorChar); } sb.append(s.elementAt(i)); } return new File(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>(); }/*from w w w. ja v a 2 s . c om*/ 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); List<Content> result = resolve(original, bases); bases.pop();/*from w w w . j a v a 2s . c om*/ return result; }
From source file:opennlp.tools.parse_thicket.kernel_interface.BracesProcessor.java
public static boolean checkParentesis(String str) { if (str.isEmpty()) return true; Stack<Character> stack = new Stack<Character>(); for (int i = 0; i < str.length(); i++) { char current = str.charAt(i); if (current == '{' || current == '(' || current == '[') { stack.push(current); }/*from w w w.java 2 s. c o m*/ if (current == '}' || current == ')' || current == ']') { if (stack.isEmpty()) return false; char last = stack.peek(); if (current == '}' && (last == '{' || current == ')') && last == '(' || (current == ']' && last == '[')) stack.pop(); else return false; } } return stack.isEmpty(); }
From source file:com.siberhus.web.ckeditor.utils.PathUtils.java
public static String normalizePath(String path) { String tokens[] = StringUtils.split(path, File.separator); List<String> tokenList = Arrays.asList(tokens); Stack<String> tokenStack = new Stack<String>(); for (String token : tokenList) { if (".".equals(token)) { // skip } else if ("..".equals(token)) { tokenStack.pop();//from w w w . j av a2s .co m } else { tokenStack.push(token); } } String result = ""; if (path.startsWith(File.separator)) { result += File.separator; } result += StringUtils.join(tokenStack, File.separator); if (path.endsWith(File.separator)) { result += File.separator; } return result.toString(); }
From source file:net.leegorous.jsc.JavaScriptCombiner.java
public static String translate2RelatePath(File standard, File file) throws IOException { if (standard.isFile()) standard = standard.getParentFile(); String standardPath = standard.getCanonicalPath().replaceAll("\\\\", "/"); File target = file;//from w w w . j a va 2 s . c om Stack stack = new Stack(); if (file.isFile()) { stack.push(target.getName()); target = file.getParentFile(); } String targetPath = file.getCanonicalPath().replaceAll("\\\\", "/"); StringBuffer result = new StringBuffer(); while (!targetPath.startsWith(standardPath)) { standardPath = standardPath.substring(0, standardPath.lastIndexOf("/")); result.append("../"); } while (!standardPath.equals(target.getCanonicalPath().replaceAll("\\\\", "/"))) { stack.push(target.getName()); target = target.getParentFile(); } while (stack.size() > 1) { result.append((String) stack.pop()).append("/"); } if (stack.size() > 0) result.append((String) stack.pop()); // System.out.println(standardPath+"\n"+targetPath); return result.toString(); }
From source file:gdt.data.grain.Support.java
/** * Intersect two string arrays /* w w w .j a v a2 s . com*/ * @param list1 first array * @param list2 second array * @return the result string array. */ public static String[] intersect(String[] list1, String[] list2) { if (list2 == null || list1 == null) { return null; } Stack<String> s1 = new Stack<String>(); Stack<String> s2 = new Stack<String>(); for (String aList2 : list2) s2.push(aList2); String line$; boolean found; String member$ = null; while (!s2.isEmpty()) { try { found = false; line$ = s2.pop().toString(); if (line$ == null) continue; for (String aList1 : list1) { member$ = aList1; if (line$.equals(member$)) { found = true; break; } } if (found) Support.addItem(member$, s1); } catch (Exception e) { Logger.getLogger(Support.class.getName()).info("intersect:" + e.toString()); } } return s1.toArray(new String[0]); }