热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

本文整理了Java中com.google.common.collect.MultimapBuilder类的一些代码示例,展示了MultimapBuilder

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

MultimapBuilder介绍

[英]A builder for a multimap implementation that allows customization of the backing map and value collection implementations used in a particular multimap.

This can be used to easily configure multimap data structure implementations not provided explicitly in com.google.common.collect, for example:

ListMultimap treeListMultimap =

MultimapBuilder instances are immutable. Invoking a configuration method has no effect on the receiving instance; you must store and use the new builder instance it returns instead.

The generated multimaps are serializable if the key and value types are serializable, unless stated otherwise in one of the configuration methods.
[中]多映射实现的生成器,允许自定义特定多映射中使用的支持映射和值集合实现。
这可用于轻松配置com中未明确提供的多映射数据结构实现。谷歌。常见的收集,例如:

ListMultimap treeListMultimap =

MultimapBuilder实例是不可变的。调用配置方法对接收实例没有影响;您必须存储并使用它返回的新生成器实例。
如果键和值类型是可序列化的,则生成的多重映射是可序列化的,除非在其中一种配置方法中另有说明。

代码示例

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

public void testGenerics_gwtCompatible() {
ListMultimap a =
MultimapBuilder.hashKeys().arrayListValues().build();
SortedSetMultimap b =
MultimapBuilder.linkedHashKeys().treeSetValues().build();
SetMultimap c =
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER)
.hashSetValues()
.build();
}

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

/**
* Returns a {@code Multimap} with the specified implementation, initialized with the entries of
* {@code multimap}.
*/
public Multimap build(
Multimap multimap) {
Multimap result = build();
result.putAll(multimap);
return result;
}

代码示例来源:origin: greenaddress/GreenBits

@Override
protected Multimap getStateTransitions() {
Multimap result = MultimapBuilder.enumKeys(State.class).arrayListValues().build();
result.put(State.UNINITIALISED, State.NEW);
result.put(State.UNINITIALISED, State.READY);
result.put(State.NEW, State.SAVE_STATE_IN_WALLET);
result.put(State.SAVE_STATE_IN_WALLET, State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER);
result.put(State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, State.READY);
result.put(State.READY, State.EXPIRED);
result.put(State.READY, State.CLOSED);
return result;
}

代码示例来源:origin: dstl/baleen

private Multimap collateMentionsIntoEntities(
final Map mentions) {
final Multimap map =
MultimapBuilder.hashKeys().arrayListValues().build();
mentions.values().forEach(m -> map.put(m.getEntityId(), m));
return map;
}

代码示例来源:origin: Swagger2Markup/swagger2markup

operatiOnsGroupedByTag= LinkedHashMultimap.create();
} else {
operatiOnsGroupedByTag= MultimapBuilder.linkedHashKeys().treeSetValues(operationOrdering).build();
logger.debug("Added path operation '{}' to tag '{}'", operation, tag);
operationsGroupedByTag.put(tag, operation);

代码示例来源:origin: dstl/baleen

private void addMetadata(JCas jCas, Document doc) {
Multimap meta = MultimapBuilder.linkedHashKeys().linkedListValues().build();
for (Metadata metadata : JCasUtil.select(jCas, Metadata.class)) {
String key = metadata.getKey();
if (key.contains(".")) { // Field names can't contain a "." in Mongo, so replace with a _
key = key.replaceAll("\\.", "_");
}
meta.put(key, metadata.getValue());
}
doc.append(FIELD_METADATA, meta.asMap());
}

代码示例来源:origin: com.torodb.torod.backends/common

.enumKeys(ScalarType.class)
.hashSetValues()
.build();
byTypeValues.put(value.getType(), value);
if (byTypeValues.isEmpty()) {
result = Collections.emptyList();
} else {

代码示例来源:origin: imperial-crystalline-recursion/abtestgen

private void generateViewTests(Set annotations,
RoundEnvironment roundEnv) {
Multimap viewTestMap =
MultimapBuilder.linkedHashKeys().arrayListValues().build();
getTextTests(roundEnv, viewTestMap);
getResTests(roundEnv, viewTestMap);
Set strings = viewTestMap.keys().elementSet();
String[] keys = strings.toArray(new String[strings.size()]);
for (String key : keys) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, key);
createTest(key, viewTestMap.get(key));
}
}

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

idxConstraintRangePairs.asMap().forEach((key, value) -> executor.submit(() -> {
long cardinality = getColumnCardinality(schema, table, auths, key.getFamily(), key.getQualifier(), value);
LOG.debug("Cardinality for column %s is %s", key.getName(), cardinality);
ListMultimap cardinalityToCOnstraints= MultimapBuilder.treeKeys().arrayListValues().build();
try {
boolean earlyReturn = false;
int numTasks = idxConstraintRangePairs.asMap().entrySet().size();
do {

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

public void testFlatteningToMultimap() {
Collector> collector =
Multimaps.flatteningToMultimap(
str -> str.charAt(0),
str -> str.substring(1).chars().mapToObj(c -> (char) c),
MultimapBuilder.linkedHashKeys().arrayListValues()::build);
BiPredicate, Multimap> equivalence =
Equivalence.equals()
.onResultOf((Multimap mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
.and(Equivalence.equals());
ListMultimap empty =
MultimapBuilder.linkedHashKeys().arrayListValues().build();
ListMultimap filled =
MultimapBuilder.linkedHashKeys().arrayListValues().build();
filled.putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'));
filled.putAll('a', Arrays.asList('p', 'p', 'l', 'e'));
filled.putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'));
filled.putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'));
filled.putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'));
CollectorTester.of(collector, equivalence)
.expectCollects(empty)
.expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry");
}

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

synchronized void updateCache() {
Multimap newClassNameLocatiOns= HashMultimap.create();
for (ClassLoader loader : getKnownClassLoaders()) {
updateCache(loader, newClassNameLocations);
}
updateCacheWithClasspathClasses(newClassNameLocations);
updateCacheWithBootstrapClasses(newClassNameLocations);
if (!newClassNameLocations.isEmpty()) {
// multimap that sorts keys and de-dups values while maintains value ordering
SetMultimap newMap =
MultimapBuilder.treeKeys().linkedHashSetValues().build();
newMap.putAll(classNameLocations);
newMap.putAll(newClassNameLocations);
classNameLocatiOns= ImmutableMultimap.copyOf(newMap);
}
}

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

/** Uses a hash table to map keys to value collections. */
public static MultimapBuilderWithKeys hashKeys() {
return hashKeys(DEFAULT_EXPECTED_KEYS);
}

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

@GwtIncompatible // serialization
public void testSerialization() throws Exception {
for (MultimapBuilderWithKeys builderWithKeys :
ImmutableList.of(
MultimapBuilder.hashKeys(),
MultimapBuilder.linkedHashKeys(),
MultimapBuilder.treeKeys(),
MultimapBuilder.enumKeys(RoundingMode.class))) {
for (MultimapBuilder builder :
ImmutableList.of(
builderWithKeys.arrayListValues(),
builderWithKeys.linkedListValues(),
builderWithKeys.hashSetValues(),
builderWithKeys.linkedHashSetValues(),
builderWithKeys.treeSetValues(),
builderWithKeys.enumSetValues(RoundingMode.class))) {
/*
* Temporarily inlining SerializableTester here for obscure internal reasons.
*/
reserializeAndAssert(builder.build());
}
}
}

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

/**
* Uses a hash table to map keys to value collections.
*
*

The collections returned by {@link Multimap#keySet()}, {@link Multimap#keys()}, and {@link
* Multimap#asMap()} will iterate through the keys in the order that they were first added to the
* multimap, save that if all values associated with a key are removed and then the key is added
* back into the multimap, that key will come last in the key iteration order.
*/
public static MultimapBuilderWithKeys linkedHashKeys() {
return linkedHashKeys(DEFAULT_EXPECTED_KEYS);
}

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

/**
* Uses a naturally-ordered {@link TreeMap} to map keys to value collections.
*
*

The collections returned by {@link Multimap#keySet()}, {@link Multimap#keys()}, and {@link
* Multimap#asMap()} will iterate through the keys in sorted order.
*
*

For all multimaps generated by the resulting builder, the {@link Multimap#keySet()} can be
* safely cast to a {@link java.util.SortedSet}, and the {@link Multimap#asMap()} can safely be
* cast to a {@link java.util.SortedMap}.
*/
@SuppressWarnings("rawtypes")
public static MultimapBuilderWithKeys treeKeys() {
return treeKeys(Ordering.natural());
}

代码示例来源:origin: com.atlassian.oai/swagger-request-validator-core

static Multimap multimapBuilder(final boolean caseSensitive) {
return caseSensitive ? MultimapBuilder.hashKeys().arrayListValues().build() :
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues().build();
}

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

@Override
public ListMultimap build(
Multimap multimap) {
return (ListMultimap) super.build(multimap);
}
}

代码示例来源:origin: HashEngineering/dashj

@Override
protected Multimap getStateTransitions() {
Multimap result = MultimapBuilder.enumKeys(State.class).arrayListValues().build();
result.put(State.UNINITIALISED, State.NEW);
result.put(State.UNINITIALISED, State.READY);
result.put(State.NEW, State.SAVE_STATE_IN_WALLET);
result.put(State.SAVE_STATE_IN_WALLET, State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER);
result.put(State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, State.READY);
result.put(State.READY, State.EXPIRED);
result.put(State.READY, State.CLOSED);
return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testSerializeStringKey() throws Exception {
Multimap map = MultimapBuilder.hashKeys().arrayListValues().build();
map.put("a", 1);
map.put("a", 2);
map.put("a", 3);
String json = mapper.writer().writeValueAsString(map);
assertEquals(json, "{\"a\":[1,2,3]}");
}

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

/** Uses a hash table to map keys to value collections. */
public static MultimapBuilderWithKeys hashKeys() {
return hashKeys(DEFAULT_EXPECTED_KEYS);
}

推荐阅读
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • ImmutableX Poised to Pioneer Web3 Gaming Revolution
    ImmutableX is set to spearhead the evolution of Web3 gaming, with its innovative technologies and strategic partnerships driving significant advancements in the industry. ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 深入解析Spring Cloud Ribbon负载均衡机制
    本文详细介绍了Spring Cloud中的Ribbon组件如何实现服务调用的负载均衡。通过分析其工作原理、源码结构及配置方式,帮助读者理解Ribbon在分布式系统中的重要作用。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • golang常用库:配置文件解析库/管理工具viper使用
    golang常用库:配置文件解析库管理工具-viper使用-一、viper简介viper配置管理解析库,是由大神SteveFrancia开发,他在google领导着golang的 ... [详细]
  • 优化ASM字节码操作:简化类转换与移除冗余指令
    本文探讨如何利用ASM框架进行字节码操作,以优化现有类的转换过程,简化复杂的转换逻辑,并移除不必要的加0操作。通过这些技术手段,可以显著提升代码性能和可维护性。 ... [详细]
  • 本文介绍了如何使用 Spring Boot DevTools 实现应用程序在开发过程中自动重启。这一特性显著提高了开发效率,特别是在集成开发环境(IDE)中工作时,能够提供快速的反馈循环。默认情况下,DevTools 会监控类路径上的文件变化,并根据需要触发应用重启。 ... [详细]
  • 本文介绍了Java并发库中的阻塞队列(BlockingQueue)及其典型应用场景。通过具体实例,展示了如何利用LinkedBlockingQueue实现线程间高效、安全的数据传递,并结合线程池和原子类优化性能。 ... [详细]
  • 数据库内核开发入门 | 搭建研发环境的初步指南
    本课程将带你从零开始,逐步掌握数据库内核开发的基础知识和实践技能,重点介绍如何搭建OceanBase的开发环境。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
author-avatar
暗恋具体哦
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有