com.google.common.collect.Multimap.put()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.4k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中com.google.common.collect.Multimap.put()方法的一些代码示例,展示了Multimap.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multimap.put()方法的具体详情如下:
包路径:com.google.common.collect.Multimap
类名称:Multimap
方法名:put

Multimap.put介绍

[英]Stores a key-value pair in this multimap.

Some multimap implementations allow duplicate key-value pairs, in which case putalways adds a new key-value pair and increases the multimap size by 1. Other implementations prohibit duplicates, and storing a key-value pair that's already in the multimap has no effect.
[中]在这个多重映射中存储一个键值对。
某些多重映射实现允许重复的键值对,在这种情况下,PutMap总是添加一个新的键值对,并将多重映射大小增加1。其他实现禁止重复,并且存储已经在multimap中的键值对没有效果。

代码示例

代码示例来源:origin: JanusGraph/janusgraph

private Multimap<String, Object> getDocument(final long time, final double weight) {
  final Multimap<String, Object> toReturn = HashMultimap.create();
  toReturn.put(NAME, "Hello world");
  toReturn.put(TIME, time);
  toReturn.put(WEIGHT, weight);
  return toReturn;
}

代码示例来源:origin: apache/incubator-druid

@Override
public void addLock(final String taskid, final TaskLock taskLock)
{
 giant.lock();
 try {
  Preconditions.checkNotNull(taskid, "taskid");
  Preconditions.checkNotNull(taskLock, "taskLock");
  taskLocks.put(taskid, taskLock);
 }
 finally {
  giant.unlock();
 }
}

代码示例来源:origin: google/guava

java.util.function.Function<? super T, ? extends V> valueFunction,
 java.util.function.Supplier<M> multimapSupplier) {
checkNotNull(keyFunction);
checkNotNull(valueFunction);
checkNotNull(multimapSupplier);
return Collector.of(
  multimapSupplier,
  (multimap, input) -> multimap.put(keyFunction.apply(input), valueFunction.apply(input)),
  (multimap1, multimap2) -> {
   multimap1.putAll(multimap2);

代码示例来源:origin: apache/hive

for (Map.Entry<String, Set<FileSplit>> entry : pathFileSplitsMap.entrySet()) {
     Utilities.getBucketFileNameFromPathSubString(entry.getKey());
 int bucketId = Utilities.getBucketIdFromFile(bucketIdStr);
 if (bucketId == -1) {
 bucketIds.put(bucketId, bucketId);
 for (FileSplit fsplit : entry.getValue()) {
  bucketToInitialSplitMap.put(bucketId, fsplit);
 for (Map.Entry<String, Set<FileSplit>> entry : pathFileSplitsMap.entrySet()) {
  int bucketId = bucketNum % numBuckets;
  for (FileSplit fsplit : entry.getValue()) {
   bucketToInitialSplitMap.put(bucketId, fsplit);
   for (InputSplit fsplit : bucketToInitialSplitMap.get(loopedBucketId)) {
    bucketToInitialSplitMap.put(bucketNum, fsplit);
     int bucketIdBase = i * inputNumBuckets;
     for (Integer bucketId : bucketIds.keySet()) {
      for (InputSplit fsplit : bucketToInitialSplitMap.get(bucketId)) {
       bucketToInitialSplitMap.put(bucketIdBase + bucketId, fsplit);

代码示例来源:origin: apache/incubator-gobblin

ConfigStoreAccessor accessor = this.getConfigStoreAccessor(u);
 ConfigKeyPath configKeypath = ConfigClientUtils.buildConfigKeyPath(u, accessor.configStore);
 partitionedAccessor.put(accessor, configKeypath);
  reverseMap.put(accessor, new HashMap<ConfigKeyPath, URI>());
 reverseMap.get(accessor).put(configKeypath, u);
for (Map.Entry<ConfigStoreAccessor, Collection<ConfigKeyPath>> entry : partitionedAccessor.asMap().entrySet()) {
 Map<ConfigKeyPath, Config> batchResult = entry.getKey().valueInspector.getResolvedConfigs(entry.getValue());
 for (Map.Entry<ConfigKeyPath, Config> resultEntry : batchResult.entrySet()) {
  URI orgURI = reverseMap.get(entry.getKey()).get(resultEntry.getKey());
  result.put(orgURI, resultEntry.getValue());

代码示例来源:origin: ctripcorp/apollo

public void register(BeanFactory beanFactory, String key, SpringValue springValue) {
 if (!registry.containsKey(beanFactory)) {
  synchronized (LOCK) {
   if (!registry.containsKey(beanFactory)) {
    registry.put(beanFactory, LinkedListMultimap.<String, SpringValue>create());
   }
  }
 }
 registry.get(beanFactory).put(key, springValue);
 // lazy initialize
 if (initialized.compareAndSet(false, true)) {
  initialize();
 }
}

代码示例来源:origin: searchbox-io/Jest

@Deprecated
public K setParameter(Map<String, Object> parameters) {
  for (Map.Entry<String, Object> entry : parameters.entrySet()) {
    this.parameters.put(entry.getKey(), entry.getValue());
  }
  return (K) this;
}

代码示例来源:origin: EngineHub/WorldEdit

public static void registerClipboardFormat(ClipboardFormat format) {
  checkNotNull(format);
  for (String key : format.getAliases()) {
    String lowKey = key.toLowerCase(Locale.ENGLISH);
    ClipboardFormat old = aliasMap.put(lowKey, format);
    if (old != null) {
      aliasMap.put(lowKey, old);
      WorldEdit.logger.warning(format.getClass().getName() + " cannot override existing alias '" + lowKey + "' used by " + old.getClass().getName());
    }
  }
  for (String ext : format.getFileExtensions()) {
    String lowExt = ext.toLowerCase(Locale.ENGLISH);
    fileExtensionMap.put(lowExt, format);
  }
  registeredFormats.add(format);
}

代码示例来源:origin: Sable/soot

private void emitTraps() {
 Chain<Trap> traps = body.getTraps();
 SootClass throwable = Scene.v().getSootClass("java.lang.Throwable");
 Map<LabelNode, Iterator<UnitBox>> handlers = new HashMap<LabelNode, Iterator<UnitBox>>(tryCatchBlocks.size());
 for (TryCatchBlockNode tc : tryCatchBlocks) {
  UnitBox start = Jimple.v().newStmtBox(null);
  UnitBox end = Jimple.v().newStmtBox(null);
  Iterator<UnitBox> hitr = handlers.get(tc.handler);
  if (hitr == null) {
   hitr = trapHandlers.get(tc.handler).iterator();
   handlers.put(tc.handler, hitr);
  }
  UnitBox handler = hitr.next();
  SootClass cls = tc.type == null ? throwable : Scene.v().getSootClass(AsmUtil.toQualifiedName(tc.type));
  Trap trap = Jimple.v().newTrap(cls, start, end, handler);
  traps.add(trap);
  labels.put(tc.start, start);
  labels.put(tc.end, end);
 }
}

代码示例来源:origin: apache/hive

public ClassicTableTypeMapping () {
 hiveToClientMap.put(TableType.MANAGED_TABLE.name(), ClassicTableTypes.TABLE.name());
 hiveToClientMap.put(TableType.EXTERNAL_TABLE.name(), ClassicTableTypes.TABLE.name());
 hiveToClientMap.put(TableType.VIRTUAL_VIEW.name(), ClassicTableTypes.VIEW.name());
 hiveToClientMap.put(TableType.MATERIALIZED_VIEW.toString(),
     ClassicTableTypes.MATERIALIZED_VIEW.toString());
 clientToHiveMap.putAll(ClassicTableTypes.TABLE.name(), Arrays.asList(
   TableType.MANAGED_TABLE.name(), TableType.EXTERNAL_TABLE.name()));
 clientToHiveMap.put(ClassicTableTypes.VIEW.name(), TableType.VIRTUAL_VIEW.name());
 clientToHiveMap.put(ClassicTableTypes.MATERIALIZED_VIEW.toString(),
     TableType.MATERIALIZED_VIEW.toString());
}

代码示例来源:origin: immutables/immutables

private static List<ExecutableElement> disambiguateMethods(
  Iterable<? extends ExecutableElement> methods) {
 Multimap<String, ExecutableElement> methodsAlternatives = HashMultimap.create();
 for (ExecutableElement m : methods) {
  if (IsParameterlessNonstaticNonobject.PREDICATE.apply(m)) {
   methodsAlternatives.put(ToSimpleName.FUNCTION.apply(m), m);
 entries: for (Entry<String, Collection<ExecutableElement>> e : methodsAlternatives.asMap().entrySet()) {
  Collection<ExecutableElement> values = e.getValue();
  if (values.size() == 1) {
   resolvedMethods.addAll(values);

代码示例来源:origin: google/guava

multimap.asMap().entrySet(), Maps.immutableEntry(sampleKey, sampleValueAsCollection));
 Collection<V> values = multimap.asMap().entrySet().iterator().next().getValue();
 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);

代码示例来源:origin: apache/storm

@Override
public void handleDataPoints(TaskInfo taskInfo, Collection<DataPoint> dataPoints) {
  synchronized (BUFFER) {
    for (DataPoint dp : dataPoints) {
      for (Map.Entry<String, Object> entry : expandComplexDataPoint(dp).entrySet()) {
        String metricName = entry.getKey();
        Multimap<Integer, Object> taskIdToBucket = BUFFER.get(taskInfo.srcComponentId, metricName);
        if (null == taskIdToBucket) {
          taskIdToBucket = ArrayListMultimap.create();
          taskIdToBucket.put(taskInfo.srcTaskId, entry.getValue());
        } else {
          taskIdToBucket.get(taskInfo.srcTaskId).add(entry.getValue());
        }
        BUFFER.put(taskInfo.srcComponentId, metricName, taskIdToBucket);
      }
    }
  }
}

代码示例来源:origin: SonarSource/sonarqube

protected void match(Tracking<RAW, BASE> tracking, Function<Trackable, SearchKey> searchKeyFactory) {
 if (tracking.isComplete()) {
  return;
 }
 Multimap<SearchKey, BASE> baseSearch = ArrayListMultimap.create();
 tracking.getUnmatchedBases()
  .forEach(base -> baseSearch.put(searchKeyFactory.apply(base), base));
 tracking.getUnmatchedRaws().forEach(raw -> {
  SearchKey rawKey = searchKeyFactory.apply(raw);
  Collection<BASE> bases = baseSearch.get(rawKey);
  bases.stream()
   .sorted(comparing(this::statusRank).reversed()
    .thenComparing(comparing(Trackable::getCreationDate)))
   .findFirst()
   .ifPresent(match -> {
    tracking.match(raw, match);
    baseSearch.remove(rawKey, match);
   });
 });
}

代码示例来源:origin: google/guava

Multimap<Class<?>, Class<?>> testClasses = HashMultimap.create();
LinkedHashSet<Class<?>> candidateClasses = Sets.newLinkedHashSet();
for (Class<?> cls : classes) {
  Class<?> testedClass = classMap.get(testedClassName.get());
  if (testedClass != null) {
   testClasses.put(testedClass, cls);
NEXT_CANDIDATE:
for (Class<?> candidate : Iterables.filter(candidateClasses, classFilter)) {
 for (Class<?> testClass : testClasses.get(candidate)) {
  if (hasTest(testClass, explicitTestNames)) {

代码示例来源:origin: jdbi/jdbi

private static <K, V, M extends Multimap<K, V>> void putEntry(M map, Map.Entry<K, V> entry) {
  map.put(entry.getKey(), entry.getValue());
}

代码示例来源:origin: google/guava

public void testMultimapEquals() {
 Multimap<String, Integer> multimap = createMultimap();
 Multimap<String, Integer> hashMultimap = HashMultimap.create();
 hashMultimap.putAll("foo", Arrays.asList(1, 3));
 hashMultimap.put("bar", 2);
 new EqualsTester()
   .addEqualityGroup(
     multimap,
     createMultimap(),
     hashMultimap,
     ImmutableSetMultimap.<String, Integer>builder()
       .put("bar", 2)
       .put("foo", 1)
       .put("foo", 3)
       .build(),
     ImmutableSetMultimap.<String, Integer>builder()
       .put("bar", 2)
       .put("foo", 3)
       .put("foo", 1)
       .build())
   .addEqualityGroup(
     ImmutableSetMultimap.<String, Integer>builder()
       .put("foo", 2)
       .put("foo", 3)
       .put("foo", 1)
       .build())
   .addEqualityGroup(
     ImmutableSetMultimap.<String, Integer>builder().put("bar", 2).put("foo", 3).build())
   .testEquals();
}

代码示例来源:origin: prestodb/presto

/**
 * This method creates a mapping from each index source lookup symbol (directly applied to the index)
 * to the corresponding probe key Input
 */
private SetMultimap<Symbol, Integer> mapIndexSourceLookupSymbolToProbeKeyInput(IndexJoinNode node, Map<Symbol, Integer> probeKeyLayout)
{
  Set<Symbol> indexJoinSymbols = node.getCriteria().stream()
      .map(IndexJoinNode.EquiJoinClause::getIndex)
      .collect(toImmutableSet());
  // Trace the index join symbols to the index source lookup symbols
  // Map: Index join symbol => Index source lookup symbol
  Map<Symbol, Symbol> indexKeyTrace = IndexJoinOptimizer.IndexKeyTracer.trace(node.getIndexSource(), indexJoinSymbols);
  // Map the index join symbols to the probe key Input
  Multimap<Symbol, Integer> indexToProbeKeyInput = HashMultimap.create();
  for (IndexJoinNode.EquiJoinClause clause : node.getCriteria()) {
    indexToProbeKeyInput.put(clause.getIndex(), probeKeyLayout.get(clause.getProbe()));
  }
  // Create the mapping from index source look up symbol to probe key Input
  ImmutableSetMultimap.Builder<Symbol, Integer> builder = ImmutableSetMultimap.builder();
  for (Map.Entry<Symbol, Symbol> entry : indexKeyTrace.entrySet()) {
    Symbol indexJoinSymbol = entry.getKey();
    Symbol indexLookupSymbol = entry.getValue();
    builder.putAll(indexLookupSymbol, indexToProbeKeyInput.get(indexJoinSymbol));
  }
  return builder.build();
}

代码示例来源:origin: ctripcorp/apollo

Map<String, ApolloConfigNotification> filteredNotifications = filterNotifications(appId, notifications);
for (Map.Entry<String, ApolloConfigNotification> notificationEntry : filteredNotifications.entrySet()) {
 String normalizedNamespace = notificationEntry.getKey();
 ApolloConfigNotification notification = notificationEntry.getValue();
 namespaces.add(normalizedNamespace);
 clientSideNotifications.put(normalizedNamespace, notification.getNotificationId());
 if (!Objects.equals(notification.getNamespaceName(), normalizedNamespace)) {
  deferredResultWrapper.recordNamespaceNameNormalizedResult(notification.getNamespaceName(), normalizedNamespace);
  this.deferredResults.put(key, deferredResultWrapper);

代码示例来源:origin: opentripplanner/OpenTripPlanner

public synchronized void catalog (String workerId, String graphAffinity) {
  WorkerObservation observation = new WorkerObservation(workerId, graphAffinity);
  WorkerObservation oldObservation = observationsByWorkerId.put(workerId, observation);
  if (oldObservation != null) {
    workersByGraph.remove(oldObservation.graphAffinity, workerId);
  }
  workersByGraph.put(graphAffinity, workerId);
}

相关文章