热门标签 | 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);
}

推荐阅读
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社区 版权所有