本文整理了Java中com.google.common.collect.Maps.newEnumMap()
方法的一些代码示例,展示了Maps.newEnumMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.newEnumMap()
方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:newEnumMap
[英]Creates an EnumMap instance.
[中]创建一个EnumMap实例。
代码示例来源:origin: google/guava
public void testEnumMapWithInitialEnumMap() {
EnumMap<SomeEnum, Integer> original = Maps.newEnumMap(SomeEnum.class);
original.put(SomeEnum.SOME_INSTANCE, 0);
EnumMap<SomeEnum, Integer> copy = Maps.newEnumMap(original);
assertEquals(original, copy);
}
代码示例来源:origin: MovingBlocks/Terasology
public BlockAppearance() {
blockParts = Maps.newEnumMap(BlockPart.class);
textureAtlasPos = Maps.newEnumMap(BlockPart.class);
for (BlockPart part : BlockPart.values()) {
textureAtlasPos.put(part, new Vector2f());
}
}
代码示例来源:origin: MovingBlocks/Terasology
public SectionDefinitionData() {
colorSources = Maps.newEnumMap(BlockPart.class);
colorOffsets = Maps.newEnumMap(BlockPart.class);
for (BlockPart part : BlockPart.values()) {
colorSources.put(part, DefaultColorSource.DEFAULT);
colorOffsets.put(part, new Vector4f(1, 1, 1, 1));
}
}
代码示例来源:origin: google/guava
/**
* For a given Enum type, creates an immutable map from each of the Enum's values to a
* corresponding LockGraphNode, with the {@code allowedPriorLocks} and {@code
* disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the
* associated Enum values.
*/
@VisibleForTesting
static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) {
EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz);
E[] keys = clazz.getEnumConstants();
final int numKeys = keys.length;
ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys);
// Create a LockGraphNode for each enum value.
for (E key : keys) {
LockGraphNode node = new LockGraphNode(getLockName(key));
nodes.add(node);
map.put(key, node);
}
// Pre-populate all allowedPriorLocks with nodes of smaller ordinal.
for (int i = 1; i < numKeys; i++) {
nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i));
}
// Pre-populate all disallowedPriorLocks with nodes of larger ordinal.
for (int i = 0; i < numKeys - 1; i++) {
nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys));
}
return Collections.unmodifiableMap(map);
}
代码示例来源:origin: google/guava
public void testEnumMapNullClass() {
try {
Maps.<SomeEnum, Long>newEnumMap((Class<MapsTest.SomeEnum>) null);
fail("no exception thrown");
} catch (NullPointerException expected) {
}
}
代码示例来源:origin: google/guava
public void testEnumMapWithInitialEmptyEnumMap() {
EnumMap<SomeEnum, Integer> original = Maps.newEnumMap(SomeEnum.class);
EnumMap<SomeEnum, Integer> copy = Maps.newEnumMap(original);
assertEquals(original, copy);
assertNotSame(original, copy);
}
代码示例来源:origin: google/guava
public void testEnumMapWithInitialMap() {
HashMap<SomeEnum, Integer> original = Maps.newHashMap();
original.put(SomeEnum.SOME_INSTANCE, 0);
EnumMap<SomeEnum, Integer> copy = Maps.newEnumMap(original);
assertEquals(original, copy);
}
代码示例来源:origin: google/guava
public void testEnumMapWithInitialEmptyMap() {
Map<SomeEnum, Integer> original = Maps.newHashMap();
try {
Maps.newEnumMap(original);
fail("Empty map must result in an IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
代码示例来源:origin: googleapis/google-cloud-java
static Map<DnsRpc.Option, ?> optionMap(Option... options) {
Map<DnsRpc.Option, Object> temp = Maps.newEnumMap(DnsRpc.Option.class);
for (Option option : options) {
Object prev = temp.put(option.getRpcOption(), option.getValue());
checkArgument(prev == null, "Duplicate option %s", option);
}
return ImmutableMap.copyOf(temp);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@VisibleForTesting
static Map<BigQueryRpc.Option, ?> optionMap(Option... options) {
Map<BigQueryRpc.Option, Object> optionMap = Maps.newEnumMap(BigQueryRpc.Option.class);
for (Option option : options) {
Object prev = optionMap.put(option.getRpcOption(), option.getValue());
checkArgument(prev == null, "Duplicate option %s", option);
}
return optionMap;
}
}
代码示例来源:origin: googleapis/google-cloud-java
private Map<TranslateRpc.Option, ?> optionMap(Option... options) {
Map<TranslateRpc.Option, Object> optionMap = Maps.newEnumMap(TranslateRpc.Option.class);
for (Option option : options) {
Object prev = optionMap.put(option.getRpcOption(), option.getValue());
checkArgument(prev == null, "Duplicate option %s", option);
}
return optionMap;
}
}
代码示例来源:origin: googleapis/google-cloud-java
static Map<SpannerRpc.Option, ?> optionMap(SessionOption... options) {
if (options.length == 0) {
return Collections.emptyMap();
}
Map<SpannerRpc.Option, Object> tmp = Maps.newEnumMap(SpannerRpc.Option.class);
for (SessionOption option : options) {
Object prev = tmp.put(option.rpcOption(), option.value());
checkArgument(prev == null, "Duplicate option %s", option.rpcOption());
}
return ImmutableMap.copyOf(tmp);
}
代码示例来源:origin: google/guava
public void testEnumMap() {
EnumMap<SomeEnum, Integer> map = Maps.newEnumMap(SomeEnum.class);
assertEquals(Collections.emptyMap(), map);
map.put(SomeEnum.SOME_INSTANCE, 0);
assertEquals(Collections.singletonMap(SomeEnum.SOME_INSTANCE, 0), map);
}
代码示例来源:origin: google/guava
@GwtIncompatible // SerializableTester
public void testNewMultimapSerialization() {
CountingSupplier<Queue<Integer>> factory = new QueueSupplier();
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory);
multimap.putAll(Color.BLUE, asList(3, 1, 4));
multimap.putAll(Color.RED, asList(2, 7, 1, 8));
SerializableTester.reserializeAndAssert(multimap);
}
代码示例来源:origin: google/guava
public void testNewMultimapValueCollectionMatchesNavigableSet() {
Supplier<TreeSet<Integer>> factory = new SortedSetSupplier();
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory);
assertTrue(multimap.get(Color.BLUE) instanceof NavigableSet);
}
代码示例来源:origin: google/guava
public void testNewMultimapValueCollectionMatchesList() {
Supplier<LinkedList<Integer>> factory = new ListSupplier();
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory);
assertTrue(multimap.get(Color.BLUE) instanceof List);
}
代码示例来源:origin: google/guava
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory);
try {
代码示例来源:origin: google/guava
public void testNewMultimap() {
// The ubiquitous EnumArrayBlockingQueueMultimap
CountingSupplier<Queue<Integer>> factory = new QueueSupplier();
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory);
assertEquals(0, factory.count);
multimap.putAll(Color.BLUE, asList(3, 1, 4));
assertEquals(1, factory.count);
multimap.putAll(Color.RED, asList(2, 7, 1, 8));
assertEquals(2, factory.count);
assertEquals("[3, 1, 4]", multimap.get(Color.BLUE).toString());
Multimap<Color, Integer> ummodifiable = Multimaps.unmodifiableMultimap(multimap);
assertEquals("[3, 1, 4]", ummodifiable.get(Color.BLUE).toString());
Collection<Integer> collection = multimap.get(Color.BLUE);
assertEquals(collection, collection);
assertFalse(multimap.keySet() instanceof SortedSet);
assertFalse(multimap.asMap() instanceof SortedMap);
}
代码示例来源:origin: google/guava
@GwtIncompatible // SerializableTester
public void testNewSortedSetMultimapSerialization() {
CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier();
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory);
multimap.putAll(Color.BLUE, asList(3, 1, 4));
multimap.putAll(Color.RED, asList(2, 7, 1, 8));
SerializableTester.reserializeAndAssert(multimap);
assertEquals(INT_COMPARATOR, multimap.valueComparator());
}
代码示例来源:origin: google/guava
public void testNewSortedSetMultimap() {
CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier();
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);
SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory);
// newSortedSetMultimap calls the factory once to determine the comparator.
assertEquals(1, factory.count);
multimap.putAll(Color.BLUE, asList(3, 1, 4));
assertEquals(2, factory.count);
multimap.putAll(Color.RED, asList(2, 7, 1, 8));
assertEquals(3, factory.count);
assertEquals("[4, 3, 1]", multimap.get(Color.BLUE).toString());
assertEquals(INT_COMPARATOR, multimap.valueComparator());
}
内容来源于网络,如有侵权,请联系作者删除!