List of usage examples for com.google.common.collect Multiset isEmpty
boolean isEmpty();
From source file:com.b2international.snowowl.snomed.reasoner.server.diff.BranchMetadataNamespaceAndModuleAssigner.java
@Override public void allocateRelationshipIdsAndModules(Multiset<String> conceptIds, final SnomedEditingContext editingContext) { if (conceptIds.isEmpty()) { return;/*from w w w. j av a 2s .c om*/ } try { Branch branch = RepositoryRequests.branching().prepareGet(editingContext.getBranch()) .build(SnomedDatastoreActivator.REPOSITORY_UUID) .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync(); String defaultModuleId = BranchMetadataResolver.getEffectiveBranchMetadataValue(branch, SnomedCoreConfiguration.BRANCH_DEFAULT_MODULE_ID_KEY); String defaultNamespaceId = BranchMetadataResolver.getEffectiveBranchMetadataValue(branch, SnomedCoreConfiguration.BRANCH_DEFAULT_NAMESPACE_KEY); ISnomedIdentifierService identifierService = getServiceForClass(ISnomedIdentifierService.class); String defaultNamespace = Strings.isNullOrEmpty(defaultNamespaceId) ? editingContext.getDefaultNamespace() : defaultNamespaceId; reservedIds = identifierService.reserve(defaultNamespace, ComponentCategory.RELATIONSHIP, conceptIds.size()); relationshipIds = reservedIds.iterator(); defaultRelationshipModuleConcept = Strings.isNullOrEmpty(defaultModuleId) ? editingContext.getDefaultModuleConcept() : editingContext.getConcept(defaultModuleId); } catch (NotFoundException e) { super.allocateRelationshipIdsAndModules(conceptIds, editingContext); } }
From source file:com.sonarsource.lits.DumpPhase.java
@VisibleForTesting private void createMissingIssues(SensorContext context, InputComponent resource) { Multiset<IssueKey> componentIssues = checker.getByComponentKey(resource.key()); if (!componentIssues.isEmpty()) { checker.disabled = true;/* w w w.j a v a 2 s . c o m*/ for (IssueKey issueKey : checker.getByComponentKey(resource.key())) { // missing issue => create checker.different = true; RuleKey ruleKey = RuleKey.parse(issueKey.ruleKey); ActiveRule activeRule = profile.getActiveRule(ruleKey.repository(), ruleKey.rule()); if (activeRule == null) { // rule not active => skip it checker.inactiveRule(issueKey.ruleKey); continue; } checker.differences++; NewIssue newIssue = context.newIssue(); NewIssueLocation location = newIssue.newLocation().on(resource).message("Missing"); if (issueKey.line != 0) { location.at(((InputFile) resource).selectLine(issueKey.line)); } newIssue.forRule(ruleKey).overrideSeverity(Severity.BLOCKER).at(location).save(); } checker.disabled = false; componentIssues.clear(); } }
From source file:de.unipassau.isl.evs.ssh.core.messaging.IncomingDispatcher.java
@Override public String toString() { StringBuilder bob = new StringBuilder(); bob.append(getClass().getSimpleName()).append(" ["); final Multiset<RoutingKey> keys = mappings.keys(); if (!keys.isEmpty()) { bob.append("\n"); for (RoutingKey key : keys) { bob.append('\t').append(key).append(" => ").append(mappings.get(key)).append('\n'); }/*from w w w.j av a 2 s.c om*/ } bob.append("]"); return bob.toString(); }
From source file:org.apache.mahout.math.random.Multinomial.java
public Multinomial(Multiset<T> counts) { this();//from w w w. j av a 2s . c o m Preconditions.checkArgument(!counts.isEmpty(), "Need some data to build sampler"); rand = RandomUtils.getRandom(); for (T t : counts.elementSet()) { add(t, counts.count(t)); } }
From source file:de.blizzy.rust.lootconfig.LootConfigDump.java
private void run() throws IOException { LootConfig config = loadConfig(configFile); Table<LootContainer, Category, Multiset<Float>> dropChances = HashBasedTable.create(); Collection<LootContainer> lootContainers = config.LootContainers.values(); config.Categories.values().stream().filter(Category::hasItemsOrBlueprints).forEach(category -> { lootContainers.forEach(lootContainer -> { Multiset<Float> categoryInContainerDropChances = getItemCategoryDropChances(category, lootContainer);/*from w w w. ja v a2 s .c o m*/ if (!categoryInContainerDropChances.isEmpty()) { dropChances.put(lootContainer, category, categoryInContainerDropChances); } }); }); dropChances.rowKeySet().stream() .filter(lootContainer -> SHOW_DMLOOT || !lootContainer.name.contains("dmloot")) .sorted((lootContainer1, lootContainer2) -> Collator.getInstance().compare(lootContainer1.name, lootContainer2.name)) .forEach(lootContainer -> { System.out.printf("%s (blueprint fragments: %s)", lootContainer, lootContainer.DistributeFragments ? "yes" : "no").println(); Map<Category, Multiset<Float>> lootContainerDropChances = dropChances.row(lootContainer); AtomicDouble lootContainerDropChancesSum = new AtomicDouble(); AtomicInteger categoriesCount = new AtomicInteger(); lootContainerDropChances.entrySet().stream().sorted(this::compareByChances).limit(7) .forEach(categoryDropChancesEntry -> { Category category = categoryDropChancesEntry.getKey(); Multiset<Float> categoryDropChances = categoryDropChancesEntry.getValue(); float categoryDropChancesSum = sum(categoryDropChances); lootContainerDropChancesSum.addAndGet(categoryDropChancesSum); System.out.printf(" %s %s%s%s", formatPercent(categoryDropChancesSum), category, (category.Items.size() > 0) ? " (" + formatItems(category) + ")" : "", (category.Blueprints.size() > 0) ? " [" + formatBlueprints(category) + "]" : "") .println(); categoriesCount.incrementAndGet(); }); if (categoriesCount.get() < lootContainerDropChances.size()) { System.out.printf(" %s other (%d)", formatPercent(1f - (float) lootContainerDropChancesSum.get()), lootContainerDropChances.size() - categoriesCount.get()).println(); } }); }
From source file:com.google.inject.internal.WeakKeySet.java
/** * There may be multiple child injectors blacklisting a certain key so only remove the source * that's relevant./*from w w w .j a v a2 s .co m*/ */ private void cleanUpForCollectedState(Set<KeyAndSource> keysAndSources) { synchronized (lock) { for (KeyAndSource keyAndSource : keysAndSources) { Multiset<Object> set = backingMap.get(keyAndSource.blacklistKey); if (set != null) { set.remove(keyAndSource.source); if (set.isEmpty()) { backingMap.remove(keyAndSource.blacklistKey); } } } } }
From source file:com.palantir.atlasdb.keyvalue.impl.SweepStatsKeyValueService.java
private void flushWrites(Multiset<String> writes, Set<String> clears) { if (writes.isEmpty() && clears.isEmpty()) { log.debug("No writes to flush"); return;/* w w w . j av a 2s .c o m*/ } log.debug("Flushing stats for {} writes and {} clears", writes.size(), clears.size()); log.trace("Flushing writes: {}", writes); log.trace("Flushing clears: {}", clears); try { Set<String> tableNames = Sets.difference(writes.elementSet(), clears); Iterable<byte[]> rows = Collections2.transform(tableNames, Functions .compose(Persistables.persistToBytesFunction(), SweepPriorityRow.fromFullTableNameFun())); Map<Cell, Value> oldWriteCounts = delegate().getRows(SWEEP_PRIORITY_TABLE, rows, SweepPriorityTable.getColumnSelection(SweepPriorityNamedColumn.WRITE_COUNT), Long.MAX_VALUE); Map<Cell, byte[]> newWriteCounts = Maps.newHashMapWithExpectedSize(writes.elementSet().size()); byte[] col = SweepPriorityNamedColumn.WRITE_COUNT.getShortName(); for (String tableName : tableNames) { Preconditions.checkState(!tableName.startsWith(AtlasDbConstants.NAMESPACE_PREFIX), "The sweep stats kvs should wrap the namespace mapping kvs, not the other way around."); byte[] row = SweepPriorityRow.of(tableName).persistToBytes(); Cell cell = Cell.create(row, col); Value oldValue = oldWriteCounts.get(cell); long oldCount = oldValue == null || oldValue.getContents().length == 0 ? 0 : SweepPriorityTable.WriteCount.BYTES_HYDRATOR.hydrateFromBytes(oldValue.getContents()) .getValue(); long newValue = clears.contains(tableName) ? writes.count(tableName) : oldCount + writes.count(tableName); log.debug("Sweep priority for {} has {} writes (was {})", tableName, newValue, oldCount); newWriteCounts.put(cell, SweepPriorityTable.WriteCount.of(newValue).persistValue()); } long timestamp = timestampService.getFreshTimestamp(); // Committing before writing is intentional, we want the start timestamp to // show up in the transaction table before we write do our writes. commit(timestamp); delegate().put(SWEEP_PRIORITY_TABLE, newWriteCounts, timestamp); } catch (RuntimeException e) { Set<String> allTableNames = delegate().getAllTableNames(); if (!allTableNames.contains(SWEEP_PRIORITY_TABLE) || !allTableNames.contains(TransactionConstants.TRANSACTION_TABLE)) { // ignore problems when sweep or transaction tables don't exist log.warn("Ignoring failed sweep stats flush due to {}", e.getMessage(), e); } log.error("Unable to flush sweep stats for writes {} and clears {}: {}", writes, clears, e.getMessage(), e); throw e; } }
From source file:gr.forth.ics.swkm.model2.util.NamespaceDependenciesIndex.java
private void removeDependency(Uri uri1, Uri uri2, Direction direction) { Map<Uri, Multiset<Uri>> deps = deps(direction); Multiset<Uri> depsOfNamespace = depsPerNamespace(deps, uri1); depsOfNamespace.remove(uri2);//from w ww .j av a 2 s. c om if (depsOfNamespace.isEmpty()) { deps.remove(uri1); } }
From source file:net.shipilev.elections.cikrf.Parser.java
private void printSummaries(PrintWriter pw, String label, SummaryData data, List<String> key) { pw.printf("**** Summary for %s (aggregate over %s):\n", label, key.toString()); Multiset<Metric> set = data.get(key); if (set == null || set.isEmpty()) { pw.println("No data."); } else {/*from w w w .ja v a2 s . co m*/ for (Metric s : set.elementSet()) { pw.printf("%15d : %s\n", set.count(s), s.getLabel()); } } pw.printf("\n"); pw.flush(); }
From source file:pl.polzone.classifier.Classifier.java
public String predict(java.util.List<String> words) { final Multiset<String> scores = HashMultiset.create(); for (String word : words) { word = stem(word);//from www. j a va2 s . c om if (wordCount.getCount(word) > feedCount / 2) continue; if (occurences.containsKey(word)) for (Object category : occurences.get(word).uniqueSet()) scores.add((String) category, occurences.get(word).getCount(category) + (feedCount - wordCount.getCount(word))); } if (scores.isEmpty()) return null; Iterator<Entry<String>> sorted = Multisets.copyHighestCountFirst(scores).entrySet().iterator(); String highest = sorted.next().getElement(); if (sorted.hasNext()) { String runnerUp = sorted.next().getElement(); if (scores.count(highest) > scores.count(runnerUp) * 2) feed(highest, words); } return highest; }