List of usage examples for java.util Queue remove
E remove();
From source file:sadl.models.pdrta.PDRTA.java
@Override public int getTransitionCount() { int result = 0; final Queue<PDRTAState> q = new ArrayDeque<>(); final Set<PDRTAState> found = new HashSet<>(); q.add(root);//from w ww. j ava 2 s. c om found.add(root); while (!q.isEmpty()) { final PDRTAState s = q.remove(); for (int i = 0; i < input.getAlphSize(); i++) { final Set<Entry<Integer, Interval>> ins = s.getIntervals(i).entrySet(); for (final Entry<Integer, Interval> eIn : ins) { final Interval in = eIn.getValue(); final PDRTAState t = in.getTarget(); if (t != null) { result++; } } } } return result; }
From source file:candr.yoclip.Parser.java
/** * Creates a {@code ParsedOptionParameter} for the argument at the head of the queue. The value of the parsed option will contain the argument * value. The parsed option parameter will contain an error if the bean does not have an arguments annotation.. * * @param parameters The current queue of command parameters. * @return a parsed option parameter or {@code null} if the parameters queue is empty. *//*from w ww.ja v a 2 s. co m*/ protected ParsedOption<T> getParsedArgument(final Queue<String> parameters) { ParsedOption<T> parsedOption = null; if (!parameters.isEmpty()) { final ParserOption<T> arguments = getParserOptions().getArguments(); final String parameter = parameters.remove(); if (null != arguments) { parsedOption = new ParsedOption<T>(arguments, parameter); } else { parsedOption = new ParsedOption<T>(getParserOptions().getName() + " does not have arguments."); } } return parsedOption; }
From source file:org.openhab.binding.networkhealth.discovery.NetworkHealthDiscoveryService.java
/** * Starts the DiscoveryThread for each IP on the Networks * @param allNetworkIPs//from w w w. jav a 2 s . co m */ private void startDiscovery(final Queue<String> networkIPs) { Runnable runnable = new Runnable() { public void run() { DiscoveryThread discoveryThread = null; DiscoveryThreadResult discoveryThreadResult = new DiscoveryThreadResult() { @Override public void newDevice(String ip) { submitDiscoveryResults(ip); } }; // ensures that only one thread at a time access the queue synchronized (lockObject) { if (networkIPs.isEmpty()) { discoveryJob.cancel(false); } else { discoveryThread = new DiscoveryThread(networkIPs.remove(), discoveryThreadResult); } } if (discoveryThread != null) discoveryThread.start(); } }; /* Every milisecond a new thread will be created. Due to the fact that the PING has a timeout of 1 sec, * only about 1000 Threads will be create at max */ discoveryJob = scheduler.scheduleAtFixedRate(runnable, 0, TASK_CREATING_TIME_IN_MS, TimeUnit.MILLISECONDS); }
From source file:ubic.basecode.dataStructure.graph.DirectedGraph.java
/** * Fills in the topoSortOrder for each node. *//*from w w w. j a va 2 s . co m*/ public void topoSort() { Queue<DirectedGraphNode<K, V>> q = new LinkedList<DirectedGraphNode<K, V>>(); int counter = 0; Map<DirectedGraphNode<K, V>, Integer> degrees = new HashMap<DirectedGraphNode<K, V>, Integer>(); /* Get the degrees of all items, and enqueue zero-indegree nodes */ for (K element : this.items.keySet()) { DirectedGraphNode<K, V> v = items.get(element); degrees.put(v, new Integer(v.inDegree())); if (degrees.get(v).intValue() == 0) { q.offer(v); } } while (!q.isEmpty()) { DirectedGraphNode<K, V> v = q.remove(); v.setTopoSortOrder(++counter); for (DirectedGraphNode<K, V> w : v.getChildNodes()) { /* decrement the degree of this node */ int inDegree = degrees.get(w).intValue(); inDegree--; degrees.put(w, new Integer(inDegree)); /* see if this now is one of the zero-indegree nodes */ if (inDegree == 0) { q.offer(w); } } } if (counter != items.size()) { throw new IllegalStateException( "Graph contains a cycle; " + counter + " items found, " + items.size() + " expected"); } }
From source file:org.wso2.carbon.andes.event.core.internal.subscription.registry.TopicManagerServiceImpl.java
/** * {@inheritDoc}//from w w w .j a va 2 s.c om */ @Override public Subscription[] getSubscriptions(String topicName, boolean withChildren) throws EventBrokerException { List<Subscription> subscriptions = new ArrayList<Subscription>(); Queue<String> pathsQueue = new LinkedList<String>(); String resourcePath = JavaUtil.getResourcePath(topicName, this.topicStoragePath); pathsQueue.add(resourcePath); while (!pathsQueue.isEmpty()) { addSubscriptions(pathsQueue.remove(), subscriptions, pathsQueue, withChildren); } return subscriptions.toArray(new Subscription[subscriptions.size()]); }
From source file:org.commonjava.maven.ext.io.rest.DefaultTranslator.java
/** * Translate the versions.// w w w .ja v a 2 s . co m * <pre>{@code * [ { * "groupId": "com.google.guava", * "artifactId": "guava", * "version": "13.0.1" * } } * }</pre> * This equates to a List of ProjectVersionRef. * * <pre>{@code * { * "productNames": [], * "productVersionIds": [], * "repositoryGroup": "", * "gavs": [ * { * "groupId": "com.google.guava", * "artifactId": "guava", * "version": "13.0.1" * } ] * } * }</pre> * There may be a lot of them, possibly causing timeouts or other issues. * This is mitigated by splitting them into smaller chunks when an error occurs and retrying. */ public Map<ProjectVersionRef, String> translateVersions(List<ProjectVersionRef> projects) { init(rgm); final Map<ProjectVersionRef, String> result = new HashMap<>(); final Queue<Task> queue = new ArrayDeque<>(); if (initialRestMaxSize != 0) { // Presplit final List<List<ProjectVersionRef>> partition = ListUtils.partition(projects, initialRestMaxSize); for (List<ProjectVersionRef> p : partition) { queue.add(new Task(rgm, p, endpointUrl + REPORTS_LOOKUP_GAVS)); } logger.debug("For initial sizing of {} have split the queue into {} ", initialRestMaxSize, queue.size()); } else { queue.add(new Task(rgm, projects, endpointUrl + REPORTS_LOOKUP_GAVS)); } while (!queue.isEmpty()) { Task task = queue.remove(); task.executeTranslate(); if (task.isSuccess()) { result.putAll(task.getResult()); } else { if (task.canSplit() && task.getStatus() == 504) { List<Task> tasks = task.split(); logger.warn( "Failed to translate versions for task @{} due to {}, splitting and retrying. Chunk size was: {} and new chunk size {} in {} segments.", task.hashCode(), task.getStatus(), task.getChunkSize(), tasks.get(0).getChunkSize(), tasks.size()); queue.addAll(tasks); } else { if (task.getStatus() < 0) { logger.debug("Caught exception calling server with message {}", task.getErrorMessage()); } else { logger.debug("Did not get status {} but received {}", SC_OK, task.getStatus()); } if (task.getStatus() > 0) { throw new RestException("Received response status " + task.getStatus() + " with message: " + task.getErrorMessage()); } else { throw new RestException("Received response status " + task.getStatus() + " with message " + task.getErrorMessage()); } } } } return result; }
From source file:sadl.models.pdrta.PDRTA.java
public void toDOTLang(Appendable ap, double minP, boolean withInput, StateColoring sc) { // Write transitions with high probability final StringBuilder sb = new StringBuilder(); final Queue<PDRTAState> q = new ArrayDeque<>(); final Set<PDRTAState> found = new HashSet<>(); q.add(root);// w ww . ja va 2s . c o m found.add(root); while (!q.isEmpty()) { final PDRTAState s = q.remove(); for (int i = 0; i < input.getAlphSize(); i++) { final Set<Entry<Integer, Interval>> ins = s.getIntervals(i).entrySet(); for (final Entry<Integer, Interval> eIn : ins) { final Interval in = eIn.getValue(); final double p = s.getStat().getTransProb(i, in); final PDRTAState t = in.getTarget(); if (t != null && p >= minP) { if (!found.contains(t)) { q.add(t); found.add(t); } // Write transition sb.append(s.getIndex()); sb.append(" -> "); sb.append(t.getIndex()); sb.append(" [ label = \""); sb.append(getSymbol(i)); sb.append(" ["); sb.append(in.getBegin()); sb.append(", "); sb.append(in.getEnd()); sb.append("] p="); sb.append(p); if (withInput) { sb.append(" n="); sb.append(in.getTails().size()); } sb.append("\" ];\n"); } } } } try { writeStatData(ap, found); // Write automaton in DOT language ap.append("digraph PDRTA {\n"); ap.append("rankdir=LR;\n"); ap.append("node[style = filled, fillcolor = white, shape = circle];\n"); ap.append("\"\"[style = invis, shape = none, margin = 0, width = 0, heigth = 0];\n"); ap.append("\"\" -> 0;\n"); // Write states for (final PDRTAState s : states.valueCollection()) { if (found.contains(s)) { ap.append(Integer.toString(s.getIndex())); ap.append(" [ xlabel = \""); ap.append(Double.toString(s.getStat().getTailEndProb())); ap.append("\""); if (sc != null) { if (sc.isRed(s)) { ap.append(", fillcolor = \"#FFA9A9\""); } else if (sc.isBlue(s)) { ap.append(", fillcolor = \"#A9D1FF\""); } } ap.append(" ];\n"); } } // Add transitions ap.append(sb.toString()); ap.append("}"); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:bme.iclef.weka.featureselection.InfoGain.java
public AttributeInfoGain[] topAttributes(final int n) { Queue<AttributeInfoGain> all = new PriorityQueue<AttributeInfoGain>(m_InfoGains.length, new Comparator<AttributeInfoGain>() { @Override/*from ww w . ja v a 2s . co m*/ public int compare(AttributeInfoGain o1, AttributeInfoGain o2) { return Double.compare(o2.infoGain, o1.infoGain); // descending } }); for (int i = 0; i < m_InfoGains.length; i++) all.add(new AttributeInfoGain(i, m_InfoGains[i])); AttributeInfoGain[] best = new AttributeInfoGain[n]; for (int i = 0; i < best.length; i++) { best[i] = all.remove(); } return best; }
From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java
/** * Ricostruisce la successione della disposizione dei frammenti nei * pannelli.//ww w. j a v a2s. c o m * * @param fragmentMgr Gestore dei frammenti. * @param fragmentQueue Frammenti. * @return Identificatore dell’ultimo elemento inserito * nel back stack. */ private int arrangeFragments(FragmentManager fragmentMgr, Queue<FragmentLayoutController.FragmentEntry> fragmentQueue) { int i; int frameCount, tnId, lastTnId; FragmentLayoutController.FragmentEntry entry; FragmentSupport newFragment, oldFragment; FragmentLayoutController.FragmentEntry[] frames; FragmentTransaction fragmentTn = null; frameCount = 1; frames = new FragmentLayoutController.FragmentEntry[myFrameCount]; Arrays.fill(frames, null); lastTnId = -1; while (!fragmentQueue.isEmpty()) { tnId = -1; entry = fragmentQueue.remove(); try { fragmentTn = fragmentMgr.beginTransaction(); if (frameCount == myFrameCount) { // Tutti i pannelli sono occupati: // Sposto ogni frammento nel pannello precedente per // liberare l'ultimo. for (i = 0; i < frameCount; i++) { if (frames[i] == null) { // Inizialmente il primo pannello risulta vuoto // anche se in realta' e' occupato dal frammento // principale (non di dettaglio). continue; } oldFragment = frames[i].getFragment(); newFragment = (i > 0) ? oldFragment.cloneFragment() : null; fragmentTn.remove(oldFragment.asFragment()); frames[i] = null; if (newFragment != null) { fragmentTn.replace(myFrameIds[i - 1], newFragment.asFragment(), entry.getTag()); frames[i - 1] = new FragmentLayoutController.FragmentEntry(newFragment, entry.getTag()); } } frameCount--; } fragmentTn.add(myFrameIds[frameCount], entry.getFragment().asFragment(), entry.getTag()); frames[frameCount++] = entry; fragmentTn.addToBackStack(null); } finally { if (fragmentTn != null) { tnId = fragmentTn.commit(); fragmentTn = null; } } if (tnId >= 0) { lastTnId = tnId; } } return lastTnId; }