List of usage examples for java.util Stack pop
public synchronized E pop()
From source file:com.joliciel.csvLearner.features.NormalisationLimitReader.java
public Map<String, Float> read() { Map<String, Float> featureToMaxMap = new TreeMap<String, Float>(); try {//from w w w .j a v a 2s.co m if (inputStream != null) { this.readCSVFile(inputStream, featureToMaxMap); } else if (file.isDirectory()) { Stack<File> directoryStack = new Stack<File>(); directoryStack.add(file); while (!directoryStack.isEmpty()) { File directory = directoryStack.pop(); LOG.debug("Scanning directory: " + directory.getName()); File[] files = directory.listFiles(); if (files == null) { continue; } for (File oneFile : files) { if (oneFile.isDirectory()) { directoryStack.push(oneFile); } else if (oneFile.getName().endsWith(".nrm_limits.csv")) { LOG.debug("Scanning limits file : " + oneFile.getName()); this.readCSVFile(new FileInputStream(oneFile), featureToMaxMap); } else { LOG.trace("Ignoring : " + oneFile.getName()); } } } } else { LOG.debug("Scanning limits file : " + file.getName()); this.readCSVFile(new FileInputStream(file), featureToMaxMap); } } catch (FileNotFoundException e) { throw new RuntimeException(e); } return featureToMaxMap; }
From source file:com.amalto.webapp.core.util.Util.java
public static WSWhereItem makeWhereItem(List<WSWhereItem> conditions) { List<Object> conds = new ArrayList<Object>(); for (int i = 0; i < conditions.size(); i++) { WSWhereItem item = conditions.get(i); conds.add(item);/*from ww w . j av a 2 s .c om*/ if (i < conditions.size() - 1) { WSStringPredicate predicate = item.getWhereCondition().getStringPredicate(); switch (predicate) { case NOT: case EXACTLY: case STRICTAND: case NONE: predicate = WSStringPredicate.AND; break; } conds.add(predicate); } } Stack<WSStringPredicate> stackOp = new Stack<WSStringPredicate>(); List<Object> rpn = new ArrayList<Object>(); for (Object item : conds) { if (item instanceof WSWhereItem) { rpn.add(item); } else { WSStringPredicate predicate = (WSStringPredicate) item; while (!stackOp.isEmpty()) { rpn.add(stackOp.pop()); } stackOp.push(predicate); } } while (!stackOp.isEmpty()) { rpn.add(stackOp.pop()); } Stack<WSWhereItem> whereStack = new Stack<WSWhereItem>(); for (Object o : rpn) { if (o instanceof WSWhereItem) { whereStack.push((WSWhereItem) o); } else if (o instanceof WSStringPredicate) { if (WSStringPredicate.OR.equals(o)) { WSWhereItem item1 = whereStack.pop(); WSWhereItem item2 = whereStack.pop(); WSWhereOr or = new WSWhereOr(new WSWhereItem[] { item2, item1 }); whereStack.push(new WSWhereItem(null, null, or)); } else if (WSStringPredicate.AND.equals(o)) { WSWhereItem item1 = whereStack.pop(); WSWhereItem item2 = whereStack.pop(); WSWhereAnd and = new WSWhereAnd(new WSWhereItem[] { item2, item1 }); whereStack.push(new WSWhereItem(null, and, null)); } } } return whereStack.pop(); }
From source file:io.fabric8.maven.enricher.fabric8.AbstractLiveEnricher.java
/** * Returns the external access to the given service name * * @param serviceName name of the service * @param protocol URL protocol such as <code>http</code> *//* w w w . j ava2 s . co m*/ protected String getExternalServiceURL(String serviceName, String protocol) { if (!isOnline()) { getLog().info("Not looking for service " + serviceName + " as we are in offline mode"); return null; } else { try { KubernetesClient kubernetes = getKubernetes(); String ns = kubernetes.getNamespace(); if (StringUtils.isBlank(ns)) { ns = getNamespace(); } Service service = kubernetes.services().inNamespace(ns).withName(serviceName).get(); return service != null ? ServiceUrlUtil.getServiceURL(kubernetes, serviceName, ns, protocol, true) : null; } catch (Throwable e) { Throwable cause = e; boolean notFound = false; boolean connectError = false; Stack<Throwable> stack = unfoldExceptions(e); while (!stack.isEmpty()) { Throwable t = stack.pop(); if (t instanceof ConnectException || "No route to host".equals(t.getMessage())) { getLog().warn("Cannot connect to Kubernetes to find URL for service %s : %s", serviceName, cause.getMessage()); return null; } else if (t instanceof IllegalArgumentException || t.getMessage() != null && t.getMessage().matches("^No.*found.*$")) { getLog().warn("%s", cause.getMessage()); return null; } ; } getLog().warn("Cannot find URL for service %s : %s", serviceName, cause.getMessage()); return null; } } }
From source file:com.joliciel.jochre.stats.DBSCANClusterer.java
private void expandCluster(int index, Set<Integer> neighbours, Set<T> cluster, double epsilon, int minPoints) { /*//from ww w . j a v a2 s.co m expandCluster(P, N, C, eps, MinPts) add P to cluster C for each point P' in N if P' is not visited mark P' as visited N' = getNeighbors(P', eps) if sizeof(N') >= MinPts N = N joined with N' if P' is not yet member of any cluster add P' to cluster C */ cluster.add(objectSet.get(index)); clusterList.set(index, cluster); Stack<Integer> points = new Stack<Integer>(); points.addAll(neighbours); while (!points.isEmpty()) { int i = points.pop(); if (!visited[i]) { visited[i] = true; Set<Integer> nPrime = this.getNeighbours(i, epsilon); if (nPrime.size() >= minPoints - 1) { points.addAll(nPrime); } } if (clusterList.get(i) == null) { cluster.add(objectSet.get(i)); clusterList.set(i, cluster); } } }
From source file:com.frostwire.android.gui.Librarian.java
/** * Given a folder path it'll return all the files contained within it and it's subfolders * as a flat set of Files.//from w ww . ja va2 s . c o m * <p> * Non-recursive implementation, up to 20% faster in tests than recursive implementation. :) * * @param folder * @param extensions If you only need certain files filtered by their extensions, use this string array (without the "."). or set to null if you want all files. e.g. ["txt","jpg"] if you only want text files and jpegs. * @return The set of files. * @author gubatron */ private static Collection<File> getAllFolderFiles(File folder, String[] extensions) { Set<File> results = new HashSet<>(); Stack<File> subFolders = new Stack<>(); File currentFolder = folder; while (currentFolder != null && currentFolder.isDirectory() && currentFolder.canRead()) { File[] fs = null; try { fs = currentFolder.listFiles(); } catch (SecurityException e) { } if (fs != null && fs.length > 0) { for (File f : fs) { if (!f.isDirectory()) { if (extensions == null || FilenameUtils.isExtension(f.getName(), extensions)) { results.add(f); } } else { subFolders.push(f); } } } if (!subFolders.isEmpty()) { currentFolder = subFolders.pop(); } else { currentFolder = null; } } return results; }
From source file:org.apache.hadoop.hbase.filter.ParseFilter.java
/** * Pops an argument from the operator stack and the number of arguments required by the operator * from the filterStack and evaluates them * <p>//from www. j ava 2s.c o m * @param operatorStack the stack containing the operators * @param filterStack the stack containing the filters * @return the evaluated filter */ public static Filter popArguments(Stack<ByteBuffer> operatorStack, Stack<Filter> filterStack) { ByteBuffer argumentOnTopOfStack = operatorStack.peek(); if (argumentOnTopOfStack.equals(ParseConstants.OR_BUFFER)) { // The top of the stack is an OR try { ArrayList<Filter> listOfFilters = new ArrayList<Filter>(); while (!operatorStack.empty() && operatorStack.peek().equals(ParseConstants.OR_BUFFER)) { Filter filter = filterStack.pop(); listOfFilters.add(0, filter); operatorStack.pop(); } Filter filter = filterStack.pop(); listOfFilters.add(0, filter); Filter orFilter = new FilterList(FilterList.Operator.MUST_PASS_ONE, listOfFilters); return orFilter; } catch (EmptyStackException e) { throw new IllegalArgumentException("Incorrect input string - an OR needs two filters"); } } else if (argumentOnTopOfStack.equals(ParseConstants.AND_BUFFER)) { // The top of the stack is an AND try { ArrayList<Filter> listOfFilters = new ArrayList<Filter>(); while (!operatorStack.empty() && operatorStack.peek().equals(ParseConstants.AND_BUFFER)) { Filter filter = filterStack.pop(); listOfFilters.add(0, filter); operatorStack.pop(); } Filter filter = filterStack.pop(); listOfFilters.add(0, filter); Filter andFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL, listOfFilters); return andFilter; } catch (EmptyStackException e) { throw new IllegalArgumentException("Incorrect input string - an AND needs two filters"); } } else if (argumentOnTopOfStack.equals(ParseConstants.SKIP_BUFFER)) { // The top of the stack is a SKIP try { Filter wrappedFilter = filterStack.pop(); Filter skipFilter = new SkipFilter(wrappedFilter); operatorStack.pop(); return skipFilter; } catch (EmptyStackException e) { throw new IllegalArgumentException("Incorrect input string - a SKIP wraps a filter"); } } else if (argumentOnTopOfStack.equals(ParseConstants.WHILE_BUFFER)) { // The top of the stack is a WHILE try { Filter wrappedFilter = filterStack.pop(); Filter whileMatchFilter = new WhileMatchFilter(wrappedFilter); operatorStack.pop(); return whileMatchFilter; } catch (EmptyStackException e) { throw new IllegalArgumentException("Incorrect input string - a WHILE wraps a filter"); } } else if (argumentOnTopOfStack.equals(ParseConstants.LPAREN_BUFFER)) { // The top of the stack is a LPAREN try { Filter filter = filterStack.pop(); operatorStack.pop(); return filter; } catch (EmptyStackException e) { throw new IllegalArgumentException("Incorrect Filter String"); } } else { throw new IllegalArgumentException("Incorrect arguments on operatorStack"); } }
From source file:org.apache.fop.render.rtf.rtflib.tools.BuilderContext.java
/** find first object of given class from top of stack s * @return null if not found// w ww .j a va 2 s . c o m */ private Object getObjectFromStack(Stack s, Class desiredClass) { Object result = null; final Stack copy = (Stack) s.clone(); while (!copy.isEmpty()) { final Object o = copy.pop(); if (desiredClass.isAssignableFrom(o.getClass())) { result = o; break; } } return result; }
From source file:SpectraFrame.java
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked // TODO add your handling code here: String input = moleculefield.getText(); NMR mynmr = new NMR(input, "1H"); ChartPanel thechart = new ChartPanel(mynmr.getchart().getchart()); spectrumarea.setLayout(new java.awt.BorderLayout()); spectrumarea.add(thechart, BorderLayout.CENTER); spectrumarea.validate();/*from ww w . j ava2 s . c o m*/ Stack<Double> thevalues = mynmr.getvalues(); String finalstring = ""; for (int i = 0; i < thevalues.size(); i++) { finalstring = finalstring + thevalues.peek(); thevalues.pop(); } jButton1.setEnabled(false); }
From source file:org.apache.synapse.endpoints.DefaultEndpoint.java
public void onFault(MessageContext synCtx) { // perform retries here if (parentEndpoint != null) { parentEndpoint.onChildEndpointFail(this, synCtx); } else {/* w w w .j a va2 s.c o m*/ Stack faultStack = synCtx.getFaultStack(); if (!faultStack.isEmpty()) { ((FaultHandler) faultStack.pop()).handleFault(synCtx); } } }
From source file:eu.annocultor.utils.HierarchyTracingFilter.java
private Set<String> traceBroaderDepthFirst(RepositoryConnection connection, ValueFactory factory, List<StringInStack> topConcepts) throws Exception { // trace skos:broader tree top-down Stack<StringInStack> urlsToCheck = new Stack<StringInStack>(); urlsToCheck.addAll(topConcepts);//from ww w . j a va 2 s.c o m Set<String> passedUrls = new HashSet<String>(); while (!urlsToCheck.isEmpty()) { StringInStack url = urlsToCheck.pop(); if (!StringUtils.isEmpty(url.getString()) && passedUrls.add(url.getString())) { List<StringInStack> children = fetchNarrower(connection, factory, url, urlsToCheck.isEmpty() ? null : urlsToCheck.peek()); Collections.sort(children); urlsToCheck.addAll(children); } } return passedUrls; }