List of usage examples for java.util Stack pop
public synchronized E pop()
From source file:Main.java
public static List<File> listFilesByName(File f) { Log.d("listFileByName f", "" + f); final List<File> fList = new LinkedList<>(); final Stack<File> stk = new Stack<>(); if (f.isDirectory()) { stk.push(f);// w w w . j ava 2s . co m } else { fList.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); } else { fList.add(f2); } } } return fList; }
From source file:app.web.CrawlerITCase.java
/** * FIXME move to Page/*from w w w .j a va2 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:org.apache.kylin.common.BackwardCompatibilityConfig.java
private static void generateFindAndReplaceScript(String kylinRepoPath, String outputPath) throws IOException { BackwardCompatibilityConfig bcc = new BackwardCompatibilityConfig(); File repoDir = new File(kylinRepoPath).getCanonicalFile(); File outputDir = new File(outputPath).getCanonicalFile(); PrintWriter out = null;/*from w w w .j a va 2 s .co m*/ // generate sed file File sedFile = new File(outputDir, "upgrade-old-config.sed"); try { out = new PrintWriter(sedFile); for (Entry<String, String> e : bcc.old2new.entrySet()) { out.println("s/" + quote(e.getKey()) + "/" + e.getValue() + "/g"); } for (Entry<String, String> e : bcc.old2newPrefix.entrySet()) { out.println("s/" + quote(e.getKey()) + "/" + e.getValue() + "/g"); } } finally { IOUtils.closeQuietly(out); } // generate sh file File shFile = new File(outputDir, "upgrade-old-config.sh"); try { out = new PrintWriter(shFile); out.println("#!/bin/bash"); Stack<File> stack = new Stack<>(); stack.push(repoDir); while (!stack.isEmpty()) { File dir = stack.pop(); for (File f : dir.listFiles()) { if (f.getName().startsWith(".")) continue; if (f.isDirectory()) { if (acceptSourceDir(f)) stack.push(f); } else if (acceptSourceFile(f)) out.println("sed -i -f upgrade-old-config.sed " + f.getAbsolutePath()); } } } finally { IOUtils.closeQuietly(out); } System.out.println("Files generated:"); System.out.println(shFile); System.out.println(sedFile); }
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);// w w w. j a v a 2 s . com T currentElement; while (!stack.isEmpty()) { currentElement = stack.pop(); elements.add(currentElement); stack.addAll(generatingFunction.apply(currentElement)); } return elements.stream(); }
From source file:Main.java
public static String _10_to_62(long number, int length) { Long rest = number;/*from w w w.j av a 2 s . co m*/ Stack<Character> stack = new Stack<Character>(); StringBuilder result = new StringBuilder(0); while (rest != 0) { stack.add(charSet[new Long((rest - (rest / 62) * 62)).intValue()]); rest = rest / 62; } for (; !stack.isEmpty();) { result.append(stack.pop()); } int result_length = result.length(); StringBuilder temp0 = new StringBuilder(); for (int i = 0; i < length - result_length; i++) { temp0.append('0'); } return temp0.toString() + result.toString(); }
From source file:com.inmobi.conduit.distcp.tools.util.TestDistCpUtils.java
public static boolean checkIfFoldersAreInSync(FileSystem fs, String targetBase, String sourceBase) throws IOException { Path base = new Path(targetBase); Stack<Path> stack = new Stack<Path>(); stack.push(base);//from w w w . j a v a 2 s. co m while (!stack.isEmpty()) { Path file = stack.pop(); if (!fs.exists(file)) continue; FileStatus[] fStatus = fs.listStatus(file); if (fStatus == null || fStatus.length == 0) continue; for (FileStatus status : fStatus) { if (status.isDir()) { stack.push(status.getPath()); } Assert.assertTrue(fs.exists(new Path( sourceBase + "/" + DistCpUtils.getRelativePath(new Path(targetBase), status.getPath())))); } } return true; }
From source file:Main.java
/** * Check of the balanced tags sup/sub//w w w .ja v a2s. c o m * * @param snippet * @return <code>true</code> if balanced, <code>false</code> otherwise */ public static boolean isBalanced(String snippet) { if (snippet == null) return true; // ???? Stack<String> s = new Stack<String>(); Matcher m = SUBS_OR_SUPS.matcher(snippet); while (m.find()) { String tag = m.group(1); if (tag.toLowerCase().startsWith("su")) { s.push(tag); } else { if (s.empty() || !tag.equals("/" + s.pop())) { return false; } } } return s.empty(); }
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(); } else {/*from w w w . j a va 2s.c o m*/ 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:org.openremote.server.route.SubflowRoute.java
public static Map<String, Object> copyCorrelationStack(Map<String, Object> headers, boolean popStack) { Map<String, Object> headersCopy = new HashMap<>(headers); if (hasCorrelationStack(headers)) { @SuppressWarnings("unchecked") Stack<String> correlationStack = (Stack<String>) headers.get(SUBFLOW_CORRELATION_STACK); @SuppressWarnings("unchecked") Stack<String> correlationStackCopy = (Stack<String>) correlationStack.clone(); if (correlationStackCopy.size() > 0 && popStack) { correlationStackCopy.pop(); }// w w w .j av a 2 s . c o m headersCopy.put(SUBFLOW_CORRELATION_STACK, correlationStackCopy); } return headersCopy; }
From source file:Main.java
/** * Removes dot segments according to RFC 3986, section 5.2.4 * * @param uri the original URI// w ww. jav a 2s . co m * @return the URI without dot segments */ private static URI removeDotSegments(URI uri) { String path = uri.getPath(); if ((path == null) || (path.indexOf("/.") == -1)) { // No dot segments to remove return uri; } String[] inputSegments = path.split("/"); Stack<String> outputSegments = new Stack<String>(); for (int i = 0; i < inputSegments.length; i++) { if ((inputSegments[i].length() == 0) || (".".equals(inputSegments[i]))) { // Do nothing } else if ("..".equals(inputSegments[i])) { if (!outputSegments.isEmpty()) { outputSegments.pop(); } } else { outputSegments.push(inputSegments[i]); } } StringBuilder outputBuffer = new StringBuilder(); for (String outputSegment : outputSegments) { outputBuffer.append('/').append(outputSegment); } try { return new URI(uri.getScheme(), uri.getAuthority(), outputBuffer.toString(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }