List of usage examples for java.util Queue isEmpty
boolean isEmpty();
From source file:org.protempa.backend.ksb.protege.ProtegeKnowledgeSourceBackend.java
private Collection<String> collectPropDescendantsInt(boolean inDataSourceOnly, boolean narrower, String[] propIds) throws KnowledgeSourceReadException { assert propIds != null : "propIds cannot be null"; Slot inverseIsASlot = this.cm.getSlot("inverseIsA"); Slot abstractedFromSlot = this.cm.getSlot("abstractedFrom"); Slot inDataSourceSlot = this.cm.getSlot("inDataSource"); Set<String> result = new HashSet<>(); Queue<Instance> queue = new LinkedList<>(); for (String propId : propIds) { Instance instance = this.cm.getInstance(propId); if (instance == null) { throw new KnowledgeSourceReadException("unknown proposition id " + propId); } else {//from ww w .j a v a 2s . c om queue.add(instance); } } while (!queue.isEmpty()) { Instance instance = queue.poll(); if (inDataSourceOnly) { Boolean inDataSource = (Boolean) this.cm.getOwnSlotValue(instance, inDataSourceSlot); if (inDataSource != null && inDataSource.booleanValue()) { result.add(instance.getName()); } } else { result.add(instance.getName()); } Collection<?> inverseIsAs = this.cm.getOwnSlotValues(instance, inverseIsASlot); for (Object obj : inverseIsAs) { queue.add((Instance) obj); } Collection<?> abstractedFroms = narrower ? this.cm.getOwnSlotValues(instance, abstractedFromSlot) : Collections.emptyList(); for (Object obj : abstractedFroms) { queue.add((Instance) obj); } } return result; }
From source file:it.geosolutions.geobatch.unredd.script.ingestion.IngestionAction.java
/** * Main loop on input files./*from ww w . ja va 2 s.c om*/ * Single file processing is called on execute(File inputZipFile) */ public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException { final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>(); LOGGER.warn("Ingestion flow running"); while (!events.isEmpty()) { final FileSystemEvent ev = events.remove(); try { if (ev != null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Processing incoming event: " + ev.getSource()); } File inputZipFile = ev.getSource(); // this is the input zip file File out = execute(inputZipFile); ret.add(new FileSystemEvent(out, FileSystemEventType.FILE_ADDED)); } else { LOGGER.error("NULL event: skipping..."); continue; } } catch (ActionException ex) { // ActionEx have already been processed LOGGER.error(ex.getMessage(), ex); throw ex; } catch (Exception ex) { final String message = "GeostoreAction.execute(): Unable to produce the output: " + ex.getLocalizedMessage(); LOGGER.error(message, ex); throw new ActionException(this, message); } } return ret; }
From source file:org.rhq.core.plugin.testutil.AbstractAgentPluginTest.java
/** * Test that loads a resource configuration and then immediately updates the resource * with the exact same loaded settings./*from w w w . j a v a 2 s .c o m*/ * * Notes: * 1) load/update is not executed on the root resource provided. * 2) if a resource is ignored then all of subresource of that resources are ignored * * @param rootResource root resource * @param ignoredResources resources to be ignored * @return number of errors * @throws InterruptedException * @throws PluginContainerException */ protected int loadUpdateConfigChildResources(Resource rootResource, List<String> ignoredResources) throws InterruptedException, PluginContainerException { ignoredResources = (ignoredResources == null) ? new ArrayList<String>() : ignoredResources; ConfigurationManager configManager = this.pluginContainer.getConfigurationManager(); Thread.sleep(10 * 1000L); Queue<Resource> unparsedResources = new LinkedList<Resource>(); addCommitedChildrenToCollection(unparsedResources, rootResource, ignoredResources); int errorCount = 0; while (!unparsedResources.isEmpty()) { Resource resourceUnderTest = unparsedResources.poll(); addCommitedChildrenToCollection(unparsedResources, resourceUnderTest, ignoredResources); if (resourceUnderTest.getResourceType().getResourceConfigurationDefinition() != null) { Configuration configUnderTest = configManager.loadResourceConfiguration(resourceUnderTest.getId()); ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(1, configUnderTest, resourceUnderTest.getId()); ConfigurationUpdateResponse updateResponse = configManager .executeUpdateResourceConfigurationImmediately(updateRequest); if (updateResponse == null) { errorCount++; log.error("------------------------------"); log.error(resourceUnderTest); log.error("Update Response is NULL!!!!"); log.error("------------------------------\n"); } if (updateResponse.getErrorMessage() != null) { errorCount++; log.error("------------------------------"); log.error(resourceUnderTest); log.error(updateResponse.getErrorMessage()); log.error("------------------------------\n"); } } } return errorCount; }
From source file:org.grouplens.grapht.solver.DependencySolver.java
/** * Update the dependency graph to include the given desire. An edge from the * root node to the desire's resolved satisfaction will exist after this is * finished./*w w w . ja v a 2 s . c o m*/ * * @param desire The desire to include in the graph */ public synchronized void resolve(Desire desire) throws ResolutionException { logger.info("Resolving desire: {}", desire); Queue<Deferral> deferralQueue = new ArrayDeque<Deferral>(); // before any deferred nodes are processed, we use a synthetic root // and null original desire since nothing produced this root deferralQueue.add(new Deferral(rootNode(), initialContext())); while (!deferralQueue.isEmpty()) { Deferral current = deferralQueue.poll(); DAGNode<Component, Dependency> parent = current.node; // deferred nodes are either root - depless - or having deferred dependencies assert parent.getOutgoingEdges().isEmpty(); if (current.node.getLabel().equals(ROOT_SATISFACTION)) { Pair<DAGNode<Component, Dependency>, Dependency> rootNode = resolveFully(desire, current.context, deferralQueue); // add this to the global graph graph = DAGNode.copyBuilder(graph).addEdge(mergePool.merge(rootNode.getLeft()), rootNode.getRight()) .build(); } else if (graph.getReachableNodes().contains(parent)) { // the node needs to be re-scanned. This means that it was not consolidated by // a previous merge operation. This branch only arises with provider injection. Satisfaction sat = parent.getLabel().getSatisfaction(); for (Desire d : sat.getDependencies()) { logger.debug("Attempting to resolve deferred dependency {} of {}", d, sat); // resolve the dependency Pair<DAGNode<Component, Dependency>, Dependency> result = resolveFully(d, current.context, deferralQueue); // merge it in DAGNode<Component, Dependency> merged = mergePool.merge(result.getLeft()); // now see if there's a real cycle if (merged.getReachableNodes().contains(parent)) { // parent node is referenced from merged, we have a circle! // that means we need a back edge backEdges.put(parent, DAGEdge.create(parent, merged, result.getRight())); } else { // an edge from parent to merged does not add a cycle // we have to update graph right away so it's available to merge the next // dependency DAGNode<Component, Dependency> newP = DAGNode.copyBuilder(parent) .addEdge(merged, result.getRight()).build(); replaceNode(parent, newP); parent = newP; } } } else { // node unreachable - it's a leftover or unneeded deferral logger.debug("node {} not in graph, ignoring", parent); } } }
From source file:sadl.models.pdrta.PDRTA.java
public void checkConsistency() { // Checking that a path for each sequence exists for (int i = 0; i < input.getAlphSize(); i++) { final Set<Entry<Integer, Interval>> ins = root.getIntervals(i).entrySet(); for (final Entry<Integer, Interval> eIn : ins) { final Set<Entry<Integer, TimedTail>> tails = eIn.getValue().getTails().entries(); for (final Entry<Integer, TimedTail> eTail : tails) { TimedTail t = eTail.getValue(); PDRTAState source = root, target; while (t != null) { assert (source.getInterval(t.getSymbolAlphIndex(), t.getTimeDelay()).getTails() .containsValue(t)); target = source.getTarget(t); if (target == null) { throw new IllegalStateException( "The tail (" + input.getSymbol(t.getSymbolAlphIndex()) + "," + t.getTimeDelay() + ") has no transition from state ((" + source.getIndex() + "))!"); }/*from ww w.java2 s . co m*/ source = target; t = t.getNextTail(); } } } } // Checking that number of states in structure is equal to number of states in map int counter = 0; final Set<PDRTAState> seen = new HashSet<>(); seen.add(root); final Queue<PDRTAState> q = new LinkedList<>(); q.add(root); while (!q.isEmpty()) { final PDRTAState s = q.poll(); PDRTAState s2 = states.get(s.getIndex()); if (s != s2) { throw new IllegalStateException("State (" + s.getIndex() + ") is not in map!"); } counter++; 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) { s2 = eIn.getValue().getTarget(); if (s2 != null && !seen.contains(s2)) { seen.add(s2); q.add(s2); } } } } if (counter != states.size()) { throw new IllegalStateException( "Found " + counter + " sates in structure but " + states.size() + " states are in map!"); } }
From source file:candr.yoclip.Parser.java
/** * Creates a collection of parsed option parameters from the queue of parameters passed in. The parameters queue is modified as parameters are * parsed, removing option parameters from the queue as they are parsed. * * @param parameters The command parameters that will be parsed. * @return a collection of parsed option parameters or {@code null} if the parameters queue is empty. *//* w w w .j a va2 s.c o m*/ protected List<ParsedOption<T>> getParsedParameters(final String[] parameters) { final LinkedList<ParsedOption<T>> parsedOptionParameters = new LinkedList<ParsedOption<T>>(); final Queue<String> parametersQueue = new LinkedList<String>(Arrays.asList(parameters)); while (!parametersQueue.isEmpty()) { ParsedOption<T> parsedOptionParameter; if (!isOption(parametersQueue.peek())) { parsedOptionParameter = getParsedArgument(parametersQueue); } else { // check for an option property match first parsedOptionParameter = getParsedOptionProperty(parametersQueue); // an option next if (null == parsedOptionParameter) { parsedOptionParameter = getParsedOption(parametersQueue); } } // not an option if (null == parsedOptionParameter) { final String parameter = parametersQueue.remove(); parsedOptionParameter = new ParsedOption<T>("'" + parameter + "': Unsupported option."); } parsedOptionParameters.add(parsedOptionParameter); } return parsedOptionParameters; }
From source file:org.apache.hama.bsp.ResourceManager.java
private void useOffer(SchedulerDriver schedulerDriver, Offer offer) { log.debug("Received offer From: " + offer.getHostname()); String host = offer.getHostname(); ResourceOffer ro = new ResourceOffer(offer); int maxSlots = ro.getMaxSlots(); if (maxSlots == 0) { schedulerDriver.declineOffer(offer.getId()); return;/* ww w. j a v a2s. co m*/ } java.util.Queue<TaskInProgress> tasks = new LinkedList<TaskInProgress>(); while (tasks.size() < maxSlots) { TaskInProgress tip = null; if (tasksToRunByGroom.get(host) != null) { tip = tasksToRunByGroom.get(host).poll(); } if (tip == null) { tip = tasksToRunByGroom.get(anyGroomServer).poll(); if (tip == null) { if (tasks.isEmpty()) { schedulerDriver.declineOffer(offer.getId()); } break; } } if (executingTasks.contains(tip)) { continue; } executingTasks.add(tip); tasksToRun.remove(tip); tasks.add(tip); log.debug("Found offer for: " + tip.getTaskId()); } if (!tasks.isEmpty()) { launchTasks(schedulerDriver, tasks, ro); } }
From source file:net.sf.nmedit.jpatch.impl.PBasicConnectionManager.java
public Collection<PConnector> graph(PConnector c) { Node n = nodemap.get(c);/* w ww . j ava 2s. c o m*/ if (n == null) return Collections.<PConnector>emptyList(); Queue<Node> queue = new LinkedList<Node>(); Collection<PConnector> g = new LinkedList<PConnector>(); queue.offer(n.root()); while (!queue.isEmpty()) { n = queue.remove(); g.add(n.c); n.addChildNodes(queue); } return Collections.<PConnector>unmodifiableCollection(g); }
From source file:net.sf.nmedit.jpatch.impl.PBasicConnectionManager.java
public Collection<PConnection> graphConnections(PConnector c) { Node n = nodemap.get(c);/*from w w w. j a v a 2 s.co m*/ if (n == null) return Collections.<PConnection>emptyList(); Queue<Node> queue = new LinkedList<Node>(); Collection<PConnection> g = new LinkedList<PConnection>(); n.addChildNodes(queue); while (!queue.isEmpty()) { n = queue.remove(); g.add(new PConnection(n.c, n.parent())); n.addChildNodes(queue); } return Collections.<PConnection>unmodifiableCollection(g); }
From source file:Graph.java
public void bfs(Queue<Node> q) { clearState();// www . j ava 2s. c o m for (Node n : nodes) { n.setState(q.contains(n) ? GRAY : WHITE); } for (Edge e : edges) { e.setMode(UNKNOWN); } for (Node n : q) { n.setDistance(0); n.setPredecessor(null); } while (!q.isEmpty()) { Node n = q.remove(); List<Node> out = findNextNodes(n); for (Node m : out) { Edge e = findEdge(n, m); if (e != null) { if (m.getState() == WHITE) { e.setMode(TREE); } else if (m.getState() == GRAY) { e.setMode(BACK); } } if (!m.isVisited()) { m.setDistance(n.getDistance() + 1); m.setPredecessor(n); m.setState(GRAY); q.offer(m); } } n.setState(BLACK); } searchState = STATE_BFS; }