List of usage examples for java.util Stack Stack
public Stack()
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.Rsa2Tg.java
/** * Sets up several a {@link SchemaGraph} and data structures before the * processing can start./*from ww w. j a v a2s .c om*/ */ @Override public void startDocument() { sg = GrumlSchema.instance().createSchemaGraph(ImplementationType.STANDARD); // Initializing all necessary data structures for processing purposes. xmiIdStack = new Stack<>(); idMap = new HashMap<>(); packageStack = new Stack<>(); generalizations = new GraphMarker<>(sg); realizations = new HashMap<>(); attributeType = new GraphMarker<>(sg); recordComponentType = new GraphMarker<>(sg); domainMap = new HashMap<>(); preliminaryVertices = new HashSet<>(); ownedEnds = new HashSet<>(); constraints = new HashMap<>(); comments = new HashMap<>(); ignoredPackages = new HashSet<>(); modelRootElementNestingDepth = 1; derivedGraphElementClasses = new HashSet<>(); }
From source file:org.openmrs.module.auditlog.api.db.hibernate.interceptor.HibernateAuditLogInterceptor.java
private void initializeStacksIfNecessary() { if (inserts.get() == null) { inserts.set(new Stack<HashSet<Object>>()); }/*from ww w. jav a 2 s. c o m*/ if (updates.get() == null) { updates.set(new Stack<HashSet<Object>>()); } if (deletes.get() == null) { deletes.set(new Stack<HashSet<Object>>()); } if (objectChangesMap.get() == null) { objectChangesMap.set(new Stack<Map<Object, Map<String, String[]>>>()); } if (entityCollectionsMap.get() == null) { entityCollectionsMap.set(new Stack<Map<Object, List<Collection<?>>>>()); } if (ownerUuidChildLogsMap.get() == null) { ownerUuidChildLogsMap.set(new Stack<Map<Object, List<AuditLog>>>()); } if (childbjectUuidAuditLogMap.get() == null) { childbjectUuidAuditLogMap.set(new Stack<Map<Object, AuditLog>>()); } if (entityRemovedChildrenMap.get() == null) { entityRemovedChildrenMap.set(new Stack<Map<Object, HashSet<Object>>>()); } if (date.get() == null) { date.set(new Stack<Date>()); } }
From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java
public SomClustTreeSelectionResult updateUpperTreeSelection(int x, int y, double w, double h) { upperTreeBImg = upperTree.getImage(); Node n = this.getNodeAt(y, x, colNode); SomClustTreeSelectionResult result = new SomClustTreeSelectionResult(); if (n != null) { upperTree.painttree(n, upperTreeBImg.getGraphics(), Color.red); Stack st = new Stack(); Vector v = new Vector(); n.fillMembers(v, st);/*from w ww . j av a 2 s . com*/ int[] sel = new int[v.size()]; for (int i = 0; i < v.size(); i++) { sel[i] = ((Integer) v.elementAt(i)); } result.setSelectedIndices(sel); } try { byte[] imageData = ChartUtilities.encodeAsPNG(upperTreeBImg); String base64 = Base64.encodeBase64String(imageData); base64 = "data:image/png;base64," + base64; result.setTreeImg1Url(base64); System.gc(); // result.setTreeImgUrl(navgStringImg); return result; } catch (IOException e) { System.err.println(e.getLocalizedMessage()); } return null; }
From source file:ca.weblite.codename1.ios.CodenameOneIOSBuildTask.java
/** * Based on https://github.com/shannah/cn1/blob/master/Ports/iOSPort/xmlvm/src/xmlvm/org/xmlvm/proc/out/build/XCodeFile.java * @param template/*from www.j av a2 s . c o m*/ * @param filter */ private String injectFilesIntoXcodeProject(String template, File[] files) { int nextid = 0; Pattern idPattern = Pattern.compile(" (\\d+) "); Matcher m = idPattern.matcher(template); while (m.find()) { int curr = Integer.parseInt(m.group(1)); if (curr > nextid) { nextid = curr; } } nextid++; StringBuilder filerefs = new StringBuilder(); StringBuilder buildrefs = new StringBuilder(); StringBuilder display = new StringBuilder(); StringBuilder source = new StringBuilder(); StringBuilder resource = new StringBuilder(); for (File f : files) { String fname = f.getName(); if (template.indexOf(" " + fname + " ") >= 0) { continue; } FileResource fres = new FileResource(fname); if (f.exists()) { filerefs.append("\t\t").append(nextid); filerefs.append(" /* ").append(fname).append(" */"); filerefs.append(" = { isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "); filerefs.append(fres.type).append("; path = \""); filerefs.append(fname).append("\"; sourceTree = \"<group>\"; };"); filerefs.append('\n'); display.append("\t\t\t\t").append(nextid); display.append(" /* ").append(fname).append(" */"); display.append(",\n"); if (fres.isBuildable) { int fileid = nextid; nextid++; buildrefs.append("\t\t").append(nextid); buildrefs.append(" /* ").append(fname); buildrefs.append(" in ").append(fres.isSource ? "Sources" : "Resources"); buildrefs.append(" */ = {isa = PBXBuildFile; fileRef = ").append(fileid); buildrefs.append(" /* ").append(fname); buildrefs.append(" */; };\n"); if (fres.isSource) { source.append("\t\t\t\t").append(nextid); source.append(" /* ").append(fname).append(" */"); source.append(",\n"); } } nextid++; } } String data = template; data = data.replace("/* End PBXFileReference section */", filerefs.toString() + "/* End PBXFileReference section */"); data = data.replace("/* End PBXBuildFile section */", buildrefs.toString() + "/* End PBXBuildFile section */"); // The next two we probably shouldn't do by regex because there is no clear pattern. Stack<String> buffer = new Stack<String>(); Stack<String> backtrackStack = new Stack<String>(); Scanner scanner = new Scanner(data); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.indexOf("/* End PBXSourcesBuildPhase section */") >= 0) { // Found the end, let's backtrack while (!buffer.isEmpty()) { String l = buffer.pop(); backtrackStack.push(l); if (");".equals(l.trim())) { // This is the closing of the sources list // we can insert the sources here buffer.push(source.toString()); while (!backtrackStack.isEmpty()) { buffer.push(backtrackStack.pop()); } break; } } } else if (line.indexOf("name = Application;") >= 0) { while (!buffer.isEmpty()) { String l = buffer.pop(); backtrackStack.push(l); if (");".equals(l.trim())) { buffer.push(display.toString()); while (!backtrackStack.isEmpty()) { buffer.push(backtrackStack.pop()); } break; } } } buffer.push(line); } StringBuilder sb = new StringBuilder(); String[] lines = buffer.toArray(new String[0]); for (String line : lines) { sb.append(line).append("\n"); } data = sb.toString(); return data; }
From source file:com.quinsoft.zeidon.zeidonoperations.ZDRVROPR.java
public int BuildEntityAttributeFromCSV(View vSrc, String cpcSrcEntity, String cpcSrcAttribute, View vTgt, String cpcTgtListEntity, String cpcTgtEAC, int lFlag) { StringBuilder sbAttributeValue = new StringBuilder(); Stack<ZNameItem> EntityStack = new Stack<ZNameItem>(); // tag stack (need not be unique) Stack<ZNameItem> AttributeStack = new Stack<ZNameItem>(); // tag stack (need not be unique) Stack<ZNameItem> ValueStack = new Stack<ZNameItem>(); // tag stack (need not be unique) Stack<ZNameItem> ContextStack = new Stack<ZNameItem>(); // tag stack (need not be unique) ZNameItem pEntityItem;//from w w w .j a v a 2s. com ZNameItem pAttribItem; ZNameItem pValueItem; ZNameItem pContextItem; String pch = null; String pchNext = null; StringBuilder sbLine = new StringBuilder(); StringBuilder sbNewline = new StringBuilder(); int nNewline; int ulCurrLth; int ulMaxLth; int lLineNbr; int lPos; int k; boolean bCreated; fnSetEntityAttribList(EntityStack, AttributeStack, ValueStack, ContextStack, cpcTgtListEntity, cpcTgtEAC); if (EntityStack.size() == 0 || AttributeStack.size() == 0) return -3; // entity.attribute.context parameter not well-formed pch = GetStringFromAttribute(pch, vSrc, cpcSrcEntity, cpcSrcAttribute); ulMaxLth = zstrlen(pch); // get true length lLineNbr = 0; ulCurrLth = 0; zstrcpy(sbLine, pch); while (ulCurrLth < ulMaxLth) { bCreated = false; lLineNbr++; if ((lFlag & 0x00000001) != 0) { nNewline = zstrstr(sbLine, ulCurrLth, "</p>"); lPos = ulCurrLth + 4; } else { nNewline = zstrstr(sbLine, ulCurrLth, "\r\n"); lPos = ulCurrLth; } if (nNewline >= 0) { pchNext = sbLine.substring(lPos, nNewline); ulCurrLth = nNewline; } else { pchNext = sbLine.substring(lPos); ulCurrLth = ulMaxLth; } // Run through the EA list. for (k = 0; k < AttributeStack.size() && (pAttribItem = AttributeStack.get(k)) != null; k++) { pEntityItem = EntityStack.get(k); pValueItem = ValueStack.get(k); pContextItem = ContextStack.get(k); if (pValueItem.getFlag() != 0) { if (bCreated = false && pValueItem.getName().isEmpty() == false) { bCreated = true; CreateEntity(vTgt, pEntityItem.getName(), zPOS_LAST); } if (pValueItem.getName().isEmpty() == false) SetAttributeFromString(vTgt, pEntityItem.getName(), pAttribItem.getName(), pValueItem.getName()); } else { pchNext = fnGetNextAttribute(pchNext, sbAttributeValue, lLineNbr); if (bCreated == false && sbAttributeValue.length() > 0) { bCreated = true; CreateEntity(vTgt, pEntityItem.getName(), zPOS_LAST); } if (sbAttributeValue.length() > 0) SetAttributeFromString(vTgt, pEntityItem.getName(), pAttribItem.getName(), sbAttributeValue.toString()); } } if (nNewline >= 0) { if ((lFlag & 0x00000001) != 0) { ulCurrLth += 4; } else { ulCurrLth += 2; } } } return 0; }
From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java
private boolean testPath(String location, String username) { File dest = LocationHelper.getFile(location, username, sample, sample.getImageFilename()); Stack<File> stack = new Stack<File>(); Stack<File> toDelete = new Stack<File>(); stack.push(dest);/*from w w w.j a v a 2s. co m*/ while ((dest = dest.getParentFile()) != null) { stack.push(dest); } try { while (!stack.isEmpty()) { File file = stack.pop(); if (file.exists()) { continue; } else { if (stack.isEmpty()) { if (!file.createNewFile()) { return false; } } else { if (!file.mkdir()) { return false; } } toDelete.add(file); } } } catch (IOException ex) { return false; } finally { while (!toDelete.isEmpty()) { toDelete.pop().delete(); } } return true; }
From source file:net.sf.jabref.bst.VM.java
public String run(Collection<BibEntry> bibtex) { // Reset//from w w w . j a v a 2 s.c o m bbl = new StringBuilder(); strings = new HashMap<>(); integers = new HashMap<>(); integers.put("entry.max$", Integer.MAX_VALUE); integers.put("global.max$", Integer.MAX_VALUE); functions = new HashMap<>(); functions.putAll(buildInFunctions); stack = new Stack<>(); // Create entries entries = new ArrayList<>(bibtex.size()); ListIterator<BstEntry> listIter = entries.listIterator(); for (BibEntry entry : bibtex) { listIter.add(new BstEntry(entry)); } // Go for (int i = 0; i < tree.getChildCount(); i++) { Tree child = tree.getChild(i); switch (child.getType()) { case BstParser.STRINGS: strings(child); break; case BstParser.INTEGERS: integers(child); break; case BstParser.FUNCTION: function(child); break; case BstParser.EXECUTE: execute(child); break; case BstParser.SORT: sort(); break; case BstParser.ITERATE: iterate(child); break; case BstParser.REVERSE: reverse(child); break; case BstParser.ENTRY: entry(child); break; case BstParser.READ: read(); break; case BstParser.MACRO: macro(child); break; default: LOGGER.info("Unknown type: " + child.getType()); break; } } return bbl.toString(); }
From source file:com.concursive.connect.web.webdav.servlets.WebdavServlet.java
/** * PROPFIND Method./*from w w w .ja v a 2s . c o m*/ * * @param context Description of the Parameter * @throws javax.servlet.ServletException Description of the Exception * @throws java.io.IOException Description of the Exception */ protected void doPropfind(ActionContext context) throws ServletException, IOException { String path = getRelativePath(context.getRequest()); //fix for windows clients if (path.equals("/files")) { path = ""; } if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } if ((path.toUpperCase().startsWith("/WEB-INF")) || (path.toUpperCase().startsWith("/META-INF"))) { context.getResponse().sendError(WebdavStatus.SC_FORBIDDEN); return; } // Properties which are to be displayed. Vector properties = null; // Propfind depth int depth = INFINITY; // Propfind type int type = FIND_ALL_PROP; String depthStr = context.getRequest().getHeader("Depth"); if (depthStr == null) { depth = INFINITY; } else { if (depthStr.equals("0")) { depth = 0; } else if (depthStr.equals("1")) { depth = 1; } else if (depthStr.equals("infinity")) { depth = INFINITY; } } /* * Read the request xml and determine all the properties */ /* Node propNode = null; DocumentBuilder documentBuilder = getDocumentBuilder(); try { Document document = documentBuilder.parse (new InputSource(context.getRequest().getInputStream())); // Get the root element of the document Element rootElement = document.getDocumentElement(); NodeList childList = rootElement.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); switch (currentNode.getNodeType()) { case Node.TEXT_NODE: break; case Node.ELEMENT_NODE: if (currentNode.getNodeName().endsWith("prop")) { type = FIND_BY_PROPERTY; propNode = currentNode; } if (currentNode.getNodeName().endsWith("propname")) { type = FIND_PROPERTY_NAMES; } if (currentNode.getNodeName().endsWith("allprop")) { type = FIND_ALL_PROP; } break; } } } catch (Exception e) { // Most likely there was no content : we use the defaults. // TODO : Enhance that ! e.printStackTrace(System.out); } if (type == FIND_BY_PROPERTY) { properties = new Vector(); NodeList childList = propNode.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); switch (currentNode.getNodeType()) { case Node.TEXT_NODE: break; case Node.ELEMENT_NODE: String nodeName = currentNode.getNodeName(); String propertyName = null; if (nodeName.indexOf(':') != -1) { propertyName = nodeName.substring (nodeName.indexOf(':') + 1); } else { propertyName = nodeName; } // href is a live property which is handled differently properties.addElement(propertyName); break; } } } */ // Properties have been determined // Retrieve the resources Connection db = null; boolean exists = true; boolean status = true; Object object = null; ModuleContext resources = null; StringBuffer xmlsb = new StringBuffer(); try { db = this.getConnection(context); resources = getCFSResources(db, context); if (resources == null) { context.getResponse().sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } object = resources.lookup(db, path); } catch (NamingException e) { //e.printStackTrace(System.out); exists = false; int slash = path.lastIndexOf('/'); if (slash != -1) { String parentPath = path.substring(0, slash); Vector currentLockNullResources = (Vector) lockNullResources.get(parentPath); if (currentLockNullResources != null) { Enumeration lockNullResourcesList = currentLockNullResources.elements(); while (lockNullResourcesList.hasMoreElements()) { String lockNullPath = (String) lockNullResourcesList.nextElement(); if (lockNullPath.equals(path)) { context.getResponse().setStatus(WebdavStatus.SC_MULTI_STATUS); context.getResponse().setContentType("text/xml; charset=UTF-8"); // Create multistatus object XMLWriter generatedXML = new XMLWriter(context.getResponse().getWriter()); generatedXML.writeXMLHeader(); generatedXML.writeElement(null, "multistatus" + generateNamespaceDeclarations(), XMLWriter.OPENING); parseLockNullProperties(context.getRequest(), generatedXML, lockNullPath, type, properties); generatedXML.writeElement(null, "multistatus", XMLWriter.CLOSING); generatedXML.sendData(); //e.printStackTrace(System.out); return; } } } } } catch (SQLException e) { e.printStackTrace(System.out); context.getResponse().sendError(SQLERROR, e.getMessage()); status = false; } finally { this.freeConnection(db, context); } if (!status) { return; } if (!exists) { context.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND, path); return; } context.getResponse().setStatus(WebdavStatus.SC_MULTI_STATUS); context.getResponse().setContentType("text/xml; charset=UTF-8"); // Create multistatus object ////System.out.println("Creating Multistatus Object"); XMLWriter generatedXML = new XMLWriter(context.getResponse().getWriter()); generatedXML.writeXMLHeader(); generatedXML.writeElement(null, "multistatus" + generateNamespaceDeclarations(), XMLWriter.OPENING); //System.out.println("Depth: " + depth); if (depth == 0) { parseProperties(context, resources, generatedXML, path, type, properties); } else { // The stack always contains the object of the current level Stack stack = new Stack(); stack.push(path); // Stack of the objects one level below Stack stackBelow = new Stack(); while ((!stack.isEmpty()) && (depth >= 0)) { String currentPath = (String) stack.pop(); if (!currentPath.equals(path)) { parseProperties(context, resources, generatedXML, currentPath, type, properties); } try { db = this.getConnection(context); object = resources.lookup(db, currentPath); } catch (NamingException e) { continue; } catch (SQLException e) { //e.printStackTrace(System.out); context.getResponse().sendError(SQLERROR, e.getMessage()); status = false; } finally { this.freeConnection(db, context); } if (!status) { return; } if ((object instanceof ModuleContext) && depth > 0) { // Get a list of all the resources at the current path and store them // in the stack try { NamingEnumeration enum1 = resources.list(currentPath); int count = 0; while (enum1.hasMoreElements()) { NameClassPair ncPair = (NameClassPair) enum1.nextElement(); String newPath = currentPath; if (!(newPath.endsWith("/"))) { newPath += "/"; } newPath += ncPair.getName(); stackBelow.push(newPath); count++; } if (currentPath.equals(path) && count == 0) { // This directory does not have any files or folders. parseProperties(context, resources, generatedXML, properties); } } catch (NamingException e) { //e.printStackTrace(System.out); context.getResponse().sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path); return; } // Displaying the lock-null resources present in that collection String lockPath = currentPath; if (lockPath.endsWith("/")) { lockPath = lockPath.substring(0, lockPath.length() - 1); } Vector currentLockNullResources = (Vector) lockNullResources.get(lockPath); if (currentLockNullResources != null) { Enumeration lockNullResourcesList = currentLockNullResources.elements(); while (lockNullResourcesList.hasMoreElements()) { String lockNullPath = (String) lockNullResourcesList.nextElement(); System.out.println("Lock null path: " + lockNullPath); parseLockNullProperties(context.getRequest(), generatedXML, lockNullPath, type, properties); } } } if (stack.isEmpty()) { depth--; stack = stackBelow; stackBelow = new Stack(); } xmlsb.append(generatedXML.toString()); //System.out.println("xml : " + generatedXML.toString()); generatedXML.sendData(); } } generatedXML.writeElement(null, "multistatus", XMLWriter.CLOSING); xmlsb.append(generatedXML.toString()); generatedXML.sendData(); //System.out.println("xml: " + xmlsb.toString()); }
From source file:gdt.data.store.Entigrator.java
/** * Get keys of entities having certain property name assigned. * @param propertyName$ property name./*from w w w. j av a 2 s . c o m*/ * @return array of entities keys. */ public String[] indx_listEntitiesAtPropertyName(String propertyName$) { if ("label".equals(propertyName$)) { return quickMap.elementListNoSorted("label"); } try { String property$ = propertyIndex.getElementItemAt("property", propertyName$); if (property$ == null) { LOGGER.severe(":indx_listEntitiesAtPropertyName:cannot find property in property index property =" + propertyName$); return null; } Sack property = getMember("property.base", property$); if (property == null) { LOGGER.severe(":indx_listEntitiesAtPropertyName:cannot find property =" + property$); return null; } Stack<String> s = new Stack<String>(); Stack<String> s2 = new Stack<String>(); if ("label".equals(propertyName$)) { Core[] ca = property.elementGet("value"); if (ca != null) for (Core aCa : ca) if (aCa.value != null) s.push(aCa.value); } else { String[] ma = property.elementList("value"); if (ma == null) { LOGGER.severe(":indx_listEntitiesAtPropertyName:no values in property =" + property$); return null; } Sack map; String[] ea; for (int i = 0; i < ma.length; i++) { s2.clear(); map = getMember("property.map.base", property.getElementItemAt("value", ma[i])); if (map == null) { LOGGER.severe(":indx_listEntitiesAtPropertyName:cannot get map[" + i + "]=" + ma[i]); continue; } ea = map.elementList("entity"); if (ea == null) { LOGGER.severe(":indx_listEntitiesAtPropertyName:empty map[" + i + "]=" + ma[i]); continue; } for (String anEa : ea) { if (!touchEntity(anEa)) s.push(anEa); } } } int cnt = s.size(); if (cnt < 1) { LOGGER.severe(":indx_listEntitiesAtPropertyName:no entities found"); return null; } String[] sa = new String[cnt]; for (int i = 0; i < cnt; i++) sa[i] = s.pop(); return sa; } catch (Exception e) { LOGGER.severe(":indx_listEntitiesAtPropertyName:" + e.toString()); return null; } }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected JComponent showWindowNewTab(Window window, String caption, String description, Integer tabPosition) { getDialogParams().reset();//w ww .j av a 2 s .com window.setWidth("100%"); window.setHeight("100%"); final WindowBreadCrumbs breadCrumbs = createBreadCrumbs(); stacks.put(breadCrumbs, new Stack<>()); breadCrumbs.addWindow(window); JComponent tabContent = createNewTab(window, caption, description, breadCrumbs, tabPosition); tabs.put(tabContent, breadCrumbs); return tabContent; }