List of usage examples for java.util Stack Stack
public Stack()
From source file:importer.handler.post.annotate.HTMLConverter.java
/** * Convert an xml->html converter with limited functionality * @param config the config specifying how to convert the tags+attributes *//*from w ww . ja v a 2 s .com*/ HTMLConverter(JSONArray config) { this.body = new StringBuilder(); this.patterns = config; map = new HashMap<Element, HTMLPattern>(); this.stack = new Stack<HTMLPattern>(); this.ignore = new HashSet<String>(); for (int i = 0; i < config.size(); i++) { JSONObject jObj = (JSONObject) config.get(i); String htmlTag = (String) jObj.get("htmlTag"); String xmlTag = (String) jObj.get("xmlTag"); String htmlAttrName = (String) jObj.get("htmlAttrName"); String htmlAttrValue = (String) jObj.get("htmlAttrValue"); String xmlAttrName = (String) jObj.get("xmlAttrName"); String xmlAttrValue = (String) jObj.get("xmlAttrValue"); addPattern(xmlTag, htmlTag, htmlAttrName, htmlAttrValue, xmlAttrName, xmlAttrValue); } }
From source file:net.ontopia.topicmaps.nav.taglibs.template.InsertTag.java
public Stack getStack() { Stack s = (Stack) pageContext.getAttribute(TEMPL_STACK_KEY, PageContext.REQUEST_SCOPE); if (s == null) { s = new Stack(); pageContext.setAttribute(TEMPL_STACK_KEY, s, PageContext.REQUEST_SCOPE); }//from w ww .j a v a2 s . co m return s; }
From source file:com.altoukhov.svsync.fileviews.LocalFileSpace.java
@Override protected Snapshot scan(List<Pattern> filters) { try {// w w w . ja v a2 s .c o m Map<String, FileSnapshot> files = new LinkedHashMap<>(); Set<String> dirs = new HashSet<>(); File root = new File(rootPath); if (root.exists()) { Stack<File> stack = new Stack<>(); stack.push(root); dirs.add(""); while (!stack.isEmpty()) { File currentFolder = stack.pop(); for (final File file : currentFolder.listFiles(filter)) { if (file.isFile() && !isExcluded(trimFilePath(file.getAbsolutePath())) && !isFiltered(toRelativePath(file.getAbsolutePath()), filters)) { FileSnapshot fileSnapshot = new FileSnapshot(file.getName(), file.length(), new DateTime(new Date(file.lastModified())), toRelativePath(file.getAbsolutePath())); files.put(fileSnapshot.getRelativePath(), fileSnapshot); } else if (file.isDirectory() && !isExcluded(trimFilePath(file.getAbsolutePath())) && !isFiltered(toRelativePath(file.getAbsolutePath(), true), filters)) { stack.push(file); dirs.add(toRelativePath(file.getAbsolutePath())); System.out.println("Scanning " + file.getAbsolutePath()); } } } } Snapshot snapshot = new Snapshot(files, dirs); return snapshot; } catch (SecurityException ex) { System.out.println("Failed to scan file space"); System.out.println(ex.getMessage()); } return null; }
From source file:net.bulletin.pdi.xero.step.support.XMLChunkerTest.java
private Stack<String> createExpectedContainerElementsStack() { Stack<String> result = new Stack<String>(); result.push("Response"); result.push("Artists"); result.push("Artist"); return result; }
From source file:edu.umd.shrawanraina.BooleanRetrievalHBase.java
private void initialize(String indexPath, String collectionPath, FileSystem fs) throws IOException { //index = new MapFile.Reader(new Path(indexPath + "/part-r-00000"), fs.getConf()); Configuration hbaseConfig = HBaseConfiguration.create(getConf()); HConnection hbaseConnection = HConnectionManager.createConnection(hbaseConfig); //HTableInterface table = hbaseConnection.getTable(indexPath); index = hbaseConnection.getTable(indexPath); collection = fs.open(new Path(collectionPath)); stack = new Stack<Set<Integer>>(); }
From source file:org.cleverbus.core.throttling.ThrottleCounterMemoryImpl.java
@Override public int count(ThrottleScope throttleScope, int interval) { Assert.notNull(throttleScope, "the throttleScope must not be null"); Assert.isTrue(interval > 0, "the interval must be positive value"); int counter = 0; boolean toLock = false; // is it necessary to lock thread? Only if two same throttle scopes are processed at the same time synchronized (OBJ_LOCK) { if (scopesInProgress.contains(throttleScope)) { toLock = true;//www . j a v a 2s .c o m } else { scopesInProgress.add(throttleScope); } } if (toLock) { lock.lock(); } try { if (requests.get(throttleScope) == null) { requests.put(throttleScope, new Stack<Long>()); } long now = DateTime.now().getMillis(); long from = now - (interval * 1000); // get timestamps for specified throttling scope List<Long> timestamps = requests.get(throttleScope); timestamps.add(now); // count requests for specified interval int lastIndex = -1; for (int i = timestamps.size() - 1; i >= 0; i--) { long timestamp = timestamps.get(i); if (timestamp >= from) { counter++; } else { lastIndex = i; break; } } // remove old timestamps if (lastIndex > 0) { for (int i = 0; i <= lastIndex; i++) { timestamps.remove(0); } } } finally { synchronized (OBJ_LOCK) { scopesInProgress.remove(throttleScope); } if (toLock) { lock.unlock(); } } // make dump only once in the specified interval if (Log.isDebugEnabled() && (DateUtils.addSeconds(new Date(), -DUMP_PERIOD).after(lastDumpTimestamp))) { dumpMemory(); lastDumpTimestamp = new Date(); } return counter; }
From source file:com.manydesigns.elements.xml.XmlBuffer.java
/** * Creates a new instance of XmlBuffer// w ww . j a v a2 s . c om * @param writer The writer */ public XmlBuffer(Writer writer) { this.writer = writer; state = START; if (checkWellFormed) { tagStack = new Stack<String>(); } else { tagStack = null; } allowedEmptyTags = DEFAULT_EMPTY_TAG_ALLOWED_LIST; }
From source file:gdt.data.entity.BaseHandler.java
/** * List all databases in the parent directory * @param entiroot$ the parent directory. * @return The locator string.//from w ww . j av a2s . c o m */ public static String[] bases(String entiroot$) { try { if (entiroot$ == null) return null; File entiroot = new File(entiroot$); File[] dirs = entiroot.listFiles(); if (dirs == null) return null; File propertyIndex; Stack<String> s = new Stack<String>(); for (int i = 0; i < dirs.length; i++) { if (!dirs[i].isDirectory()) continue; propertyIndex = new File(dirs[i] + "/" + Entigrator.PROPERTY_INDEX); if (propertyIndex.exists() && propertyIndex.isFile()) s.push(dirs[i].getPath()); } int cnt = s.size(); if (cnt < 1) return null; String[] sa = new String[cnt]; for (int i = 0; i < cnt; i++) sa[i] = (String) s.pop(); return sa; } catch (Exception e) { Logger.getLogger(BaseHandler.class.getName()).severe(e.toString()); ; return null; } }
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 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:net.sf.jabref.logic.util.io.FileUtil.java
/** * Creates the minimal unique path substring for each file among multiple file paths. * * @param paths the file paths//from w w w .j a va 2s . co m * @return the minimal unique path substring for each file path */ public static List<String> uniquePathSubstrings(List<String> paths) { List<Stack<String>> stackList = new ArrayList<>(paths.size()); // prepare data structures for (String path : paths) { List<String> directories = Arrays.asList(path.split(Pattern.quote(File.separator))); Stack<String> stack = new Stack<>(); stack.addAll(directories); stackList.add(stack); } List<String> pathSubstrings = new ArrayList<>(Collections.nCopies(paths.size(), "")); // compute shortest folder substrings while (!stackList.stream().allMatch(Vector::isEmpty)) { for (int i = 0; i < stackList.size(); i++) { String tempString = pathSubstrings.get(i); if (tempString.isEmpty() && !stackList.get(i).isEmpty()) { pathSubstrings.set(i, stackList.get(i).pop()); } else if (!stackList.get(i).isEmpty()) { pathSubstrings.set(i, stackList.get(i).pop() + File.separator + tempString); } } for (int i = 0; i < stackList.size(); i++) { String tempString = pathSubstrings.get(i); if (Collections.frequency(pathSubstrings, tempString) == 1) { stackList.get(i).clear(); } } } return pathSubstrings; }