List of usage examples for java.util Queue poll
E poll();
From source file:au.org.ala.delta.intkey.directives.BracketedTaxonListArgument.java
@Override public Pair<List<Item>, Boolean> parseInput(Queue<String> inputTokens, IntkeyContext context, String directiveName, StringBuilder stringRepresentationBuilder) throws IntkeyDirectiveParseException { List<String> selectedKeywordsOrTaxonNumbers = new ArrayList<String>(); boolean overrideExcludedTaxa = false; boolean inBrackets = false; String token = inputTokens.poll(); if (token != null && token.equalsIgnoreCase(OVERRIDE_EXCLUDED_TAXA)) { overrideExcludedTaxa = true;/* w w w . ja v a2 s.c o m*/ token = inputTokens.poll(); } boolean includeSpecimen = false; List<Item> taxa = null; SelectionMode selectionMode = context.displayKeywords() ? SelectionMode.KEYWORD : SelectionMode.LIST; if (token != null) { if (token.equalsIgnoreCase(DEFAULT_DIALOG_WILDCARD)) { // do nothing - default selection mode is already set above. } else if (token.equalsIgnoreCase(KEYWORD_DIALOG_WILDCARD)) { selectionMode = SelectionMode.KEYWORD; } else if (token.equalsIgnoreCase(LIST_DIALOG_WILDCARD)) { selectionMode = SelectionMode.LIST; } else if (token.equalsIgnoreCase(LIST_DIALOG_AUTO_SELECT_SOLE_ITEM_WILDCARD)) { selectionMode = SelectionMode.LIST_AUTOSELECT_SINGLE_VALUE; } else { taxa = new ArrayList<Item>(); if (token.equals(OPEN_BRACKET)) { inBrackets = true; token = inputTokens.poll(); } while (token != null) { if (token.equals(CLOSE_BRACKET)) { break; } try { if (token.equalsIgnoreCase(IntkeyContext.SPECIMEN_KEYWORD)) { includeSpecimen = true; } else { taxa.addAll(ParsingUtils.parseTaxonToken(token, context)); } selectedKeywordsOrTaxonNumbers.add(token); // If we are expecting a bracketed list, but no brackets // are present, // only parse the first token if (!inBrackets) { break; } token = inputTokens.poll(); } catch (IllegalArgumentException ex) { throw new IntkeyDirectiveParseException( String.format("Unrecognized taxon keyword %s", token)); } } if (!(overrideExcludedTaxa || _selectFromAll)) { taxa.retainAll(context.getIncludedTaxa()); } } } if (taxa == null) { inBrackets = true; // The specimen is included as an option for these prompts MutableBoolean specimenSelected = new MutableBoolean(false); List<String> selectedKeywords = new ArrayList<String>(); boolean includeSpecimenAsOption = !context.getSpecimen().getUsedCharacters().isEmpty(); DirectivePopulator populator = context.getDirectivePopulator(); if (selectionMode == SelectionMode.KEYWORD && context.displayKeywords()) { taxa = populator.promptForTaxaByKeyword(directiveName, !(overrideExcludedTaxa || _selectFromAll), _noneSelectionPermitted, includeSpecimenAsOption, specimenSelected, selectedKeywords); } else { boolean autoSelectSingleValue = (selectionMode == SelectionMode.LIST_AUTOSELECT_SINGLE_VALUE); taxa = populator.promptForTaxaByList(directiveName, !(overrideExcludedTaxa || _selectFromAll), autoSelectSingleValue, false, includeSpecimenAsOption, specimenSelected, selectedKeywords); } if (taxa == null) { // cancelled return null; } includeSpecimen = specimenSelected.booleanValue(); // Put selected keywords or taxon numbers into a collection to use // to build the string representation. if (!selectedKeywords.isEmpty()) { for (String selectedKeyword : selectedKeywords) { if (selectedKeyword.contains(" ")) { // Enclose any keywords that contain spaces in quotes // for the string representation selectedKeywordsOrTaxonNumbers.add("\"" + selectedKeyword + "\""); } else { selectedKeywordsOrTaxonNumbers.add(selectedKeyword); } } } else { List<Integer> selectedTaxonNumbers = new ArrayList<Integer>(); for (int i = 0; i < taxa.size(); i++) { Item taxon = taxa.get(i); selectedTaxonNumbers.add(taxon.getItemNumber()); } selectedKeywordsOrTaxonNumbers.add(Utils.formatIntegersAsListOfRanges(selectedTaxonNumbers)); } } // build the string representation of the directive call stringRepresentationBuilder.append(" "); if (overrideExcludedTaxa) { stringRepresentationBuilder.append(OVERRIDE_EXCLUDED_TAXA); stringRepresentationBuilder.append(" "); } if (inBrackets) { stringRepresentationBuilder.append(OPEN_BRACKET); } stringRepresentationBuilder.append(StringUtils.join(selectedKeywordsOrTaxonNumbers, " ")); if (inBrackets) { stringRepresentationBuilder.append(CLOSE_BRACKET); } if (taxa.size() == 0 && includeSpecimen == false && !_noneSelectionPermitted) { throw new IntkeyDirectiveParseException("NoTaxaInSet.error"); } Collections.sort(taxa); return new Pair<List<Item>, Boolean>(taxa, includeSpecimen); }
From source file:com.connection.factory.FtpConnectionApacheLib.java
@Override public List<RemoteFileObject> readAllFilesWalkinPath(String remotePath) { List<RemoteFileObject> willReturnObject = new ArrayList<>(); Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>(); RemoteFileObject object = null;/* ww w.ja va 2 s .c o m*/ object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); object.setDirectPath(remotePath); directorylist.add(object); try { while (!directorylist.isEmpty()) { object = directorylist.poll(); FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath()); for (FTPFile each : fileListTemp) { RemoteFileObject objectTemp = null; if (each.isDirectory()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); directorylist.add(objectTemp); } else if (each.isFile()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); objectTemp.setFileSize(each.getSize()); objectTemp.setFileType(); objectTemp.setDate(each.getTimestamp().getTime()); willReturnObject.add(objectTemp); } } object = null; fileListTemp = null; } } catch (IOException ex) { return null; } catch (ConnectionException ex) { } return willReturnObject; }
From source file:com.connection.factory.FtpConnectionApacheLib.java
@Override public void readAllFilesWalkingPathWithListener(FileListener listener, String remotePath) { // List<RemoteFileObject> willReturnObject = new ArrayList<>(); Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>(); RemoteFileObject object = null;/*from w ww.ja v a2 s. co m*/ object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); object.setDirectPath(remotePath); directorylist.add(object); try { while (!directorylist.isEmpty()) { object = directorylist.poll(); FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath()); for (FTPFile each : fileListTemp) { RemoteFileObject objectTemp = null; if (each.isDirectory()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); directorylist.add(objectTemp); } else if (each.isFile()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); objectTemp.setFileSize(each.getSize()); objectTemp.setFileType(); objectTemp.setDate(each.getTimestamp().getTime()); listener.handleRemoteFile(object); } } object = null; fileListTemp = null; } } catch (IOException | ConnectionException ex) { // return null; } // return willReturnObject; // return willReturnObject; }
From source file:org.apache.synapse.transport.passthru.DeliveryAgent.java
/** * Notification for a connection availability. When this occurs a message in the * queue for delivery will be tried.//from w w w.ja v a 2s. c o m * * @param host name of the remote host * @param port remote port number */ public void connected(HttpRoute route, NHttpClientConnection conn) { Queue<MessageContext> queue = null; lock.lock(); try { queue = waitingMessages.get(route); } finally { lock.unlock(); } while (queue.size() > 0) { if (conn == null) { conn = targetConnections.getExistingConnection(route); } if (conn != null) { MessageContext messageContext = queue.poll(); if (messageContext != null) { tryNextMessage(messageContext, route, conn); } conn = null; } else { break; } } }
From source file:org.apache.stratos.usage.agent.persist.UsageDataPersistenceTask.java
/** * this method create a Summarizer object for each tenant and call accumulate() method to * accumulate usage statistics/*w w w . ja v a 2 s. com*/ * * @param jobQueue usage data persistence jobs * @throws org.apache.stratos.usage.agent.exception.UsageException * */ public void persistUsage(Queue<BandwidthUsage> jobQueue) throws UsageException { // create a map to hold summarizer objects against tenant id HashMap<Integer, Summarizer> summarizerMap = new HashMap<Integer, Summarizer>(); // if the jobQueue is not empty for (int i = 0; i < configuration.getUsageTasksNumberOfRecordsPerExecution() && !jobQueue.isEmpty(); i++) { // get the first element from the queue, which is a BandwidthUsage object BandwidthUsage usage = jobQueue.poll(); // get the tenant id int tenantId = usage.getTenantId(); //get the Summarizer object corresponds to the tenant id Summarizer summarizer = summarizerMap.get(tenantId); // when tenant invoke service for the first time, no corresponding summarizer object in // the map if (summarizer == null) { //create a Summarizer object and put to the summarizerMap summarizer = new Summarizer(); summarizerMap.put(tenantId, summarizer); } // now accumulate usage summarizer.accumulate(usage); } //Finished accumulating. Now publish the events // get the collection view of values in summarizerMap Collection<Summarizer> summarizers = summarizerMap.values(); // for each summarizer object call the publish method for (Summarizer summarizer : summarizers) { summarizer.publish(); } }
From source file:de.tbuchloh.kiskis.gui.treeview.TreeView.java
/** * @return gets all the displayed tree nodes *///from w w w .ja v a 2s . c o m protected Collection<MyTreeNode> getAllNodes() { final Queue<MyTreeNode> treeNodes = new LinkedList<MyTreeNode>(); treeNodes.add(getRoot()); final Collection<MyTreeNode> r = new LinkedList<MyTreeNode>(); r.add(getRoot()); while (!treeNodes.isEmpty()) { final MyTreeNode node = treeNodes.poll(); final List<MyTreeNode> children = Collections.list(node.children()); treeNodes.addAll(children); r.addAll(children); } return r; }
From source file:org.kuali.rice.krad.uif.element.ValidationMessages.java
/** * Adds all group keys of this component (starting from this component itself) by calling getKeys on each of * its nested group's ValidationMessages and adding them to the list. * * @param keyList//from w ww .j a v a 2 s .c o m * @param component */ protected void addNestedGroupKeys(Collection<String> keyList, Component component) { @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); try { elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(component).values()); while (!elementQueue.isEmpty()) { LifecycleElement element = elementQueue.poll(); ValidationMessages ef = null; if (element instanceof ContainerBase) { ef = ((ContainerBase) element).getValidationMessages(); } else if (element instanceof FieldGroup) { ef = ((FieldGroup) element).getGroup().getValidationMessages(); } if (ef != null) { keyList.addAll(ef.getKeys((Component) element)); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(element).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }
From source file:org.siddhiesb.transport.passthru.DeliveryAgent.java
/** * This method queues the message for delivery. If a connection is already existing for * the destination epr, the message will be delivered immediately. Otherwise message has * to wait until a connection is established. In this case this method will inform the * system about the need for a connection. * * @param commonContext the message context to be sent */// w ww .j a va2 s . c o m public void submit(CommonContext commonContext) { try { String toAddress = (String) commonContext.getProperty(CommonAPIConstants.ENDPOINT); URL url = new URL(toAddress); String scheme = url.getProtocol() != null ? url.getProtocol() : "http"; String hostname = url.getHost(); int port = url.getPort(); if (port == -1) { // use default if ("http".equals(scheme)) { port = 80; } else if ("https".equals(scheme)) { port = 443; } } HttpHost target = new HttpHost(hostname, port, scheme); boolean secure = "https".equalsIgnoreCase(target.getSchemeName()); HttpHost proxy = null; //proxyConfig.selectProxy(target); HttpRoute route; if (proxy != null) { route = new HttpRoute(target, null, proxy, secure); } else { route = new HttpRoute(target, null, secure); } // first we queue the message Queue<CommonContext> queue = null; lock.lock(); try { queue = waitingMessages.get(route); if (queue == null) { queue = new ConcurrentLinkedQueue<CommonContext>(); waitingMessages.put(route, queue); } if (queue.size() == maxWaitingMessages) { CommonContext msgCtx = queue.poll(); } queue.add(commonContext); } finally { lock.unlock(); } NHttpClientConnection conn = targetConnections.getConnection(route); if (conn != null) { conn.resetInput(); conn.resetOutput(); CommonContext commonContext1 = queue.poll(); if (commonContext1 != null) { tryNextMessage(commonContext1, route, conn); } } } catch (MalformedURLException e) { handleException("Malformed URL in the target EPR", e); } }
From source file:dendroscope.autumn.hybridnetwork.ComputeHybridizationNetwork.java
/** * get all alive leaves below the given root * * @param root/*from w w w.j a v a 2 s . c om*/ * @return leaves */ private List<Root> getAllAliveLeaves(Root root) { List<Root> leaves = new LinkedList<Root>(); if (root.getTaxa().cardinality() > 0) { if (root.getOutDegree() == 0) leaves.add(root); else { Queue<Root> queue = new LinkedList<Root>(); queue.add(root); while (queue.size() > 0) { root = queue.poll(); for (Edge e = root.getFirstOutEdge(); e != null; e = root.getNextOutEdge(e)) { Root w = (Root) e.getTarget(); if (w.getTaxa().cardinality() > 0) { if (w.getOutDegree() == 0) leaves.add(w); else queue.add(w); } } } } } return leaves; }
From source file:it.geosolutions.geobatch.nrl.csvingest.CSVIngestAction.java
/** * /* www . j a v a 2 s. c o m*/ */ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.setTask("Check config"); // @autowired fields are injected *after* the checkConfiguration() is called checkInit(); listenerForwarder.started(); CSVIngestConfiguration configuration = getConfiguration(); if (configuration == null) { throw new IllegalStateException("ActionConfig is null."); } while (!events.isEmpty()) { EventObject event = events.poll(); if (event instanceof FileSystemEvent) { FileSystemEvent fse = (FileSystemEvent) event; File file = fse.getSource(); processCSVFile(file); // throw new ActionException(this, "Could not process " + event); } else { throw new ActionException(this, "EventObject not handled " + event); } } return new LinkedList<EventObject>(); }