List of usage examples for com.google.common.collect Multiset entrySet
Set<Entry<E>> entrySet();
From source file:com.synflow.cx.internal.validation.ExpressionValidator.java
@Check(NORMAL) public void checkMultipleReads(final CxExpression expr) { // Checks that there are at most one read per port in the expression. Otherwise indicate an // error./*from w w w . ja va 2 s . com*/ Task task = EcoreUtil2.getContainerOfType(expr, Task.class); if (task == null) { return; } instantiator.forEachMapping(task, new Executable<Entity>() { @Override public void exec(Entity entity) { Multiset<Port> portsRead = LinkedHashMultiset.create(); Multiset<Port> portsAvailable = LinkedHashMultiset.create(); computePortSets(entity, portsAvailable, portsRead, expr); boolean hasMultipleReads = false; for (Entry<Port> entry : portsRead.entrySet()) { hasMultipleReads |= entry.getCount() > 1; } if (hasMultipleReads) { error("Port error: cannot have more than one read per port in expression", expr, null, ERR_MULTIPLE_READS); } } }); }
From source file:org.immutables.value.processor.meta.ValueTypeComposer.java
private void checkAttributeNamesForDuplicates(ValueType type, Protoclass protoclass) { if (!type.attributes.isEmpty()) { Multiset<String> attributeNames = HashMultiset.create(type.attributes.size()); for (ValueAttribute attribute : type.attributes) { attributeNames.add(attribute.name()); }/*w ww .ja va 2 s . com*/ List<String> duplicates = Lists.newArrayList(); for (Multiset.Entry<String> entry : attributeNames.entrySet()) { if (entry.getCount() > 1) { duplicates.add(entry.getElement()); } } if (!duplicates.isEmpty()) { protoclass.report().error( "Duplicate attribute names %s. You should check if correct @Value.Style applied", duplicates); } } }
From source file:org.sonar.plugins.core.issue.IssueCountersDecorator.java
private void saveIssuesPerRules(DecoratorContext context, RulePriority severity, Map<RulePriority, Multiset<Rule>> rulesPerSeverity) { Metric metric = SeverityUtils.severityToIssueMetric(severity); Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(metric)); for (Measure child : children) { RuleMeasure childRuleMeasure = (RuleMeasure) child; Rule rule = childRuleMeasure.getRule(); if (rule != null && MeasureUtils.hasValue(childRuleMeasure)) { Multiset<Rule> rulesBag = initRules(rulesPerSeverity, severity); rulesBag.add(rule, childRuleMeasure.getIntValue()); }//from ww w.ja va 2 s. co m } Multiset<Rule> rulesBag = rulesPerSeverity.get(severity); if (rulesBag != null) { for (Multiset.Entry<Rule> entry : rulesBag.entrySet()) { RuleMeasure measure = RuleMeasure.createForRule(metric, entry.getElement(), (double) entry.getCount()); measure.setSeverity(severity); context.saveMeasure(measure); } } }
From source file:com.github.fhirschmann.clozegen.lib.generators.CollocationGapGenerator.java
@Override public Optional<Gap> generate(final int count) { checkNotNull(model);/* w ww .jav a 2 s . co m*/ Gap gap = new Gap(); gap.addValidAnswers(triplet.getValue1()); // Collect a list of possible candidates for this gap final Multiset<String> candidates = ConcurrentHashMultiset.create(MultisetUtils.mergeMultiSets( model.getTails().get(triplet.getValue2()), model.getHeads().get(triplet.getValue0()))); // Remove the correct answer from the candidate set candidates.remove(triplet.getValue1(), candidates.count(triplet.getValue1())); // Remove candidates p* which appear in the context (A, p*, B) for (Entry<String> entry : candidates.entrySet()) { if (model.getMultiset().contains( MiscUtils.WS_JOINER.join(triplet.getValue0(), entry.getElement(), triplet.getValue2()))) { candidates.remove(entry.getElement(), entry.getCount()); } } if (candidates.elementSet().size() > count - 2) { final Set<String> invalidAnswers = Sets .newHashSet(MultisetUtils.sortedElementList(candidates, count - 1)); gap.addInvalidAnswers(invalidAnswers); return Optional.of(gap); } else { return Optional.absent(); } }
From source file:com.google.devtools.build.lib.rules.objc.ResourceSupport.java
/** * Validates resource attributes on this rule. * * @return this resource support/*from ww w. ja va 2 s. co m*/ */ ResourceSupport validateAttributes() { Iterable<String> assetCatalogErrors = ObjcCommon.notInContainerErrors(attributes.assetCatalogs(), ObjcCommon.ASSET_CATALOG_CONTAINER_TYPE); for (String error : assetCatalogErrors) { ruleContext.attributeError("asset_catalogs", error); } Iterable<String> dataModelErrors = ObjcCommon.notInContainerErrors(attributes.datamodels(), Xcdatamodels.CONTAINER_TYPES); for (String error : dataModelErrors) { ruleContext.attributeError("datamodels", error); } Multiset<Artifact> resources = HashMultiset.create(); resources.addAll(attributes.resources()); resources.addAll(attributes.structuredResources()); resources.addAll(attributes.strings()); resources.addAll(attributes.assetCatalogs()); resources.addAll(attributes.datamodels()); resources.addAll(attributes.xibs()); resources.addAll(attributes.storyboards()); for (Multiset.Entry<Artifact> entry : resources.entrySet()) { if (entry.getCount() > 1) { ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString()); } } return this; }
From source file:org.zenoss.app.consumer.metric.impl.MetricsQueue.java
@Override public void reAddAll(Collection<Metric> metrics) { Multiset<String> counts = clientCounts(metrics); queue.addAll(metrics);/* w w w .j av a 2 s . c o m*/ for (Multiset.Entry<String> e : counts.entrySet()) { perClientBacklog.addAndGet(e.getElement(), e.getCount()); } }
From source file:com.koloboke.compile.KolobokeMapBackedMultiset.java
@Override public boolean addAll(Collection<? extends E> c) { if (c.isEmpty()) { return false; }/*w w w. jav a 2 s . com*/ if (c instanceof Multiset) { Multiset<? extends E> that = cast(c); for (Entry<? extends E> entry : that.entrySet()) { this.add(entry.getElement(), entry.getCount()); } } else { Iterators.addAll(this, c.iterator()); } return true; }
From source file:io.janusproject.util.MultisetView.java
@Override public boolean addAll(Collection<? extends K> c) { if (c.isEmpty()) { return false; }// ww w . ja v a 2 s . co m if (c instanceof Multiset) { Multiset<? extends K> that = (Multiset<? extends K>) c; for (Entry<? extends K> entry : that.entrySet()) { add(entry.getElement(), entry.getCount()); } } else { Iterators.addAll(this, c.iterator()); } return true; }
From source file:se.gothiaforum.controller.tagcloud.TagCloudController.java
/** * Renders the view for the tag cloud./*from w ww. ja va 2 s . c o m*/ * * @param request * the request * @param model * the model * @return a view */ @RenderMapping public String renderView(RenderRequest request, Model model) { try { List<JournalArticle> articles = JournalArticleLocalServiceUtil.getJournalArticles(0, JournalArticleLocalServiceUtil.getJournalArticlesCount()); Set<AssetEntry> entrys = new HashSet<AssetEntry>(); for (JournalArticle ja : articles) { if (ja.getType().equals(ActorsConstants.TYPE_ACTOR)) { entrys.add(AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), ja.getResourcePrimKey())); } } Multiset<AssetTag> tagMultiSet = HashMultiset.create(); for (AssetEntry entry : entrys) { List<AssetTag> tags = AssetTagLocalServiceUtil.getEntryTags(entry.getEntryId()); for (AssetTag tag : tags) { tagMultiSet.add(tag); } } List<TagVO> tagVOList = new ArrayList<TagVO>(); for (Entry<AssetTag> entry : tagMultiSet.entrySet()) { String cssClass; final int number8 = 8; final int number7 = 7; final int number6 = 6; final int number5 = 5; final int number4 = 4; final int number3 = 3; final int number2 = 2; if (entry.getCount() > number8) { cssClass = "tag-weight-10"; } else if (entry.getCount() > number7) { cssClass = "tag-weight-9"; } else if (entry.getCount() > number6) { cssClass = "tag-weight-8"; } else if (entry.getCount() > number5) { cssClass = "tag-weight-7"; } else if (entry.getCount() > number4) { cssClass = "tag-weight-6"; } else if (entry.getCount() > number3) { cssClass = "tag-weight-5"; } else if (entry.getCount() > number2) { cssClass = "tag-weight-4"; } else { cssClass = "tag-weight-2"; } TagVO tagVO = new TagVO(cssClass, entry.getElement().getName(), ActorsConstants.SEARCH_REDIRECT_URL + entry.getElement().getName(), entry.getElement().getTagId()); tagVO.setCount(entry.getCount()); tagVOList.add(tagVO); } final int size = 20; if (tagVOList.size() > size) { for (int i = 1; tagVOList.size() > size; i++) { List<TagVO> removeList = new ArrayList<TagVO>(); for (TagVO tagVO : tagVOList) { if (tagVO.getCount() == i) { removeList.add(tagVO); } } tagVOList.removeAll(removeList); } } Collections.shuffle(tagVOList); model.addAttribute("tagVOList", tagVOList); } catch (SystemException e) { e.printStackTrace(); } catch (PortalException e) { e.printStackTrace(); } return "tagCloudView"; }
From source file:org.onebusaway.nyc.vehicle_tracking.impl.particlefilter.ParticleFilter.java
/** * This runs a single time-step of the particle filter, given a single * timestep's worth of sensor readings./* ww w .j a v a 2 s. c o m*/ * * @param timestamp * @param obs * @param moveParticles * @throws ParticleFilterException */ private void runSingleTimeStep(double timestamp, OBS obs, boolean moveParticles) throws ParticleFilterException { Multiset<Particle> particles = _particles; /* * perform movement and weighing separately */ if (moveParticles) { final double elapsed = timestamp - _timeOfLastUpdate; particles = _motionModel.move(_particles, timestamp, elapsed, obs, _previouslyResampled); } /** * 3. track the weighted particles (before resampling and normalization) */ _weightedParticles = particles; /** * 4. store the most likely particle's information */ computeBestState(particles); if (getEffectiveSampleSize(particles) / ParticleFactoryImpl.getInitialNumberOfParticles() < _resampleThreshold) { /** * 5. resample */ final Multiset<Particle> resampled = lowVarianceSampler(particles, particles.size()); final Multiset<Particle> reweighted = HashMultiset.create(resampled.size()); for (final Entry<Particle> pEntry : resampled.entrySet()) { final Particle p = pEntry.getElement().cloneParticle(); p.setWeight(((double) pEntry.getCount()) / resampled.size()); reweighted.add(p, pEntry.getCount()); } _particles = reweighted; _previouslyResampled = true; } else { _particles = particles; _previouslyResampled = false; } }