List of usage examples for java.util Queue isEmpty
boolean isEmpty();
From source file:org.protempa.backend.ksb.SimpleKnowledgeSourceBackend.java
private Collection<PropositionDefinition> collectSubtreePropositionDefinitionsInt(String[] propIds, boolean narrower, boolean inDataSource) { ProtempaUtil.checkArray(propIds, "propDefs"); Set<PropositionDefinition> propResult = new HashSet<>(); Queue<String> queue = new LinkedList<>(); for (String pd : propIds) { queue.add(pd);/*from w w w. jav a 2 s.c om*/ } while (!queue.isEmpty()) { String propId = queue.poll(); PropositionDefinition pd = this.propDefsMap.get(propId); if (!inDataSource || pd.getInDataSource()) { propResult.add(pd); } if (narrower) { Arrays.addAll(queue, pd.getChildren()); } else { Arrays.addAll(queue, pd.getInverseIsA()); } } return propResult; }
From source file:com.google.cloud.solutions.griddler.android.ui.game.BoardView.java
private void updateLetterUI() { Queue<LetterRenderModel> selectedLetterQueue = gameManager.getBoardRenderModel().getGridLayout() .getSelectedLetterQueue();/*from w w w .ja va2 s.co m*/ if (!selectedLetterQueue.isEmpty()) { for (LetterRenderModel letterQueue : selectedLetterQueue) { Location loc = gameManager.getBoardRenderModel().getGridLayout().getBoard().get(letterQueue); if (loc != null) { if (!letterViewsHash.containsKey(loc)) { addToView(loc); } } } } else { answerLetterLayout.removeAllViews(); letterViewsHash.clear(); } }
From source file:it.geosolutions.geobatch.destination.action.DestinationBaseAction.java
public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.setTask("Check config"); checkInit();//from w ww.j a v a2 s. c o m final LinkedList<EventObject> ret = new LinkedList<EventObject>(); try { listenerForwarder.started(); while (!events.isEmpty()) { EventObject event = events.poll(); File file = null; if (event instanceof FileSystemEvent) { FileSystemEvent fse = (FileSystemEvent) event; file = fse.getSource(); } FeatureConfiguration featureConfiguration = unwrapFeatureConfig(event); DataStore ds = FeatureConfigurationUtil.createDataStore(featureConfiguration); if (ds == null) { throw new ActionException(this, "Can't find datastore "); } try { if (!(ds instanceof JDBCDataStore)) { throw new ActionException(this, "Bad Datastore type " + ds.getClass().getName()); } JDBCDataStore dataStore = (JDBCDataStore) ds; dataStore.setExposePrimaryKeyColumns(true); MetadataIngestionHandler metadataHandler = new MetadataIngestionHandler(dataStore); doProcess((T) getConfiguration(), featureConfiguration, dataStore, metadataHandler, file); // pass the feature config to the next action ret.add(createOutputEvent(event)); } finally { ds.dispose(); } } listenerForwarder.completed(); return ret; } catch (Exception t) { listenerForwarder.failed(t); throw new ActionException(this, t.getMessage(), t); } }
From source file:org.polymap.model2.engine.EntityRepositoryImpl.java
public EntityRepositoryImpl(final Configuration config) { this.config = config; // init store getStore().init(new StoreRuntimeContextImpl()); // init infos log.debug("Initialializing Composite types:"); Queue<Class<? extends Composite>> queue = new LinkedList(); queue.addAll(Arrays.asList(config.entities.get())); while (!queue.isEmpty()) { Class<? extends Composite> type = queue.poll(); if (!infos.containsKey(type)) { log.debug(" Composite type: " + type); CompositeInfoImpl info = new CompositeInfoImpl(type); infos.put(type, info);/*from w w w . j a v a2 s . c om*/ // init static TYPE variable try { Field field = type.getDeclaredField("TYPE"); field.setAccessible(true); field.set(null, Expressions.template(type, this)); } catch (NoSuchFieldException e) { } catch (SecurityException | IllegalAccessException e) { throw new ModelRuntimeException(e); } // mixins queue.addAll(info.getMixins()); // Composite properties for (PropertyInfo propInfo : info.getProperties()) { if (Composite.class.isAssignableFrom(propInfo.getType())) { queue.offer(propInfo.getType()); } } } } }
From source file:com.tasktop.c2c.server.internal.tasks.domain.conversion.TaskConverter.java
@SuppressWarnings("unchecked") @Override/* w w w . j a v a 2s .c om*/ public void copy(Task target, Object internalObject, DomainConverter converter, DomainConversionContext context) { com.tasktop.c2c.server.internal.tasks.domain.Task source = (com.tasktop.c2c.server.internal.tasks.domain.Task) internalObject; DomainConversionContext subcontext = context.subcontext(); target.setId(source.getId()); target.setFoundInRelease( source.getVersion() == null ? null : source.getVersion().isEmpty() ? null : source.getVersion()); target.setCreationDate(source.getCreationTs()); target.setModificationDate(source.getDeltaTs()); target.setVersion(source.getDeltaTs() == null ? null : Long.toString(source.getDeltaTs().getTime())); target.setShortDescription(source.getShortDesc()); target.setEstimatedTime(source.getEstimatedTime()); target.setRemainingTime(source.getRemainingTime()); target.setDeadline(source.getDeadline()); target.setUrl(configuration.getWebUrlForTask(target.getId())); // Mandatory custom fields target.setTaskType(source.getTaskType()); List<ExternalTaskRelation> externalTaskRelations = new ArrayList<ExternalTaskRelation>(); if (source.getExternalTaskRelations() != null) { String[] strings = StringUtils.split(source.getExternalTaskRelations(), "\n"); Pattern p = Pattern.compile("(.*)\\.(.*): (.*)"); for (String string : strings) { Matcher matcher = p.matcher(string); if (matcher.matches()) { String type = matcher.group(1); String kind = matcher.group(2); String uri = matcher.group(3); externalTaskRelations.add(new ExternalTaskRelation(type, kind, uri)); } } } target.setExternalTaskRelations(externalTaskRelations); List<String> commits = new ArrayList<String>(); if (source.getCommits() != null) { for (String commit : StringUtils.split(source.getCommits(), ",")) { commits.add(commit); } } target.setCommits(commits); // These must be set from query join results target.setSeverity(context.getTaskSeverity(source.getSeverity())); target.setStatus(context.getTaskStatus(source.getStatus())); target.setResolution(context.getTaskResolution(source.getResolution())); target.setPriority(context.getPriority(source.getPriority())); target.setMilestone(context.getMilestone(source.getProduct(), source.getTargetMilestone())); target.setProduct((Product) converter.convert(source.getProduct(), subcontext)); target.setComponent((Component) converter.convert(source.getComponent(), subcontext)); target.setReporter((TaskUserProfile) converter.convert(source.getReporter(), subcontext)); target.setAssignee((TaskUserProfile) converter.convert(source.getAssignee(), subcontext)); target.setWatchers((List<TaskUserProfile>) converter.convert(source.getCcs(), subcontext)); List<Keyworddef> keyworddefs = new ArrayList<Keyworddef>(); for (com.tasktop.c2c.server.internal.tasks.domain.Keyword keyword : source.getKeywordses()) { keyworddefs.add(keyword.getKeyworddefs()); } target.setKeywords((List<Keyword>) converter.convert(keyworddefs, subcontext)); // Description (first comment), Comments, and Worklog items (comment with workTime) copyCommentsAndWorkLogs(target, source.getComments(), converter, context); BigDecimal sumOfSubtasksEstimate = BigDecimal.ZERO; BigDecimal sumOfSubtasksTimeSpent = BigDecimal.ZERO; Queue<Dependency> subTaskQueue = new LinkedList<Dependency>(source.getDependenciesesForBlocked()); while (!subTaskQueue.isEmpty()) { com.tasktop.c2c.server.internal.tasks.domain.Task subTask = subTaskQueue.poll().getBugsByDependson(); subTaskQueue.addAll(subTask.getDependenciesesForBlocked()); if (subTask.getEstimatedTime() != null) { sumOfSubtasksEstimate = sumOfSubtasksEstimate.add(subTask.getEstimatedTime()); } for (com.tasktop.c2c.server.internal.tasks.domain.Comment c : subTask.getComments()) { if (c.getWorkTime() != null && c.getWorkTime().signum() > 0) { sumOfSubtasksTimeSpent = sumOfSubtasksTimeSpent.add(c.getWorkTime()); } } } target.setSumOfSubtasksEstimatedTime(sumOfSubtasksEstimate); target.setSumOfSubtasksTimeSpent(sumOfSubtasksTimeSpent); if (!context.isThin()) { target.setBlocksTasks(new ArrayList<Task>(source.getDependenciesesForDependson().size())); for (Dependency dep : source.getDependenciesesForDependson()) { target.getBlocksTasks().add(shallowCopyAssociate(dep.getBugsByBlocked(), subcontext)); } target.setSubTasks(new ArrayList<Task>(source.getDependenciesesForBlocked().size())); for (Dependency dep : source.getDependenciesesForBlocked()) { target.getSubTasks().add(shallowCopyAssociate(dep.getBugsByDependson(), subcontext)); } if (source.getDuplicatesByBugId() != null) { target.setDuplicateOf( shallowCopyAssociate(source.getDuplicatesByBugId().getBugsByDupeOf(), subcontext)); } target.setDuplicates(new ArrayList<Task>()); for (Duplicate duplicate : source.getDuplicatesesForDupeOf()) { target.getDuplicates().add(shallowCopyAssociate(duplicate.getBugsByBugId(), subcontext)); } if (source.getStatusWhiteboard() != null && !source.getStatusWhiteboard().isEmpty()) { // A non-empty statusWhiteboard means we store description there for backward compatibility. (See // discussion in Task 422) target.setDescription(source.getStatusWhiteboard()); // REVIEW do we really need this for subtasks? target.setWikiRenderedDescription( renderer.render(source.getStatusWhiteboard(), context.getWikiMarkup())); } target.setAttachments((List<Attachment>) converter.convert(source.getAttachments(), subcontext)); } else { // THIN tasks still get their parent populated if (!source.getDependenciesesForDependson().isEmpty()) { target.setParentTask(shallowCopyAssociate( source.getDependenciesesForDependson().get(0).getBugsByBlocked(), subcontext)); } } }
From source file:com.facebook.config.AbstractExpandedConfJSONProvider.java
private JSONObject getExpandedJSONConfig() throws JSONException { Set<String> traversedFiles = new HashSet<>(); Queue<String> toTraverse = new LinkedList<>(); // Seed the graph traversal with the root node traversedFiles.add(root);/* w ww . ja v a 2 s.com*/ toTraverse.add(root); // Policy: parent configs will override children (included) configs JSONObject expanded = new JSONObject(); while (!toTraverse.isEmpty()) { String current = toTraverse.remove(); JSONObject json = load(current); JSONObject conf = json.getJSONObject(CONF_KEY); Iterator<String> iter = conf.keys(); while (iter.hasNext()) { String key = iter.next(); // Current config will get to insert keys before its include files if (!expanded.has(key)) { expanded.put(key, conf.get(key)); } } // Check if the file itself has any included files if (json.has(INCLUDES_KEY)) { JSONArray includes = json.getJSONArray(INCLUDES_KEY); for (int idx = 0; idx < includes.length(); idx++) { String include = resolve(current, includes.getString(idx)); if (traversedFiles.contains(include)) { LOG.warn("Config file was included twice: " + include); } else { toTraverse.add(include); traversedFiles.add(include); } } } } return expanded; }
From source file:objects.PatternEntry.java
public PatternEntry[] segment(Ruleset rule) { if (cells.getW() == 0 || cells.getH() == 0) { PatternEntry[] returnArray = {}; return returnArray; }/*from w w w .ja va 2 s .c o m*/ int startX = 0; int startY = 0; for (int x = 0; x < cells.getW(); x++) for (int y = 0; y < cells.getH(); y++) if (cells.pattern[x][y] != 0) { startX = x; startY = y; break; } boolean[][] isPart = new boolean[cells.getW()][cells.getH()]; Queue<int[]> knownPoints = new LinkedList<int[]>(); int[] starterPoint = { startX, startY }; knownPoints.add(starterPoint); isPart[startX][startY] = true; while (!knownPoints.isEmpty()) { int[] pt = knownPoints.poll(); for (int[] dP : rule.getNeighborField()) { int[] thispt = { pt[0] + dP[0], pt[1] + dP[1] }; if (Engine.getByte(cells.pattern, thispt[0], thispt[1]) != 0 && !Engine.isActive(isPart, thispt[0], thispt[1])) { knownPoints.add(thispt); isPart[thispt[0]][thispt[1]] = true; } } } boolean canSplit = false; for (int x = 0; x < cells.getW(); x++) for (int y = 0; y < cells.getH(); y++) if (cells.pattern[x][y] != 0 && !isPart[x][y]) canSplit = true; if (canSplit) { byte[][] cellsOne = new byte[cells.getW()][cells.getH()]; byte[][] cellsTwo = new byte[cells.getW()][cells.getH()]; for (int x = 0; x < cells.getW(); x++) for (int y = 0; y < cells.getH(); y++) { if (isPart[x][y]) cellsOne[x][y] = cells.pattern[x][y]; else cellsTwo[x][y] = cells.pattern[x][y]; } PatternEntry componentPatternOne = new PatternEntry(cellsOne); PatternEntry[] getOtherParts = new PatternEntry(cellsTwo).segment(rule); return ArrayUtils.addAll(getOtherParts, componentPatternOne); } PatternEntry[] returnArray = { this }; return returnArray; }
From source file:playground.johannes.socialnets.NetworkGenerator2.java
private TObjectIntHashMap<Ego> initDegreeDistribution(Collection<? extends Ego> egos) { TObjectIntHashMap<Ego> stubsMap = new TObjectIntHashMap<Ego>(); /*/*from w w w . j a va2 s.c o m*/ * For now, uniform degree distribution */ Queue<Ego> egos2 = new LinkedList<Ego>(egos); while (!egos2.isEmpty()) { Ego e1 = egos2.poll(); for (Ego e2 : egos) { if (random.nextDouble() <= 1 / alpha * getDyadProba(e1, e2, scale)) { stubsMap.adjustOrPutValue(e1, 1, 1); stubsMap.adjustOrPutValue(e2, 1, 1); } } } return stubsMap; }
From source file:org.rhq.core.pc.configuration.ConfigurationManager.java
private void mergedStructuredIntoRaws(Configuration configuration, ResourceConfigurationFacet facet) { Set<RawConfiguration> rawConfigs = facet.loadRawConfigurations(); if (rawConfigs == null) { return;// ww w. j a v a2s . c o m } prepareConfigForMergeIntoRaws(configuration, rawConfigs); Queue<RawConfiguration> queue = new LinkedList<RawConfiguration>(rawConfigs); while (!queue.isEmpty()) { RawConfiguration originalRaw = queue.poll(); RawConfiguration mergedRaw = facet.mergeRawConfiguration(configuration, originalRaw); if (mergedRaw != null) { //TODO bypass validation of structured config for template values String contents = mergedRaw.getContents(); String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256) .calcDigestString(contents); mergedRaw.setContents(contents, sha256); updateRawConfig(configuration, originalRaw, mergedRaw); } } }