com.google.common.collect.Maps类的使用及代码示例

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

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

Maps介绍

[英]Static utility methods pertaining to Map instances (including instances of SortedMap, BiMap, etc.). Also see this class's counterparts Lists, Sets and Queues.

See the Guava User Guide article on Maps.
[中]与映射实例(包括SortedMap、BiMap等)相关的静态实用程序方法。还可以查看该类的对应列表、集合和队列。
请参阅关于Maps的Guava用户指南文章。

代码示例

代码示例来源:origin: Graylog2/graylog2-server

public Periodicals(ScheduledExecutorService scheduler, ScheduledExecutorService daemonScheduler) {
  this.scheduler = scheduler;
  this.daemonScheduler = daemonScheduler;
  this.periodicals = Lists.newArrayList();
  this.futures = Maps.newHashMap();
}

代码示例来源:origin: com.google.inject/guice

private RecordingBinder(Stage stage) {
 this.stage = stage;
 this.modules = Maps.newLinkedHashMap();
 this.scanners = Sets.newLinkedHashSet();
 this.elements = Lists.newArrayList();
 this.source = null;
 this.sourceProvider =
   SourceProvider.DEFAULT_INSTANCE.plusSkippedClasses(
     Elements.class,
     RecordingBinder.class,
     AbstractModule.class,
     ConstantBindingBuilderImpl.class,
     AbstractBindingBuilder.class,
     BindingBuilder.class);
 this.parent = null;
 this.privateElements = null;
 this.privateBinders = Lists.newArrayList();
}

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

Iterable<? extends Class<?>> classes, Iterable<String> explicitTestNames) {
TreeMap<String, Class<?>> classMap = Maps.newTreeMap();
for (Class<?> cls : classes) {
 classMap.put(cls.getName(), cls);
LinkedHashSet<Class<?>> candidateClasses = Sets.newLinkedHashSet();
for (Class<?> cls : classes) {
 Optional<String> testedClassName = TEST_SUFFIX.chop(cls.getName());
List<Class<?>> result = Lists.newArrayList();
NEXT_CANDIDATE:
for (Class<?> candidate : Iterables.filter(candidateClasses, classFilter)) {
 for (Class<?> testClass : testClasses.get(candidate)) {
  if (hasTest(testClass, explicitTestNames)) {

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

/** Returns an empty mutable map whose keys will respect this {@link ElementOrder}. */
<K extends T, V> Map<K, V> createMap(int expectedSize) {
 switch (type) {
  case UNORDERED:
   return Maps.newHashMapWithExpectedSize(expectedSize);
  case INSERTION:
   return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
  case SORTED:
   return Maps.newTreeMap(comparator());
  default:
   throw new AssertionError();
 }
}

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

@Override
 protected Map<String, String> create(Entry<String, String>[] entries) {
  Map<String, String> map = Maps.newLinkedHashMap();
  for (Entry<String, String> entry : entries) {
   map.put(entry.getKey(), encode(entry.getValue()));
  }
  return Maps.transformValues(map, DECODE_FUNCTION);
 }
})

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

@Override
public Map<Symbol, Symbol> visitProject(ProjectNode node, Set<Symbol> lookupSymbols)
{
  // Map from output Symbols to source Symbols
  Map<Symbol, Symbol> directSymbolTranslationOutputMap = Maps.transformValues(Maps.filterValues(node.getAssignments().getMap(), SymbolReference.class::isInstance), Symbol::from);
  Map<Symbol, Symbol> outputToSourceMap = lookupSymbols.stream()
      .filter(directSymbolTranslationOutputMap.keySet()::contains)
      .collect(toImmutableMap(identity(), directSymbolTranslationOutputMap::get));
  checkState(!outputToSourceMap.isEmpty(), "No lookup symbols were able to pass through the projection");
  // Map from source Symbols to underlying index source Symbols
  Map<Symbol, Symbol> sourceToIndexMap = node.getSource().accept(this, ImmutableSet.copyOf(outputToSourceMap.values()));
  // Generate the Map the connects lookup symbols to underlying index source symbols
  Map<Symbol, Symbol> outputToIndexMap = Maps.transformValues(Maps.filterValues(outputToSourceMap, in(sourceToIndexMap.keySet())), Functions.forMap(sourceToIndexMap));
  return ImmutableMap.copyOf(outputToIndexMap);
}

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

@Test
public void test() throws Exception {
 Map<String, String> confMap = Maps.newHashMap();
 confMap.put("key1", "value1");
 confMap.put(ConfigurationKeys.REQUIRED_ATRRIBUTES_LIST, "required1,required2");
 confMap.put(StaticJobTemplate.SUPER_TEMPLATE_KEY, "template2");
 JobCatalogWithTemplates catalog = Mockito.mock(JobCatalogWithTemplates.class);
 Mockito.when(catalog.getTemplate(new URI("template2"))).thenAnswer(
   new InheritingJobTemplateTest.TestTemplateAnswer(
     Lists.<URI>newArrayList(), ImmutableMap.of("key2", "value2"),
     Lists.<String>newArrayList(), catalog));
 StaticJobTemplate template =
   new StaticJobTemplate(new URI("template"), "1", "desc", ConfigFactory.parseMap(confMap), catalog);
 Assert.assertEquals(template.getSuperTemplates().size(), 1);
 Assert.assertEquals(template.getSuperTemplates().iterator().next().getUri(), new URI("template2"));
 Collection<String> required = template.getRequiredConfigList();
 Assert.assertEquals(required.size(), 2);
 Assert.assertTrue(required.contains("required1"));
 Assert.assertTrue(required.contains("required2"));
 Config rawTemplate = template.getRawTemplateConfig();
 Assert.assertEquals(rawTemplate.getString("key1"), "value1");
 Assert.assertEquals(rawTemplate.getString("key2"), "value2");
 Config resolved = template.getResolvedConfig(ConfigFactory.parseMap(ImmutableMap.of("required1", "r1", "required2", "r2")));
 Assert.assertEquals(resolved.getString("key1"), "value1");
 Assert.assertEquals(resolved.getString("key2"), "value2");
 Assert.assertEquals(resolved.getString("required1"), "r1");
 Assert.assertEquals(resolved.getString("required2"), "r2");
}

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

/**
 *
 */
@Test
public void testCollectionsInCollection() {
  GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
  obj.foo = Lists.newArrayList(
    Lists.newArrayList(1, 2),
    Lists.newLinkedList(Arrays.asList(1, 2)),
    Sets.newHashSet("a", "b"),
    Sets.newLinkedHashSet(Arrays.asList("a", "b")),
    Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b")));
  GridBinaryTestClasses.TestObjectContainer deserialized = wrap(obj).build().deserialize();
  assertEquals(obj.foo, deserialized.foo);
}

代码示例来源:origin: spotify/helios

final Map<String, byte[]> portNodes = Maps.newHashMap();
final byte[] idJson = id.toJsonBytes();
for (final int port : staticPorts) {
final List<ZooKeeperOperation> operations = Lists.newArrayList(
  check(jobPath),
  create(portNodes),
return ImmutableList.copyOf(operations);

代码示例来源:origin: spotify/helios

@Test
public void testMergeFileAndCliArgs() throws Exception {
 final Map<String, PortMapping> ports = ImmutableMap.of(
   "foo", PortMapping.of(4711),
   "bar", PortMapping.of(5000, externalPort));
 final Map<ServiceEndpoint, ServicePorts> registration = ImmutableMap.of(
   ServiceEndpoint.of("foo-service", "tcp"), ServicePorts.of("foo"),
   ServiceEndpoint.of("bar-service", "http"), ServicePorts.of("bar"));
 final String registrationDomain = "my-domain";
 final Map<String, String> env = ImmutableMap.of("BAD", "f00d");
 final Map<String, String> volumes = Maps.newHashMap();
 volumes.put("/etc/spotify/secret-keys.yaml:ro", "/etc/spotify/secret-keys.yaml");
   .setCommand(Lists.newArrayList("server", "foo-service.yaml"))
   .setEnv(env)
   .setPorts(ports)
   .setToken("foo-token")
   .setNetworkMode("host")
   .setSecurityOpt(ImmutableList.of("label:user:dxia", "apparmor:foo"));
 final Job job = builder.build();
 final String jobConfigJsonString = job.toJsonString();

代码示例来源:origin: com.google.inject/guice

Element element = Iterables.getOnlyElement(baseElements);
 if (element instanceof PrivateElements) {
  PrivateElements privateElements = (PrivateElements) element;
  Elements.getElements(
    currentStage(),
    ImmutableList.<Module>builder().addAll(overrides).add(scannersModule).build());
final Set<Key<?>> overriddenKeys = Sets.newHashSet();
final Map<Class<? extends Annotation>, ScopeBinding> overridesScopeAnnotations =
  Maps.newHashMap();
final Map<Scope, List<Object>> scopeInstancesInUse = Maps.newHashMap();
final List<ScopeBinding> scopeBindings = Lists.newArrayList();
new ModuleWriter(binder) {
 @Override

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

public ClassAliasResolver(Class<T> subTypeOf) {
 Map<String, Class<? extends T>> cache = Maps.newHashMap();
 this.aliasObjects = Lists.newArrayList();
 for (Class<? extends T> clazz : REFLECTIONS.getSubTypesOf(subTypeOf)) {
  if (clazz.isAnnotationPresent(Alias.class)) {
   Alias aliasObject = clazz.getAnnotation(Alias.class);
   String alias = aliasObject.value().toUpperCase();
   if (cache.containsKey(alias)) {
    log.warn(String.format("Alias %s already mapped to class %s. Mapping for %s will be ignored", alias,
      cache.get(alias).getCanonicalName(), clazz.getCanonicalName()));
   } else {
    aliasObjects.add(aliasObject);
    cache.put(clazz.getAnnotation(Alias.class).value().toUpperCase(), clazz);
   }
  }
 }
 this.subtypeOf = subTypeOf;
 this.aliasToClassCache = ImmutableMap.copyOf(cache);
}

代码示例来源:origin: rubenlagus/TelegramBots

/**
 * @return a local non-thread safe copy of the database
 */
private Map<String, Object> localCopy() {
 return db.getAll().entrySet().stream().map(entry -> {
  Object struct = entry.getValue();
  if (struct instanceof Set)
   return Pair.of(entry.getKey(), newHashSet((Set) struct));
  else if (struct instanceof List)
   return Pair.of(entry.getKey(), newArrayList((List) struct));
  else if (struct instanceof Map)
   return Pair.of(entry.getKey(), newHashMap((Map) struct));
  else
   return Pair.of(entry.getKey(), struct);
 }).collect(toMap(pair -> (String) pair.a(), Pair::b));
}

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

splitToList(state.getProp(WikipediaExtractor.SOURCE_PAGE_TITLES)));
Map<String, LongWatermark> prevHighWatermarks = Maps.newHashMap();
for (Map.Entry<String, Iterable<WorkUnitState>> entry : previousWorkUnits.entrySet()) {
 Iterable<LongWatermark> watermarks =
   Iterables.transform(entry.getValue(), new Function<WorkUnitState, LongWatermark>() {
  @Override
  public LongWatermark apply(WorkUnitState wus) {
 watermarks = Iterables.filter(watermarks, Predicates.notNull());
 List<LongWatermark> watermarkList = Lists.newArrayList(watermarks);
 if (watermarkList.size() > 0) {
  prevHighWatermarks.put(entry.getKey(), Collections.max(watermarkList));
List<WorkUnit> workUnits = Lists.newArrayList();

代码示例来源:origin: spotify/helios

final Map<JobId, Execution> newExecutions = Maps.newHashMap(executions.get());
for (final Entry<JobId, Task> entry : tasks.entrySet()) {
 final JobId jobId = entry.getKey();
final Map<JobId, Execution> pending = ImmutableMap.copyOf(
  Maps.filterValues(newExecutions, PORT_ALLOCATION_PENDING));
if (!pending.isEmpty()) {
 final ImmutableSet.Builder<Integer> usedPorts = ImmutableSet.builder();
 final Map<JobId, Execution> allocated = Maps.filterValues(newExecutions, PORTS_ALLOCATED);
 for (final Entry<JobId, Execution> entry : allocated.entrySet()) {
  usedPorts.addAll(entry.getValue().getPorts().values());
 executions.setUnchecked(ImmutableMap.copyOf(newExecutions));
for (final Entry<JobId, Supervisor> entry : ImmutableSet.copyOf(supervisors.entrySet())) {
 final JobId jobId = entry.getKey();
 final Supervisor supervisor = entry.getValue();
final Set<JobId> reapedTasks = Sets.newHashSet();
for (final Entry<JobId, Execution> entry : executions.get().entrySet()) {
 final JobId jobId = entry.getKey();
 final Map<JobId, Execution> survivors = Maps.filterKeys(executions.get(),
   not(in(reapedTasks)));
 executions.setUnchecked(ImmutableMap.copyOf(survivors));

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

public Collection<PluginUpdateAggregate> aggregate(@Nullable Collection<PluginUpdate> pluginUpdates) {
 if (pluginUpdates == null || pluginUpdates.isEmpty()) {
  return Collections.emptyList();
 }
 Map<Plugin, PluginUpdateAggregateBuilder> builders = Maps.newHashMap();
 for (PluginUpdate pluginUpdate : pluginUpdates) {
  Plugin plugin = pluginUpdate.getPlugin();
  PluginUpdateAggregateBuilder builder = builders.get(plugin);
  if (builder == null) {
   builder = PluginUpdateAggregateBuilder.builderFor(plugin);
   builders.put(plugin, builder);
  }
  builder.add(pluginUpdate);
 }
 return Lists.newArrayList(transform(builders.values(), PluginUpdateAggregateBuilder::build));
}

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

return ImmutableList.of();
Map<String,RexNode> stringToRexNode = Maps.newLinkedHashMap();
for (RexNode r : predsToPushDown) {
 String rexNodeString = r.toString();
 return ImmutableList.of();
Set<String> predicatesInSubtree = Sets.newHashSet();
final RelMetadataQuery mq = inp.getCluster().getMetadataQuery();
for (RexNode pred : mq.getPulledUpPredicates(inp).pulledUpPredicates) {
 predicatesInSubtree.add(pred.toString());
 predicatesInSubtree.addAll(Lists.transform(RelOptUtil.conjunctions(pred), REX_STR_FN));
final ImmutableList.Builder<RexNode> newConjuncts = ImmutableList.builder();
for (Entry<String,RexNode> e : stringToRexNode.entrySet()) {
 if (predicatesInSubtree.add(e.getKey())) {

代码示例来源:origin: spotify/helios

@Test
public void testRollingUpdateCoordination() throws Exception {
 // stop the default master
 master.stopAsync().awaitTerminated();
 // start a bunch of masters and agents
 final Map<String, MasterMain> masters = startDefaultMasters(3);
 final Map<String, AgentMain> agents = Maps.newLinkedHashMap();
 for (int i = 0; i < 20; i++) {
  final String name = TEST_HOST + i;
  agents.put(name, startDefaultAgent(name, "--labels", TEST_LABEL));
 }
 // create a deployment group and start rolling out
 cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
 final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
 cli("rolling-update", "--async", "--par", String.valueOf(agents.size()), testJobNameAndVersion,
   TEST_GROUP);
 // wait until the task is running on the final agent
 awaitTaskState(jobId, getLast(agents.keySet()), TaskStatus.State.RUNNING);
 // ensure that all masters were involved
 final Set<String> deployingMasters = Sets.newHashSet();
 final Map<String, HostStatus> hostStatuses = defaultClient().hostStatuses(
   Lists.newArrayList(agents.keySet())).get();
 for (final HostStatus status : hostStatuses.values()) {
  for (final Deployment deployment : status.getJobs().values()) {
   deployingMasters.add(deployment.getDeployerMaster());
  }
 }
 assertEquals(masters.size(), deployingMasters.size());
}

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

Lists.newArrayList(Iterables.filter(datasetWorkUnitStates.getValue(), WATERMARK_WORKUNIT_PREDICATE));
Maps.newHashMap(this.previousWatermarks.getPartitionWatermarks(tableKey)));

代码示例来源:origin: google/error-prone

public Inliner(Context context, Bindings bindings) {
 this.context = new SubContext(context);
 this.bindings = new Bindings(bindings).unmodifiable();
 this.importsToAdd = Sets.newHashSet();
 this.staticImportsToAdd = Sets.newHashSet();
 this.typeVarCache = Maps.newHashMap();
}

相关文章