本文整理了Java中com.google.common.collect.Maps.immutableEnumMap()
方法的一些代码示例,展示了Maps.immutableEnumMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.immutableEnumMap()
方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:immutableEnumMap
[英]Returns an immutable map instance containing the given entries. Internally, the returned map will be backed by an EnumMap.
The iteration order of the returned map follows the enum's iteration order, not the order in which the elements appear in the given map.
[中]返回包含给定项的不可变映射实例。在内部,返回的映射将由EnumMap支持。
返回映射的迭代顺序遵循枚举的迭代顺序,而不是元素在给定映射中出现的顺序。
代码示例来源:origin: google/guava
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
Map<AnEnum, String> map = Maps.newHashMap();
for (Entry<AnEnum, String> entry : entries) {
// checkArgument(!map.containsKey(entry.getKey()));
map.put(entry.getKey(), entry.getValue());
}
return Maps.immutableEnumMap(map);
}
}
代码示例来源:origin: google/guava
public static <K extends Enum<K>, V> ImmutableEnumMap<?, ?> instantiate(
SerializationStreamReader reader) throws SerializationException {
Map<K, V> deserialized = Maps.newHashMap();
Map_CustomFieldSerializerBase.deserialize(reader, deserialized);
/*
* It is safe to cast to ImmutableEnumSet because in order for it to be
* serialized as an ImmutableEnumSet, it must be non-empty to start
* with.
*/
return (ImmutableEnumMap<?, ?>) Maps.immutableEnumMap(deserialized);
}
代码示例来源:origin: google/guava
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
Map<AnEnum, String> map = Maps.newHashMap();
for (Entry<AnEnum, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return Maps.immutableEnumMap(map);
}
}
代码示例来源:origin: google/guava
public void testEmptyImmutableEnumMap() {
ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(ImmutableMap.<AnEnum, String>of());
assertEquals(ImmutableMap.of(), map);
}
代码示例来源:origin: google/guava
public void testIteratesOnce() {
Map<AnEnum, AnEnum> map =
Maps.asMap(
ImmutableSet.of(AnEnum.A),
new Function<AnEnum, AnEnum>() {
boolean used = false;
@Override
public AnEnum apply(AnEnum ae) {
checkState(!used, "should not be applied more than once");
used = true;
return ae;
}
});
ImmutableMap<AnEnum, AnEnum> copy = Maps.immutableEnumMap(map);
assertThat(copy.entrySet()).containsExactly(Helpers.mapEntry(AnEnum.A, AnEnum.A));
}
代码示例来源:origin: google/guava
public void testImmutableEnumMapOrdering() {
ImmutableMap<AnEnum, String> map =
Maps.immutableEnumMap(ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));
assertThat(map.entrySet())
.containsExactly(
Helpers.mapEntry(AnEnum.A, "a"),
Helpers.mapEntry(AnEnum.C, "c"),
Helpers.mapEntry(AnEnum.E, "e"))
.inOrder();
}
代码示例来源:origin: org.gradle/gradle-model-core
public ModelProperty(ModelType<T> type, String name, Set<ModelType<?>> declaredBy,
Map<PropertyAccessorType, WeaklyTypeReferencingMethod<?, ?>> accessors) {
this.name = name;
this.type = type;
this.declaredBy = ImmutableSet.copyOf(declaredBy);
this.accessors = Maps.immutableEnumMap(accessors);
}
代码示例来源:origin: com.google.cloud.bigdataoss/gcs-connector
protected ImmutableMap<Counter, AtomicLong> createCounterMap() {
EnumMap<Counter, AtomicLong> countersMap = new EnumMap<>(Counter.class);
for (Counter counter : ALL_COUNTERS) {
countersMap.put(counter, new AtomicLong());
}
return Maps.immutableEnumMap(countersMap);
}
代码示例来源:origin: com.google.guava/guava-testlib
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
Map<AnEnum, String> map = Maps.newHashMap();
for (Entry<AnEnum, String> entry : entries) {
// checkArgument(!map.containsKey(entry.getKey()));
map.put(entry.getKey(), entry.getValue());
}
return Maps.immutableEnumMap(map);
}
}
代码示例来源:origin: com.google.guava/guava-testlib-jdk5
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
Map<AnEnum, String> map = Maps.newHashMap();
for (Entry<AnEnum, String> entry : entries) {
// checkArgument(!map.containsKey(entry.getKey()));
map.put(entry.getKey(), entry.getValue());
}
return Maps.immutableEnumMap(map);
}
}
代码示例来源:origin: com.google.guava/guava-gwt
public static <K extends Enum<K>, V> ImmutableEnumMap<?, ?> instantiate(
SerializationStreamReader reader) throws SerializationException {
Map<K, V> deserialized = Maps.newHashMap();
Map_CustomFieldSerializerBase.deserialize(reader, deserialized);
/*
* It is safe to cast to ImmutableEnumSet because in order for it to be
* serialized as an ImmutableEnumSet, it must be non-empty to start
* with.
*/
return (ImmutableEnumMap<?, ?>) Maps.immutableEnumMap(deserialized);
}
代码示例来源:origin: com.walmartlabs.concord.server/concord-server
/**
* Copy the current immutable object by replacing the {@link ProcessAnsibleResource.AnsibleStatsEntry#stats() stats} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the stats map
* @return A modified copy of {@code this} object
*/
public final ImmutableAnsibleStatsEntry withStats(Map<ProcessAnsibleResource.AnsibleHostStatus, ? extends Integer> entries) {
if (this.stats == entries) return this;
ImmutableMap<ProcessAnsibleResource.AnsibleHostStatus, Integer> newValue = Maps.immutableEnumMap(entries);
return new ImmutableAnsibleStatsEntry(this.uniqueHosts, newValue, this.hostGroups);
}
代码示例来源:origin: exomiser/Exomiser
private InheritanceModeOptions(Map<SubModeOfInheritance, Float> values) {
this.subMoiMaxFreqs = Maps.immutableEnumMap(values);
this.subMoiMaxFreqs.forEach(InheritanceModeOptions::checkBounds);
this.moiMaxFreqs = createInheritanceModeMaxFreqs(subMoiMaxFreqs);
this.maxFreq = moiMaxFreqs.values().stream().max(Comparator.naturalOrder()).orElse(Float.MAX_VALUE);
}
代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
IBakedModel coreModel = new ItemLayerModel(ImmutableList.copyOf(locations)).bake(state, format, bakedTextureGetter);
builder.addAll(coreModel.getQuads(null, null, 0));
TextureAtlasSprite someTexture = bakedTextureGetter.apply(locations.get(0));
return new SteamExosuitItemBakedModel(this, builder.build(), someTexture, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap());
}
}
代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
IBakedModel coreModel = new ItemLayerModel(ImmutableList.copyOf(locations)).bake(state, format, bakedTextureGetter);
builder.addAll(coreModel.getQuads(null, null, 0));
TextureAtlasSprite someTexture = bakedTextureGetter.apply(locations.get(0));
return new LeatherExosuitItemBakedModel(this, builder.build(), someTexture, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap());
}
}
代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
IBakedModel coreModel = new ItemLayerModel(ImmutableList.of(core, head)).bake(state, format, bakedTextureGetter);
builder.addAll(coreModel.getQuads(null, null, 0));
TextureAtlasSprite headTexture = bakedTextureGetter.apply(head);
return new SteamToolBakedModel(this, builder.build(), headTexture, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap());
}
代码示例来源:origin: com.google.guava/guava-tests
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
Map<AnEnum, String> map = Maps.newHashMap();
for (Entry<AnEnum, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return Maps.immutableEnumMap(map);
}
}
代码示例来源:origin: RS485/LogisticsPipes
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
IBakedModel model = (new ItemLayerModel(ImmutableList.of(EMPTY))).bake(state, format, bakedTextureGetter);
builder.addAll(model.getQuads(null, null, 0));
TextureAtlasSprite particleSprite = model.getParticleTexture();
return new BakedItemModel(builder.build(), particleSprite, Maps.immutableEnumMap(transformMap), new FluidContainerItemOverrideList(state, format, transformMap, bakedTextureGetter));
}
代码示例来源:origin: com.google.guava/guava-tests
public void testIteratesOnce() {
Map<AnEnum, AnEnum> map = Maps.asMap(ImmutableSet.of(AnEnum.A), new Function<AnEnum, AnEnum>() {
boolean used = false;
@Override public AnEnum apply(AnEnum ae) {
checkState(!used, "should not be applied more than once");
used = true;
return ae;
}
});
ImmutableMap<AnEnum, AnEnum> copy = Maps.immutableEnumMap(map);
assertThat(copy.entrySet()).containsExactly(Helpers.mapEntry(AnEnum.A, AnEnum.A));
}
代码示例来源:origin: com.google.guava/guava-tests
public void testImmutableEnumMapOrdering() {
ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(
ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));
assertThat(map.entrySet()).containsExactly(
Helpers.mapEntry(AnEnum.A, "a"),
Helpers.mapEntry(AnEnum.C, "c"),
Helpers.mapEntry(AnEnum.E, "e")).inOrder();
}
内容来源于网络,如有侵权,请联系作者删除!