List of usage examples for java.util Stack pop
public synchronized E pop()
From source file:gr.omadak.leviathan.asp.AspParser.java
public void parseDir(File sdir, boolean vbDefault) { FileFilter filter = new FileFilter() { public boolean accept(File f) { boolean result = f.isDirectory(); if (!result) { String name = f.getName(); int lastDot = name.lastIndexOf('.'); result = lastDot > 0 && "asp".equalsIgnoreCase(name.substring(lastDot + 1)); }/*www . j a va2 s .c o m*/ return result; } }; Stack stack = new Stack(); stack.push(sdir); while (!stack.isEmpty()) { File dir = (File) stack.pop(); for (Iterator it = IteratorUtils.arrayIterator(dir.listFiles(filter)); it.hasNext();) { File f = (File) it.next(); if (f.isDirectory()) { stack.push(f); } else { try { parseFile(f, vbDefault); } catch (ANTLRException ae) { LOG.error("Failed to parse file:" + f.getAbsolutePath(), ae); } catch (Exception ex) { LOG.error("Failed to parse file:" + f.getAbsolutePath() + " with error", ex); } } } } }
From source file:com.matteoveroni.model.copy.FilenameUtils.java
/** * Checks a filename to see if it matches the specified wildcard matcher * allowing control over case-sensitivity. * <p>/*from ww w. java 2 s. c o m*/ * The wildcard matcher uses the characters '?' and '*' to represent a * single or multiple (zero or more) wildcard characters. * N.B. the sequence "*?" does not work properly at present in match strings. * * @param filename the filename to match on * @param wildcardMatcher the wildcard string to match against * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive * @return true if the filename matches the wilcard string * @since 1.3 */ public static boolean wildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity) { if (filename == null && wildcardMatcher == null) { return true; } if (filename == null || wildcardMatcher == null) { return false; } if (caseSensitivity == null) { caseSensitivity = IOCase.SENSITIVE; } String[] wcs = splitOnTokens(wildcardMatcher); boolean anyChars = false; int textIdx = 0; int wcsIdx = 0; Stack<int[]> backtrack = new Stack<int[]>(); // loop around a backtrack stack, to handle complex * matching do { if (backtrack.size() > 0) { int[] array = backtrack.pop(); wcsIdx = array[0]; textIdx = array[1]; anyChars = true; } // loop whilst tokens and text left to process while (wcsIdx < wcs.length) { if (wcs[wcsIdx].equals("?")) { // ? so move to next text char textIdx++; if (textIdx > filename.length()) { break; } anyChars = false; } else if (wcs[wcsIdx].equals("*")) { // set any chars status anyChars = true; if (wcsIdx == wcs.length - 1) { textIdx = filename.length(); } } else { // matching text token if (anyChars) { // any chars then try to locate text token textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]); if (textIdx == -1) { // token not found break; } int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]); if (repeat >= 0) { backtrack.push(new int[] { wcsIdx, repeat }); } } else { // matching from current position if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) { // couldnt match token break; } } // matched text token, move text index to end of matched token textIdx += wcs[wcsIdx].length(); anyChars = false; } wcsIdx++; } // full match if (wcsIdx == wcs.length && textIdx == filename.length()) { return true; } } while (backtrack.size() > 0); return false; }
From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer.java
private void createParentDirs(Path destDirPath) throws IOException { Path parent = destDirPath.getParent(); Path cacheRoot = LocalCacheDirectoryManager.getCacheDirectoryRoot(parent); Stack<Path> dirs = new Stack<Path>(); while (!parent.equals(cacheRoot)) { dirs.push(parent);/* ww w . j a v a 2 s . co m*/ parent = parent.getParent(); } // Create directories with user cache permission while (!dirs.isEmpty()) { createDir(lfs, dirs.pop(), USERCACHE_FOLDER_PERMS); } }
From source file:com.spidertracks.datanucleus.spring.ConsistencyLevelAspect.java
/** * Validates any method that has the valid annotation on it and is wired as * a spring service//from w w w . j a va 2 s.c o m * * @param jp * @throws Throwable */ @Around("@annotation(com.spidertracks.datanucleus.spring.Consistency)") public Object setConsistency(ProceedingJoinPoint pjp) throws Throwable { logger.debug("Invoking before advice for @Consistency annotation. Target object is {} on method {}", pjp.getTarget(), pjp.getSignature()); MethodSignature sig = (MethodSignature) pjp.getSignature(); Object[] args = pjp.getArgs(); Method signatureMethod = sig.getMethod(); Class<?>[] signatureTypes = signatureMethod.getParameterTypes(); // we do this because we want to get the best match from the child // classes Class<?>[] runtimeArgs = new Class<?>[signatureTypes.length]; for (int i = 0; i < signatureTypes.length; i++) { if (args[i] != null) { runtimeArgs[i] = args[i].getClass(); } else { runtimeArgs[i] = signatureTypes[i]; } } Class<?> runtimeClass = pjp.getTarget().getClass(); // check if this is annotated, if not proceed and execute it ConsistencyLevel level = consistency(runtimeClass, signatureMethod.getName(), runtimeArgs); if (level == null) { return pjp.proceed(args); } Stack<ConsistencyLevel> stack = threadStack.get(); stack.push(level); com.spidertracks.datanucleus.client.Consistency.set(level); Object result = null; try { result = pjp.proceed(args); } finally { stack.pop(); if (stack.size() > 0) { com.spidertracks.datanucleus.client.Consistency.set(stack.peek()); } else { com.spidertracks.datanucleus.client.Consistency.remove(); } } return result; }
From source file:app.web.Application2ITCase.java
public void restoreToPreviousAction(Stack<Action> actionStack) { if (actionStack.size() == 1) { return; // No previous state }/*from w ww . j av a2 s . co m*/ log.info("Restore " + actionStack.get(0).getValue()); selenium.open(actionStack.get(0).getValue()); actionStack.pop(); // remove last action for (int i = 1; i < actionStack.size(); i++) { Action action = actionStack.get(i); if (action.getType() == Action.ActionType.OPEN) { } else { log.info("Restore click " + action.getTarget()); clickAndWaitIfNecessary(action.getTarget(), action.getType() != Action.ActionType.CLICK_DOM_UPDATE); } } }
From source file:com.buildabrand.gsb.util.URLUtils.java
private String canonicalizePath(String path) { if (StringUtils.isEmpty(path)) { return "/"; }/*from ww w . ja v a 2s . com*/ // There are some cases where the path will not start with '/'. Example: // "ftp://host.com?q" -- the hostname is 'host.com' and the path '%3Fq'. // Browsers typically do prepend a leading slash to the path in this case, // we'll do the same. if (!path.startsWith("/")) { path = "/" + path; } path = escape(path); Stack<String> pathComponents = new Stack<String>(); for (String pathComponent : StringUtils.split(path, '/')) { // If the path component is '..' we skip it and remove the preceding path // component if there are any. if (pathComponent.equals("..")) { if (!pathComponents.isEmpty()) { pathComponents.pop(); } } else if (!pathComponent.equals(".") && !pathComponent.equals("")) { // We skip empty path components to remove successive slashes (i.e., // // -> /). Note: this means that the leading and trailing slash will // also be removed and need to be re-added afterwards. // // If the path component is '.' we also skip it (i.e., /./ -> /). pathComponents.add(pathComponent); } } // Put the path components back together and re-add the leading slash which // got stripped by removing empty path components. String canonicalPath = "/" + StringUtils.join(pathComponents, "/"); // If necessary we also re-add the trailing slash. if (path.endsWith("/") && !canonicalPath.endsWith("/")) { canonicalPath += "/"; } return canonicalPath; }
From source file:org.apache.hadoop.hdfs.server.namenode.WaitingRoom.java
/** * Moves a file/dir to the waiting room//from ww w . ja v a2 s. c o m * * @param path Path to file/dir * @return false if move failed, true otherwise */ public boolean moveToWaitingRoom(Path path) throws IOException { // Make path absolute if (!path.isAbsolute()) path = new Path(dfs.getWorkingDirectory(), path); // Check if path is valid if (!dfs.exists(path)) throw new FileNotFoundException(path.toString()); // Check if file already in waiting area String qPath = path.makeQualified(dfs).toString(); if (qPath.startsWith(WR.toString())) return false; // Check if trying to move waiting room or its parent dir to // waiting room if (WR.toString().startsWith(qPath)) { throw new IOException("Can't delete " + path + " as it contains the waiting room directory."); } String fName = path.getName(); Path baseWRPath = getWaitingRoomPath(path.getParent()); // Make dir(s) for base Stack<Path> parentDirs = new Stack<Path>(); do { parentDirs.push(baseWRPath); baseWRPath = baseWRPath.getParent(); } while (baseWRPath != null); while (!parentDirs.empty()) { baseWRPath = parentDirs.pop(); // Create new dir with appended .WRx if already exists. for (int i = 0; dfs.exists(baseWRPath) && !dfs.getFileStatus(baseWRPath).isDir(); i++) { baseWRPath = new Path(baseWRPath.toString() + ".WR" + i); } if (!dfs.mkdirs(baseWRPath, PERMISSION)) { LOG.warn("Couldn't create base dir path in waiting room for " + baseWRPath); return false; } } // Rename file/dir to waiting room. Append .WRx if already exists. Path myWRPath = new Path(baseWRPath.toString(), fName); for (int i = 0; dfs.exists(myWRPath); i++) { myWRPath = new Path(myWRPath.toString() + ".WR" + i); } if (dfs.rename(path, myWRPath)) return true; // success return false; }
From source file:atter.jedis.RedisCacheTemplateTest.java
@Test public void testStack() { String key = "orderStack"; String orderId = "orderStack1"; String order = "orderABC"; String orderId1 = "orderStack2"; String order1 = "orderABC"; String orderId2 = "orderStack3"; String order2 = "orderABC"; Stack stack = cacheTemplate.getStack(key); stack.push(order);/*w w w . j av a 2 s. c o m*/ stack.push(order1); stack.push(order2); stack.push(orderId); stack.push(orderId1); stack.push(orderId2); for (int i = 0; i < 6; i++) { String savedOrder = (String) stack.pop(); // switch (i) { case 0: assertEquals("??", orderId2, savedOrder); break; case 1: assertEquals("??", orderId1, savedOrder); break; case 2: assertEquals("??", orderId, savedOrder); break; case 3: assertEquals("??", order2, savedOrder); break; case 4: assertEquals("??", order1, savedOrder); break; case 5: assertEquals("??", order, savedOrder); break; } } }
From source file:aula1.Aula1.java
public static String calculaPolonesaINversa(String entrada, String info) { Stack<String> pilha = new Stack<>(); Stack<Op> operadores = new Stack<>(); String[] operadoresSuportados = { "+", "-", "*", "/", "^", "(", ")", "sen" }; for (int i = 0; i < entrada.length(); i++) { String s = ""; if (entrada.charAt(i) == 's') { if (entrada.contains("sen")) { int ind = entrada.indexOf("sen"); ind += 2;// w ww . java2s .c om i = 0; entrada = entrada.substring(ind + 1); s = "sen"; } } else s = String.valueOf(entrada.charAt(i)); if (Character.isDigit(entrada.charAt(i)) || entrada.charAt(i) == 'x') { if (Character.isDigit(entrada.charAt(i))) { s = String.valueOf(entrada.charAt(i)); while (Character.isDigit(entrada.charAt(i + 1))) { s += String.valueOf(entrada.charAt(i + 1)); i++; } } pilha.push(s); } else if (Arrays.asList(operadoresSuportados).contains(s)) { String n1 = ""; String n2 = ""; if (s.equals("sen")) n1 = pilha.pop(); else { n1 = pilha.pop(); n2 = pilha.pop(); } String resultado; if (n1.equals("x")) n1 = info; else if (n2.equals("x")) n2 = info; try { switch (s) { case "+": resultado = Operadores.soma(n2, n1); pilha.push(resultado); break; case "-": resultado = Operadores.sub(n2, n1); pilha.push(resultado); break; case "*": resultado = Operadores.M(n2, n1); pilha.push(resultado); break; case "/": resultado = Operadores.D(n2, n1); pilha.push(resultado); break; case "^": resultado = Operadores.pow(n2, n1); pilha.push(resultado); break; case "sen": resultado = Operadores.sen(n1); pilha.push(resultado); break; } } catch (Exception e) { System.out.println("Erro: " + e.getMessage()); } } } return pilha.peek(); }
From source file:gdt.jgui.entity.bookmark.JBookmarksEditor.java
/** * Execute the response locator./*from www . j a v a 2 s . c o m*/ * @param console the main console. * @param locator$ the response locator. * */ @Override public void response(JMainConsole console, String locator$) { // System.out.println("BookmarkEditor:response:locator="+locator$); try { Properties locator = Locator.toProperties(locator$); String action$ = locator.getProperty(JRequester.REQUESTER_ACTION); if (ACTION_CREATE_BOOKMARKS.equals(action$)) { String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); String text$ = locator.getProperty(JTextEditor.TEXT); Entigrator entigrator = console.getEntigrator(entihome$); Sack bookmarks = entigrator.ent_new("bookmarks", text$); bookmarks = entigrator.ent_assignProperty(bookmarks, "bookmarks", bookmarks.getProperty("label")); bookmarks.putAttribute(new Core(null, "icon", "bookmark.png")); entigrator.save(bookmarks); entigrator.saveHandlerIcon(JEntitiesPanel.class, "bookmark.png"); entityKey$ = bookmarks.getKey(); JBookmarksEditor be = new JBookmarksEditor(); String beLocator$ = be.getLocator(); beLocator$ = Locator.append(beLocator$, Entigrator.ENTIHOME, entihome$); beLocator$ = Locator.append(beLocator$, EntityHandler.ENTITY_KEY, entityKey$); JEntityPrimaryMenu.reindexEntity(console, beLocator$); Stack<String> s = console.getTrack(); s.pop(); console.setTrack(s); JConsoleHandler.execute(console, beLocator$); return; } String icon$ = locator.getProperty(JIconSelector.ICON); String requesterResponseLocator$ = locator.getProperty(JRequester.REQUESTER_RESPONSE_LOCATOR); byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String bmLocator$ = new String(ba, "UTF-8"); // System.out.println("BookmarkEditor:response:bm locator="+bmLocator$); Properties bmLocator = Locator.toProperties(bmLocator$); String entihome$ = bmLocator.getProperty(Entigrator.ENTIHOME); String entityKey$ = bmLocator.getProperty(EntityHandler.ENTITY_KEY); String bookmarkKey$ = locator.getProperty(BOOKMARK_KEY); String text$ = locator.getProperty(JTextEditor.TEXT); Entigrator entigrator = console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); Core bookmark = entity.getElementItem("jbookmark", bookmarkKey$); //System.out.println("BookmarkEditor:response:bookmark="+bookmarkKey$); if (JBookmarkItem.ACTION_RENAME.equals(action$)) { bookmark.type = text$; // System.out.println("BookmarkEditor:response:text="+text$); } if (JBookmarkItem.ACTION_SET_ICON.equals(action$)) { // System.out.println("BookmarkEditor:response icon="+icon$); String bookmarkIcon$ = entigrator.readIconFromIcons(icon$); // System.out.println("BookmarkEditor:response bookmark icon="+icon$); String bookmarkLocator$ = bookmark.value; bookmarkLocator$ = Locator.append(bookmarkLocator$, Locator.LOCATOR_ICON, bookmarkIcon$); bookmark.value = bookmarkLocator$; } entity.putElementItem("jbookmark", bookmark); entigrator.save(entity); String bmeLocator$ = getLocator(); bmeLocator$ = Locator.append(bmeLocator$, Entigrator.ENTIHOME, entihome$); bmeLocator$ = Locator.append(bmeLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, bmeLocator$); } catch (Exception e) { LOGGER.severe(e.toString()); } }