本文整理汇总了Java中com.google.common.collect.ImmutableBiMap.Builder类的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Builder类属于com.google.common.collect.ImmutableBiMap包,在下文中一共展示了Builder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuilderPutAll
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutAll() {
Map<String, Integer> toPut = new LinkedHashMap<String, Integer>();
toPut.put("one", 1);
toPut.put("two", 2);
toPut.put("three", 3);
Map<String, Integer> moreToPut = new LinkedHashMap<String, Integer>();
moreToPut.put("four", 4);
moreToPut.put("five", 5);
ImmutableBiMap<String, Integer> map = new Builder<String, Integer>()
.putAll(toPut)
.putAll(moreToPut)
.build();
assertMapEquals(map,
"one", 1, "two", 2, "three", 3, "four", 4, "five", 5);
assertMapEquals(map.inverse(),
1, "one", 2, "two", 3, "three", 4, "four", 5, "five");
}
示例2: testBuilderReuse
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderReuse() {
Builder<String, Integer> builder = new Builder<String, Integer>();
ImmutableBiMap<String, Integer> mapOne = builder
.put("one", 1)
.put("two", 2)
.build();
ImmutableBiMap<String, Integer> mapTwo = builder
.put("three", 3)
.put("four", 4)
.build();
assertMapEquals(mapOne, "one", 1, "two", 2);
assertMapEquals(mapOne.inverse(), 1, "one", 2, "two");
assertMapEquals(mapTwo, "one", 1, "two", 2, "three", 3, "four", 4);
assertMapEquals(mapTwo.inverse(),
1, "one", 2, "two", 3, "three", 4, "four");
}
示例3: testDuplicateValues
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testDuplicateValues() {
ImmutableMap<String, Integer> map
= new ImmutableMap.Builder<String, Integer>()
.put("one", 1)
.put("two", 2)
.put("uno", 1)
.put("dos", 2)
.build();
try {
ImmutableBiMap.copyOf(map);
fail();
} catch (IllegalArgumentException expected) {
assertThat(expected.getMessage()).contains("1");
}
}
示例4: resolveShardForPath
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
Long resolveShardForPath(final YangInstanceIdentifier path) {
final String shardName = actorContext.getShardStrategyFactory().getStrategy(path).findShard(path);
Long cookie = shards.get(shardName);
if (cookie == null) {
synchronized (this) {
cookie = shards.get(shardName);
if (cookie == null) {
cookie = nextShard++;
Builder<String, Long> builder = ImmutableBiMap.builder();
builder.putAll(shards);
builder.put(shardName, cookie);
shards = builder.build();
}
}
}
return cookie;
}
示例5: testDuplicateValues
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testDuplicateValues() {
ImmutableMap<String, Integer> map
= new ImmutableMap.Builder<String, Integer>()
.put("one", 1)
.put("two", 2)
.put("uno", 1)
.put("dos", 2)
.build();
try {
ImmutableBiMap.copyOf(map);
fail();
} catch (IllegalArgumentException expected) {
assertTrue(expected.getMessage().contains("1"));
}
}
示例6: testDuplicateValues
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testDuplicateValues() {
ImmutableMap<String, Integer> map =
new ImmutableMap.Builder<String, Integer>()
.put("one", 1)
.put("two", 2)
.put("uno", 1)
.put("dos", 2)
.build();
try {
ImmutableBiMap.copyOf(map);
fail();
} catch (IllegalArgumentException expected) {
assertThat(expected.getMessage()).contains("1");
}
}
示例7: create
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
/**
* Create a prefix {@link Converter} for {@link XPathExpressionException} defined in a particular YANG
* {@link Module} .Instantiation requires establishing how a module's imports are mapped to actual modules
* and their namespaces. This information is cached and used for improved lookups.
*
* @param ctx A SchemaContext
* @param module Module in which the XPath is defined
* @return A new Converter
*/
public static @Nonnull Converter<String, QNameModule> create(final SchemaContext ctx, final Module module) {
// Always check for null ctx
requireNonNull(ctx, "Schema context may not be null");
// Use immutable map builder for detection of duplicates (which should never occur)
final Builder<String, QNameModule> b = ImmutableBiMap.builder();
b.put(module.getPrefix(), module.getQNameModule());
for (ModuleImport i : module.getImports()) {
final Optional<Module> mod = ctx.findModule(i.getModuleName(), i.getRevision());
checkArgument(mod.isPresent(), "Unsatisfied import of %s by module %s", i, module);
b.put(i.getPrefix(), mod.get().getQNameModule());
}
return Maps.asConverter(b.build());
}
示例8: testEmptyBuilder
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testEmptyBuilder() {
ImmutableBiMap<String, Integer> map
= new Builder<String, Integer>().build();
assertEquals(Collections.<String, Integer>emptyMap(), map);
assertEquals(Collections.<Integer, String>emptyMap(), map.inverse());
assertSame(ImmutableBiMap.of(), map);
}
示例9: testSingletonBuilder
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testSingletonBuilder() {
ImmutableBiMap<String, Integer> map = new Builder<String, Integer>()
.put("one", 1)
.build();
assertMapEquals(map, "one", 1);
assertMapEquals(map.inverse(), 1, "one");
}
示例10: testBuilder_orderEntriesByValueAfterExactSizeBuild
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilder_orderEntriesByValueAfterExactSizeBuild() {
ImmutableBiMap.Builder<String, Integer> builder =
new ImmutableBiMap.Builder<String, Integer>(2).put("four", 4).put("one", 1);
ImmutableMap<String, Integer> keyOrdered = builder.build();
ImmutableMap<String, Integer> valueOrdered =
builder.orderEntriesByValue(Ordering.natural()).build();
assertMapEquals(keyOrdered, "four", 4, "one", 1);
assertMapEquals(valueOrdered, "one", 1, "four", 4);
}
示例11: testBuilder_orderEntriesByValue_usedTwiceFails
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilder_orderEntriesByValue_usedTwiceFails() {
ImmutableBiMap.Builder<String, Integer> builder = new Builder<String, Integer>()
.orderEntriesByValue(Ordering.natural());
try {
builder.orderEntriesByValue(Ordering.natural());
fail("Expected IllegalStateException");
} catch (IllegalStateException expected) {}
}
示例12: testBuilderPutNullKey
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullKey() {
Builder<String, Integer> builder = new Builder<String, Integer>();
try {
builder.put(null, 1);
fail();
} catch (NullPointerException expected) {
}
}
示例13: testBuilderPutNullValue
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullValue() {
Builder<String, Integer> builder = new Builder<String, Integer>();
try {
builder.put("one", null);
fail();
} catch (NullPointerException expected) {
}
}
示例14: testBuilderPutNullKeyViaPutAll
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullKeyViaPutAll() {
Builder<String, Integer> builder = new Builder<String, Integer>();
try {
builder.putAll(Collections.<String, Integer>singletonMap(null, 1));
fail();
} catch (NullPointerException expected) {
}
}
示例15: testBuilderPutNullValueViaPutAll
import com.google.common.collect.ImmutableBiMap.Builder; //导入依赖的package包/类
public void testBuilderPutNullValueViaPutAll() {
Builder<String, Integer> builder = new Builder<String, Integer>();
try {
builder.putAll(Collections.<String, Integer>singletonMap("one", null));
fail();
} catch (NullPointerException expected) {
}
}