本文整理了Java中com.google.common.collect.Multimap.keySet()
方法的一些代码示例,展示了Multimap.keySet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multimap.keySet()
方法的具体详情如下:
包路径:com.google.common.collect.Multimap
类名称:Multimap
方法名:keySet
[英]Returns a view collection of all distinct keys contained in this multimap. Note that the key set contains a key if and only if this multimap maps that key to at least one value.
Changes to the returned set will update the underlying multimap, and vice versa. However, adding to the returned set is not possible.
[中]返回此多重映射中包含的所有不同键的视图集合。请注意,该键集包含一个键,当且仅当此多重映射将该键映射到至少一个值时。
对返回集的更改将更新基础多重映射,反之亦然。但是,无法添加到返回的集合中。
代码示例来源:origin: google/guava
@Override
public int size() {
return multimap.keySet().size();
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
public void printStopsForPatterns(String prefix, Multimap<TripPattern, StopAtDistance> stopClustersByPattern) {
for (TripPattern tp : stopClustersByPattern.keySet()) {
LOG.info("{} {}", prefix, tp.code);
for (StopAtDistance sd : stopClustersByPattern.get(tp)) {
LOG.info(" {}", sd);
}
}
}
代码示例来源:origin: ctripcorp/apollo
/**
* Create permissions, note that permissionType + targetId should be unique
*/
@Transactional
public Set<Permission> createPermissions(Set<Permission> permissions) {
Multimap<String, String> targetIdPermissionTypes = HashMultimap.create();
for (Permission permission : permissions) {
targetIdPermissionTypes.put(permission.getTargetId(), permission.getPermissionType());
}
for (String targetId : targetIdPermissionTypes.keySet()) {
Collection<String> permissionTypes = targetIdPermissionTypes.get(targetId);
List<Permission> current =
permissionRepository.findByPermissionTypeInAndTargetId(permissionTypes, targetId);
Preconditions.checkState(CollectionUtils.isEmpty(current),
"Permission with permissionType %s targetId %s already exists!", permissionTypes,
targetId);
}
Iterable<Permission> results = permissionRepository.saveAll(permissions);
return FluentIterable.from(results).toSet();
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
patternsByRoute.put(ttp.route, ttp);
for (Route route : patternsByRoute.keySet()) {
String routeName = GtfsLibrary.getRouteName(route);
if (usedRouteNames.contains(routeName)) {
ROUTE : for (Route route : patternsByRoute.keySet()) {
Collection<TripPattern> routeTripPatterns = patternsByRoute.get(route);
String routeName = uniqueRouteNames.get(route);
if (ends.get(end).size() == 1) {
pattern.name = sb.toString();
continue PATTERN; // only pattern with this last stop
if (starts.get(start).size() == 1) {
pattern.name = (sb.toString());
continue PATTERN; // only pattern with this first stop
if (remainingPatterns.size() == 1) {
pattern.name = (sb.toString());
continue PATTERN;
if (remainingPatterns.size() == 2) {
for (Route route : patternsByRoute.keySet()) {
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testHashCode() throws Exception {
CopyableDataset copyableDataset = new TestCopyableDataset();
Path target = new Path("/target");
CopyableDatasetMetadata metadata = new CopyableDatasetMetadata(copyableDataset);
String serialized = metadata.serialize();
CopyableDatasetMetadata deserialized = CopyableDatasetMetadata.deserialize(serialized);
CopyableDatasetMetadata deserialized2 = CopyableDatasetMetadata.deserialize(serialized);
Multimap<CopyableDatasetMetadata, WorkUnitState> datasetRoots = ArrayListMultimap.create();
datasetRoots.put(deserialized, new WorkUnitState());
datasetRoots.put(deserialized2, new WorkUnitState());
Assert.assertEquals(datasetRoots.keySet().size(), 1);
}
代码示例来源:origin: prestodb/presto
@Benchmark
@OperationsPerInvocation(SPLITS)
public Object benchmark(BenchmarkData data)
{
List<RemoteTask> remoteTasks = ImmutableList.copyOf(data.getTaskMap().values());
Iterator<MockRemoteTaskFactory.MockRemoteTask> finishingTask = Iterators.cycle(data.getTaskMap().values());
Iterator<Split> splits = data.getSplits().iterator();
Set<Split> batch = new HashSet<>();
while (splits.hasNext() || !batch.isEmpty()) {
Multimap<Node, Split> assignments = data.getNodeSelector().computeAssignments(batch, remoteTasks).getAssignments();
for (Node node : assignments.keySet()) {
MockRemoteTaskFactory.MockRemoteTask remoteTask = data.getTaskMap().get(node);
remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder()
.putAll(new PlanNodeId("sourceId"), assignments.get(node))
.build());
remoteTask.startSplits(MAX_SPLITS_PER_NODE);
}
if (assignments.size() == batch.size()) {
batch.clear();
}
else {
batch.removeAll(assignments.values());
}
while (batch.size() < SPLIT_BATCH_SIZE && splits.hasNext()) {
batch.add(splits.next());
}
finishingTask.next().finishSplits((int) Math.ceil(MAX_SPLITS_PER_NODE / 50.0));
}
return remoteTasks;
}
代码示例来源:origin: google/guava
public void testLinkedKeySet() {
Multimap<String, Integer> map = create();
map.put("bar", 1);
map.put("foo", 2);
map.put("bar", 3);
map.put("bar", 4);
assertEquals("[bar, foo]", map.keySet().toString());
map.keySet().remove("bar");
assertEquals("{foo=[2]}", map.toString());
}
代码示例来源:origin: google/guava
assertSetIsUnmodifiable(multimap.keySet(), sampleKey);
assertMultimapRemainsUnmodified(multimap, originalEntries);
K key = multimap.keySet().iterator().next();
assertCollectionIsUnmodifiable(multimap.get(key), sampleValue);
assertMultimapRemainsUnmodified(multimap, originalEntries);
multimap.put(sampleKey, sampleValue);
fail("put succeeded on unmodifiable multimap");
} catch (UnsupportedOperationException expected) {
multimap2.put(sampleKey, sampleValue);
try {
multimap.putAll(multimap2);
K presentKey = multimap.keySet().iterator().next();
try {
multimap.asMap().get(presentKey).remove(sampleValue);
代码示例来源:origin: google/guava
public void testNewMultimap() {
// The ubiquitous EnumArrayBlockingQueueMultimap
CountingSupplier<Queue<Integer>> factory = new QueueSupplier();
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory);
assertEquals(0, factory.count);
multimap.putAll(Color.BLUE, asList(3, 1, 4));
assertEquals(1, factory.count);
multimap.putAll(Color.RED, asList(2, 7, 1, 8));
assertEquals(2, factory.count);
assertEquals("[3, 1, 4]", multimap.get(Color.BLUE).toString());
Multimap<Color, Integer> ummodifiable = Multimaps.unmodifiableMultimap(multimap);
assertEquals("[3, 1, 4]", ummodifiable.get(Color.BLUE).toString());
Collection<Integer> collection = multimap.get(Color.BLUE);
assertEquals(collection, collection);
assertFalse(multimap.keySet() instanceof SortedSet);
assertFalse(multimap.asMap() instanceof SortedMap);
}
代码示例来源:origin: google/guava
private ArrayListMultimap(Multimap<? extends K, ? extends V> multimap) {
this(
multimap.keySet().size(),
(multimap instanceof ArrayListMultimap)
? ((ArrayListMultimap<?, ?>) multimap).expectedValuesPerKey
: DEFAULT_VALUES_PER_KEY);
putAll(multimap);
}
代码示例来源:origin: palantir/atlasdb
private void scrubCells(TransactionManager txManager,
Multimap<TableReference, Cell> tableNameToCells,
long scrubTimestamp,
Transaction.TransactionType transactionType) {
Map<TableReference, Multimap<Cell, Long>> allCellsToMarkScrubbed =
Maps.newHashMapWithExpectedSize(tableNameToCells.keySet().size());
for (Entry<TableReference, Collection<Cell>> entry : tableNameToCells.asMap().entrySet()) {
TableReference tableRef = entry.getKey();
log.debug("Attempting to immediately scrub {} cells from table {}", entry.getValue().size(), tableRef);
for (List<Cell> cells : Iterables.partition(entry.getValue(), batchSizeSupplier.get())) {
Multimap<Cell, Long> allTimestamps = keyValueService.getAllTimestamps(
tableRef, ImmutableSet.copyOf(cells), scrubTimestamp);
Multimap<Cell, Long> timestampsToDelete = Multimaps.filterValues(
allTimestamps, v -> !v.equals(Value.INVALID_VALUE_TIMESTAMP));
// If transactionType == TransactionType.AGGRESSIVE_HARD_DELETE this might
// force other transactions to abort or retry
deleteCellsAtTimestamps(txManager, tableRef, timestampsToDelete, transactionType);
Multimap<Cell, Long> cellsToMarkScrubbed = HashMultimap.create(allTimestamps);
for (Cell cell : cells) {
cellsToMarkScrubbed.put(cell, scrubTimestamp);
}
allCellsToMarkScrubbed.put(tableRef, cellsToMarkScrubbed);
}
log.debug("Immediately scrubbed {} cells from table {}", entry.getValue().size(), tableRef);
}
scrubberStore.markCellsAsScrubbed(allCellsToMarkScrubbed, batchSizeSupplier.get());
}
代码示例来源:origin: prestodb/presto
MockRemoteTaskFactory remoteTaskFactory = new MockRemoteTaskFactory(remoteTaskExecutor, remoteTaskScheduledExecutor);
int task = 0;
for (Node node : assignments.keySet()) {
TaskId taskId = new TaskId("test", 1, task);
task++;
MockRemoteTaskFactory.MockRemoteTask remoteTask = remoteTaskFactory.createTableScanTask(taskId, node, ImmutableList.copyOf(assignments.get(node)), nodeTaskMap.createPartitionedSplitCountTracker(node, taskId));
remoteTask.startSplits(25);
nodeTaskMap.addTask(node, remoteTask);
for (Node node : assignments.keySet()) {
RemoteTask remoteTask = taskMap.get(node);
remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder()
.putAll(new PlanNodeId("sourceId"), assignments.get(node))
.build());
for (Node node : assignments.keySet()) {
RemoteTask remoteTask = taskMap.get(node);
remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder()
.putAll(new PlanNodeId("sourceId"), assignments.get(node))
.build());
for (Node node : assignments.keySet()) {
RemoteTask remoteTask = taskMap.get(node);
remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder()
assignments = nodeSelector.computeAssignments(localSplits.build(), ImmutableList.copyOf(taskMap.values())).getAssignments();
assertEquals(assignments.size(), 3);
assertEquals(assignments.keySet().size(), 3);
代码示例来源:origin: opentripplanner/OpenTripPlanner
/** merge similar states (states that have come from the same place on different patterns) */
public void mergeStates() {
Set<TransitStop> touchedStopVertices = new HashSet<TransitStop>(states.keySet());
for (TransitStop tstop : touchedStopVertices) {
Collection<ProfileState> pss = states.get(tstop);
// find states that have come from the same place
Multimap<ProfileState, ProfileState> foundStates = ArrayListMultimap.create();
for (Iterator<ProfileState> it = pss.iterator(); it.hasNext();) {
ProfileState ps = it.next();
foundStates.put(ps.previous, ps);
}
pss.clear();
// merge them now
for (Collection<ProfileState> states : foundStates.asMap().values()) {
if (states.size() == 1)
pss.addAll(states);
else
pss.add(ProfileState.merge(states, true));
}
}
}
代码示例来源:origin: google/error-prone
private static ImmutableList<Fix> buildValidReplacements(
Multimap<Integer, JCVariableDecl> potentialReplacements,
Function<JCVariableDecl, Fix> replacementFunction) {
if (potentialReplacements.isEmpty()) {
return ImmutableList.of();
}
// Take all of the potential edit-distance replacements with the same minimum distance,
// then suggest them as individual fixes.
return potentialReplacements.get(Collections.min(potentialReplacements.keySet())).stream()
.map(replacementFunction)
.collect(toImmutableList());
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutPresentKeyPropagatesToAsMapEntrySet() {
List<K> keys = Helpers.copyToList(multimap().keySet());
for (K key : keys) {
resetContainer();
int size = getNumElements();
Iterator<Entry<K, Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator();
Collection<V> collection = null;
while (asMapItr.hasNext()) {
Entry<K, Collection<V>> asMapEntry = asMapItr.next();
if (key.equals(asMapEntry.getKey())) {
collection = asMapEntry.getValue();
break;
}
}
assertNotNull(collection);
Collection<V> expectedCollection = Helpers.copyToList(collection);
multimap().put(key, v3());
expectedCollection.add(v3());
assertEqualIgnoringOrder(expectedCollection, collection);
assertEquals(size + 1, multimap().size());
}
}
}
代码示例来源:origin: MovingBlocks/Terasology
api.put(category, apiPackage + " (PACKAGE)");
} else {
addToApi(category, apiClass, api);
api.put(category, apiPackage + " (PACKAGE)");
} else {
addToApi(category, apiClass, api);
for (String key : api.keySet()) {
stringApi.append("## ");
stringApi.append(key);
stringApi.append("\n");
for (String value : api.get(key)) {
stringApi.append("* ");
stringApi.append(value);
代码示例来源:origin: google/guava
private LinkedListMultimap(Multimap<? extends K, ? extends V> multimap) {
this(multimap.keySet().size());
putAll(multimap);
}
代码示例来源:origin: prestodb/presto
if (type.isComparable()) {
if (!functions.canResolveOperator(HASH_CODE, BIGINT, ImmutableList.of(type))) {
missingOperators.put(type, HASH_CODE);
missingOperators.put(type, EQUAL);
missingOperators.put(type, NOT_EQUAL);
for (Type type : missingOperators.keySet()) {
messages.add(format("%s missing for %s", missingOperators.get(type), type));
代码示例来源:origin: google/truth
private static <K, V> String countDuplicatesMultimap(Multimap<K, V> multimap) {
List<String> entries = new ArrayList<>();
for (K key : multimap.keySet()) {
entries.add(key + "=" + SubjectUtils.countDuplicates(multimap.get(key)));
}
StringBuilder sb = new StringBuilder();
sb.append("{");
Joiner.on(", ").appendTo(sb, entries);
sb.append("}");
return sb.toString();
}
代码示例来源:origin: google/guava
public void testFilterFiltered() {
Multimap<String, Integer> unfiltered = HashMultimap.create();
unfiltered.put("foo", 55556);
unfiltered.put("badkey", 1);
unfiltered.put("foo", 1);
Multimap<String, Integer> keyFiltered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
Multimap<String, Integer> filtered = Multimaps.filterValues(keyFiltered, VALUE_PREDICATE);
assertEquals(1, filtered.size());
assertTrue(filtered.containsEntry("foo", 1));
assertTrue(filtered.keySet().retainAll(Arrays.asList("cat", "dog")));
assertEquals(0, filtered.size());
}
内容来源于网络,如有侵权,请联系作者删除!