List of usage examples for java.util Stack Stack
public Stack()
From source file:com.pvo.activity.MainFragmentActivity.java
public void redirectScreen(Fragment newFragment) { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); SupportMapFragment f = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap); if (f != null) fragmentTransaction.remove(f);//from w w w . j a va 2 s . c om Fragment visibleFragment = getVisibleFragment(); if (visibleFragment != null) fragmentTransaction.hide(visibleFragment); fragmentTransaction.add(R.id.content_frame, newFragment); if (fragmentStack != null) { fragmentStack.push(newFragment); } else { fragmentStack = new Stack<Fragment>(); fragmentStack.push(newFragment); } fragmentTransaction.commit(); }
From source file:it.ms.theing.loquitur.functions.Brain.java
/** * Process a phrase/*ww w . j a v a 2s . c o m*/ * @param phrase * the phrase usually understood by the recognizer * @return * The resulting logical analysis */ @JavascriptInterface public String process(String phrase) { try { root = dataBase.get("@"); Stack<Result> results = new Stack<Result>(); tokens = phrase.toLowerCase().split(separators); boolean a = match(root, tokens, results); JSONObject shell = new JSONObject(); try { shell.put("goal", a); if (a) { JSONObject json = new JSONObject(); for (Result res : results) { res.putJSON(json); } shell.put("args", json); } } catch (JSONException e) { } return shell.toString(); } catch (Exception e) { Utils.safe(e); } return "[ ]"; }
From source file:com.aurel.track.admin.customize.category.filter.execute.SavedFilterExecuteAction.java
/** * Saves the instant filter settings into the session *//*from w w w . j a v a 2 s.co m*/ public String applyInstant() { if (filterUpperTO == null) { //nothing was submitted to selects filterUpperTO = new FilterUpperTO(); } filterUpperTO.setFieldExpressionSimpleList(FilterSubmitHandler.createFieldExpressionSimpleListAfterSubmit( simpleMatcherRelationMap, simpleDisplayValueMap, locale)); List<FieldExpressionInTreeTO> fieldExpressionsInTreeListExecute = FilterSubmitHandler .createFieldExpressionInTreeListAfterSubmit(inTreeDisplayValueMap, inTreeMatcherRelationMap, fieldMap, fieldMomentMap, operationMap, parenthesisOpenedMap, parenthesisClosedMap, fieldExpressionOrderMap, locale); /*List<FieldExpressionInTreeTO> fieldExpressionsInTreeListEdit = FilterSubmitHandler.createFieldExpressionInTreeListAfterSubmit( inTreeDisplayValueMap, inTreeMatcherRelationMap, fieldMap, fieldMomentMap, operationMap, parenthesisOpenedMap, parenthesisClosedMap, fieldExpressionOrderMap, locale);*/ /** * transform the custom selections strings to Integer[] because struts can't submit to Map<Integer, Integer[]> */ Map<Integer, Integer> customSelectSimpleFields = new HashMap<Integer, Integer>(); Map<Integer, String> selectedCustomSelectsStr = filterUpperTO.getSelectedCustomSelectsStr(); Map<Integer, Integer[]> selectedCustomSelects = filterUpperTO.getSelectedCustomSelects(); if (selectedCustomSelectsStr != null) { if (selectedCustomSelects == null) { selectedCustomSelects = new HashMap<Integer, Integer[]>(); filterUpperTO.setSelectedCustomSelects(selectedCustomSelects); } for (Integer fieldID : selectedCustomSelectsStr.keySet()) { String selections = selectedCustomSelectsStr.get(fieldID); if (selections != null) { selectedCustomSelects.put(fieldID, FilterUpperTO.createIntegerArrFromString(selections)); } customSelectSimpleFields.put(fieldID, FieldBL.getSystemOptionType(fieldID)); } filterUpperTO.setCustomSelectSimpleFields(customSelectSimpleFields); } session.put(FilterBL.FILTER_UPPER_APPLY_EXECUTE + filterID + "_" + filterType, filterUpperTO); //FilterUpperTO filterUpperTOForEdit = filterUpperTO.copy(); //session.put(FilterBL.FILTER_UPPER_APPLY_EDIT + filterID + "_" + filterType, filterUpperTOForEdit); try { QNode rootNode = TreeFilterSaverBL.transformExpressionListToTree(fieldExpressionsInTreeListExecute, new Stack<QNode>()); if (rootNode != null) { session.put(FilterBL.TREE_APPLY_EXECUTE + filterID + "_" + filterType, rootNode); } else { session.remove(FilterBL.TREE_APPLY_EXECUTE + filterID + "_" + filterType); } } catch (Exception e) { String errorKey = e.getMessage(); String errorMessage = LocalizeUtil.getLocalizedTextFromApplicationResources(errorKey, locale); LOGGER.warn("Transforming the instant query to expression failed with " + errorMessage); JSONUtility.encodeJSONFailure(servletResponse, errorMessage); } /*try { QNode rootNode = TreeFilterSaverBL.transformExpressionListToTree(fieldExpressionsInTreeListEdit, new Stack<QNode>()); if (rootNode!=null) { session.put(FilterBL.TREE_APPLY_EDIT + filterID + "_" + filterType, rootNode); } } catch (Exception e) { String errorKey = e.getMessage(); String errorMessage = LocalizeUtil.getLocalizedTextFromApplicationResources(errorKey, locale); LOGGER.warn("Transforming the instant query to expression failed with " + errorMessage); JSONUtility.encodeJSONFailure(servletResponse, errorMessage); }*/ JSONUtility.encodeJSONSuccess(servletResponse); return null; }
From source file:com.pvo.activity.MainFragmentActivity.java
public void redirectScreenWithoutStack(Fragment newFragment) { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); SupportMapFragment f = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap); if (f != null) fragmentTransaction.remove(f);/*from w ww . j a va 2 s. co m*/ fragmentStack = new Stack<Fragment>(); Fragment visibleFragment = getVisibleFragment(); if (visibleFragment != null) fragmentTransaction.hide(visibleFragment); fragmentTransaction.add(R.id.content_frame, newFragment); fragmentStack.push(newFragment); fragmentTransaction.commit(); }
From source file:com.sun.socialsite.pojos.PropDefinition.java
protected void init(PropDefinition profileDef, InputStream input) throws SocialSiteException { try {/* w w w .j av a 2 s.c om*/ XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(input); String ns = null; // TODO: namespace for ProfileDef // hold the current things we're working on Map<String, DisplaySectionDefinition> sdefs = new LinkedHashMap<String, DisplaySectionDefinition>(); Stack<PropertyDefinitionHolder> propertyHolderStack = new Stack<PropertyDefinitionHolder>(); List<AllowedValue> allowedValues = null; PropertyDefinition pdef = null; for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { switch (event) { case XMLStreamConstants.START_ELEMENT: log.debug("START ELEMENT -- " + parser.getLocalName()); if ("display-section".equals(parser.getLocalName())) { propertyHolderStack.push(new DisplaySectionDefinition(parser.getAttributeValue(ns, "name"), parser.getAttributeValue(ns, "namekey"))); } else if ("property".equals(parser.getLocalName())) { PropertyDefinitionHolder holder = propertyHolderStack.peek(); pdef = new PropertyDefinition(holder.getBasePath(), parser.getAttributeValue(ns, "name"), parser.getAttributeValue(ns, "namekey"), parser.getAttributeValue(ns, "type")); } else if ("object".equals(parser.getLocalName())) { PropertyDefinitionHolder holder = propertyHolderStack.peek(); propertyHolderStack.push(new PropertyObjectDefinition(holder.getBasePath(), parser.getAttributeValue(ns, "name"), parser.getAttributeValue(ns, "namekey"))); } else if ("collection".equals(parser.getLocalName())) { PropertyDefinitionHolder holder = propertyHolderStack.peek(); propertyHolderStack.push(new PropertyObjectCollectionDefinition(holder.getBasePath(), parser.getAttributeValue(ns, "name"), parser.getAttributeValue(ns, "namekey"))); } else if ("allowed-values".equals(parser.getLocalName())) { allowedValues = new ArrayList<AllowedValue>(); } else if ("value".equals(parser.getLocalName())) { AllowedValue allowedValue = new AllowedValue(parser.getAttributeValue(ns, "name"), parser.getAttributeValue(ns, "namekey")); allowedValues.add(allowedValue); } else if ("default-value".equals(parser.getLocalName())) { pdef.setDefaultValue(parser.getText()); } break; case XMLStreamConstants.END_ELEMENT: log.debug("END ELEMENT -- " + parser.getLocalName()); if ("display-section".equals(parser.getLocalName())) { DisplaySectionDefinition sdef = (DisplaySectionDefinition) propertyHolderStack.pop(); sdefs.put(sdef.getName(), sdef); } else if ("property".equals(parser.getLocalName())) { PropertyDefinitionHolder holder = propertyHolderStack.peek(); holder.getPropertyDefinitions().add(pdef); propertyDefs.put(pdef.getName(), pdef); pdef = null; } else if ("object".equals(parser.getLocalName())) { PropertyObjectDefinition odef = (PropertyObjectDefinition) propertyHolderStack.pop(); PropertyDefinitionHolder holder = propertyHolderStack.peek(); holder.getPropertyObjectDefinitions().add(odef); // add to list of all property object defs propertyObjectDefs.put(odef.getName(), odef); odef = null; } else if ("collection".equals(parser.getLocalName())) { PropertyObjectCollectionDefinition cdef = (PropertyObjectCollectionDefinition) propertyHolderStack .pop(); PropertyDefinitionHolder holder = propertyHolderStack.peek(); holder.getPropertyObjectCollectionDefinitions().add(cdef); // add to list of all property object defs propertyObjectCollectionDefs.put(cdef.getName(), cdef); cdef = null; } else if ("allowed-values".equals(parser.getLocalName())) { pdef.setAllowedValues(allowedValues); allowedValues = null; } break; case XMLStreamConstants.CHARACTERS: break; case XMLStreamConstants.CDATA: break; } // end switch } // end while parser.close(); profileDef.sectionDefs = sdefs; } catch (Exception ex) { throw new SocialSiteException("ERROR parsing profile definitions", ex); } }
From source file:edu.isi.karma.er.helper.SPARQLGeneratorUtil.java
private String checkParentMarked(TriplesMap triple, HashMap<TriplesMap, String> markedTriples, String var1) { Stack<String> stk = new Stack<>(); ParentMapingInfo parentTriple = this.ParentMapingInfoList.get(triple.getSubject().getId()); boolean markedParent = false; int count = 1; String previous = var1; while (parentTriple != null) { String predicate = parentTriple.predicate.getTemplate().toString(); if (markedTriples.get(parentTriple.parent) == null) { markedTriples.put(parentTriple.parent, "Z" + count); String rdfsTypes = parentTriple.parent.getSubject().getRdfsType().get(0).toString(); this.prefix_list.put("pref" + "Z" + count, rdfsTypes); stk.push(" ?Z" + count + " a pref" + "Z" + count + ": ."); stk.push(" ?" + markedTriples.get(parentTriple.parent) + " " + predicate + " ?" + previous + " . "); } else {//from ww w .ja v a2 s . co m stk.push(" ?" + markedTriples.get(parentTriple.parent) + " " + predicate + " ?" + previous + " . "); markedParent = true; break; } previous = markedTriples.get(parentTriple.parent); parentTriple = this.ParentMapingInfoList.get(parentTriple.parent.getSubject().getId()); if (parentTriple == null) { break; } var1 = markedTriples.get(parentTriple.parent); // if(markedTriples.containsKey(parentTriple.parent)) { // markedParent = true; // stk.push(" ?" + markedTriples.get(parentTriple.parent) + " " + // predicate + " ?"+var1 + " . "); // break; // } } if (markedParent) { return StringUtils.join(stk, " "); } return ""; }
From source file:ch.entwine.weblounge.contentrepository.impl.fs.FileSystemContentRepository.java
/** * {@inheritDoc}/*from w w w. ja v a 2 s . c o m*/ * * @see ch.entwine.weblounge.contentrepository.impl.AbstractContentRepository#listResources() */ @Override protected Collection<ResourceURI> listResources() throws IOException { List<ResourceURI> uris = new ArrayList<ResourceURI>(); // Add all known resource types to the index for (ResourceSerializer<?, ?> serializer : getSerializers()) { // Temporary path for rebuilt site String resourceType = serializer.getType().toLowerCase(); String resourceDirectory = resourceType + "s"; String homePath = UrlUtils.concat(repositorySiteRoot.getAbsolutePath(), resourceDirectory); File resourcesRootDirectory = new File(homePath); if (!resourcesRootDirectory.isDirectory() || resourcesRootDirectory.list().length == 0) { logger.debug("No {}s found to index", resourceType); continue; } try { Stack<File> u = new Stack<File>(); u.push(resourcesRootDirectory); while (!u.empty()) { File dir = u.pop(); File[] files = dir.listFiles(new FileFilter() { public boolean accept(File path) { if (path.getName().startsWith(".")) return false; return path.isDirectory() || path.getName().endsWith(".xml"); } }); if (files == null || files.length == 0) continue; for (File f : files) { if (f.isDirectory()) { u.push(f); } else { long version = Long.parseLong(f.getParentFile().getName()); String id = f.getParentFile().getParentFile().getName(); ResourceURI uri = new ResourceURIImpl(resourceType, getSite(), null, id, version); uris.add(uri); } } } } catch (Throwable t) { logger.error("Error reading available uris from file system: {}", t.getMessage()); throw new IOException(t); } } return uris; }
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)); }// w ww . j ava 2s .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:de.tudarmstadt.ukp.dkpro.lexsemresource.graph.EntityGraphJUNG.java
/** * Computes the depth of the graph, i.e. the maximum path length starting * with the root node (if a single root exists) * * @return The depth of the hierarchy.//from w ww .j ava2s . co m */ @Override public double getDepth() { List<Entity> roots = new Stack<Entity>(); roots.addAll(getRoots()); if (roots.size() == 0) { logger.error("There is no root for this lexical semantic resource."); return Double.NaN; } else if (roots.size() > 1) { logger.error("There are several roots for this lexical semantic resource."); return Double.NaN; } else { Entity root = roots.get(0); // return getEccentricity(root); double maxPathLength = 0.0; double[] returnValues = computeShortestPathLengths(root, 0.0, maxPathLength, new HashSet<Entity>()); maxPathLength = returnValues[1]; return maxPathLength; } }
From source file:fr.paris.lutece.plugins.upload.web.UploadJspBean.java
/** * Returns the total size of a directory. * @param directory The directory/* w w w.ja v a 2s .c om*/ * @return The total size */ private static long getDirectorySize(File directory) { long lResult = 0; // We use a Stack (LIFO) to keep track of the unprocessed directories Stack<File> dirsToProcess = new Stack<File>(); // The stack is initialized with the main directory dirsToProcess.push(directory); // Loop until all directories have been processed while (!dirsToProcess.empty()) { // Get a new directory from the stack File currentDir = dirsToProcess.pop(); // Don't forget the directory's own size! lResult += currentDir.length(); // Add the local files' size to the global size File[] files = currentDir.listFiles(fileFilter); for (int i = 0; i < files.length; i++) { lResult += files[i].length(); } // Add the sub-directories to the stack File[] subDirs = currentDir.listFiles(dirFilter); for (int i = 0; i < subDirs.length; i++) { dirsToProcess.push(subDirs[i]); } } return lResult; }