本文整理汇总了Java中com.google.common.collect.HashBiMap.create方法的典型用法代码示例。如果您正苦于以下问题:Java HashBiMap.create方法的具体用法?Java HashBiMap.create怎么用?Java HashBiMap.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.HashBiMap
的用法示例。
在下文中一共展示了HashBiMap.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTypeMap
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
public void testTypeMap()
{
BiMap<String, Integer> map = HashBiMap.create();
map.put("test1", 1);
map.put("test2", 2);
map.put("test3", 3);
map.put("test4", 4);
mappings.addNodeMapping(
new ListMapping("collection", "types/type", ArrayList.class, new NodeTypeMapping("", "", map, new Integer(4))));
getBean();
assertEquals(1, bean.collection.get(0));
assertEquals(2, bean.collection.get(1));
assertEquals(3, bean.collection.get(2));
assertEquals(4, bean.collection.get(3));
getPropBagEx();
assertEquals("test1", xml.getNode("types/type[0]"));
assertEquals("test2", xml.getNode("types/type[1]"));
assertEquals("test3", xml.getNode("types/type[2]"));
assertEquals("test4", xml.getNode("types/type[3]"));
}
示例2: testKeyValueCheck
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
/**
* HashBiMap key, value 相关校验
*/
@Test
public void testKeyValueCheck() {
BiMap<String, String> biMap = HashBiMap.create();
biMap.put("k1", "v1");
// 校验 map 是否为空
boolean isBiMapEmpty = biMap.isEmpty();
System.out.println("isBiMapEmpty: " + isBiMapEmpty);
// 检查某个key是否存在
boolean isKeyExists = biMap.containsKey("k1");
System.out.println("isKeyExists: " + isKeyExists);
// 检查某个value是否存在
boolean isValueExists = biMap.containsValue("v1");
System.out.println("isValueExists: " + isValueExists);
}
示例3: onCreate
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void onCreate(Map<ResourceLocation, ?> slaveset, BiMap<ResourceLocation, ? extends IForgeRegistry<?>> registries)
{
final ClearableObjectIntIdentityMap<IBlockState> idMap = new ClearableObjectIntIdentityMap<IBlockState>()
{
@SuppressWarnings("deprecation")
@Override
public int get(IBlockState key)
{
Integer integer = (Integer)this.identityMap.get(key);
// There are some cases where this map is queried to serialize a state that is valid,
//but somehow not in this list, so attempt to get real metadata. Doing this hear saves us 7 patches
if (integer == null && key != null)
integer = this.identityMap.get(key.getBlock().getStateFromMeta(key.getBlock().getMetaFromState(key)));
return integer == null ? -1 : integer.intValue();
}
};
((Map<ResourceLocation,Object>)slaveset).put(BLOCKSTATE_TO_ID, idMap);
final HashBiMap<Block, Item> map = HashBiMap.create();
((Map<ResourceLocation,Object>)slaveset).put(BLOCK_TO_ITEM, map);
}
示例4: testUpdateBiMapDate
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
/**
* HashBiMap 修改数据
* putAll
* remove
* replace
*/
@Test
public void testUpdateBiMapDate() {
BiMap<String, String> biMap = HashBiMap.create();
biMap.put("k1", "v1");
biMap.put("k2", "v2");
// putAll , 存入另一个Map的数据,此时如果value有重复的依然会抛异常
biMap.putAll(ImmutableBiMap.of("k3", "v3", "k4", "v4", "k5", "v5", "k6", "v6"));
System.out.println("biMap putAll after: " + biMap);
System.out.println("\n-------------------------------------------\n");
// remove , 移除指定key的元素,如果key不存在,则返回null
String v2 = biMap.remove("k2");
String valueNotExists = biMap.remove("keyNotExists");
System.out.println("remove k2 then biMap= " + biMap + ", and remove the value= " + v2);
System.out.println("valueNotExists=" + valueNotExists);
System.out.println("\n-------------------------------------------\n");
// 清空map里的数据
biMap.clear();
System.out.println("clean biMap=" + biMap);
}
示例5: registerRitual
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
public static void registerRitual(IRitual ritual, String name) {
if(Strings.isNullOrEmpty(name)) {
throw new IllegalArgumentException("Attempted to register a ritual with no name: " + ritual);
}
if(ritual == null) {
throw new NullPointerException("The ritual cannot be null");
}
ModContainer mod = Loader.instance().activeModContainer();
if(mod == null) {
name = "minecraft:" + name;
} else {
name = mod.getModId() + ":" + name;
}
HashBiMap<String, IRitualRecipe> recipes = HashBiMap.create();
NAMED_RITUALS.put(name, ritual);
RITUALS_RECIPES.put(ritual, recipes);
}
示例6: groupRecipientsForMessagePairs
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
private static Map<Set<User>, SortedSet<MessagePair>> groupRecipientsForMessagePairs(
Map<User, SortedSet<MessagePair>> messagePairsPerUser )
{
BiMap<Set<User>, SortedSet<MessagePair>> grouped = HashBiMap.create();
for ( Map.Entry<User, SortedSet<MessagePair>> entry : messagePairsPerUser.entrySet() )
{
User user = entry.getKey();
SortedSet<MessagePair> setOfPairs = entry.getValue();
if ( grouped.containsValue( setOfPairs ) )
{
// Value exists -> Add user to the existing key set
grouped.inverse().get( setOfPairs ).add( user );
}
else
{
// Value doesn't exist -> Add the [user, set] as a new entry
grouped.put( Sets.newHashSet( user ), setOfPairs );
}
}
return grouped;
}
示例7: computeTryInfo
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
private TryInfo computeTryInfo() {
// Canonical map of handlers.
BiMap<CatchHandlers<BasicBlock>, Integer> canonicalHandlers = HashBiMap.create();
// Compute the list of try items and their handlers.
List<TryItem> tryItems = computeTryItems(canonicalHandlers);
// Compute handler sets before dex items which depend on the handler index.
Try[] tries = getDexTryItems(tryItems, canonicalHandlers);
TryHandler[] handlers = getDexTryHandlers(canonicalHandlers.inverse());
return new TryInfo(tries, handlers);
}
示例8: loadFullUserMap
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
synchronized private void loadFullUserMap() throws IOException {
BiMap<Integer, String> uMap = HashBiMap.create();
if (OS.startsWith("Mac")) {
updateMapInternal(uMap, "user", MAC_GET_ALL_USERS_CMD, "\\s+",
staticMapping.uidMapping);
} else {
updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
staticMapping.uidMapping);
}
uidNameMap = uMap;
lastUpdateTime = Time.monotonicNow();
}
示例9: testStaticMapping
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
@Test
public void testStaticMapping() throws IOException {
assumeTrue(!Shell.WINDOWS);
Map<Integer, Integer> uidStaticMap = new PassThroughMap<Integer>();
Map<Integer, Integer> gidStaticMap = new PassThroughMap<Integer>();
uidStaticMap.put(11501, 10);
gidStaticMap.put(497, 200);
// Maps for id to name map
BiMap<Integer, String> uMap = HashBiMap.create();
BiMap<Integer, String> gMap = HashBiMap.create();
String GET_ALL_USERS_CMD =
"echo \"atm:x:1000:1000:Aaron T. Myers,,,:/home/atm:/bin/bash\n"
+ "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\""
+ " | cut -d: -f1,3";
String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
+ "mapred:x:497\n"
+ "mapred2:x:498\""
+ " | cut -d: -f1,3";
ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
uidStaticMap);
ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
gidStaticMap);
assertEquals("hdfs", uMap.get(10));
assertEquals(10, (int)uMap.inverse().get("hdfs"));
assertEquals("atm", uMap.get(1000));
assertEquals(1000, (int)uMap.inverse().get("atm"));
assertEquals("hdfs", gMap.get(11501));
assertEquals(11501, (int)gMap.inverse().get("hdfs"));
assertEquals("mapred", gMap.get(200));
assertEquals(200, (int)gMap.inverse().get("mapred"));
assertEquals("mapred2", gMap.get(498));
assertEquals(498, (int)gMap.inverse().get("mapred2"));
}
示例10: loadIntegerToIntegerBiMap
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
public static BiMap<Integer, Integer> loadIntegerToIntegerBiMap(String file) throws IOException {
BiMap<Integer, Integer> res = HashBiMap.create();
BufferedReader reader = IOUtils.getBufferedFileReader(file);
String line;
while ((line = reader.readLine()) != null) {
String[] tokens = line.split("\t");
res.put(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1]));
}
reader.close();
return res;
}
示例11: testInverseDate
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
/**
* inverse() BiMap的核心功能inverse,inverse后返回新的BiMap,此时key-value做了翻转
* inverse() 不改变原来BiMap,而是新生成一个
* 此时k,v 的存储没有相同的数据冲突
*/
@Test
public void testInverseDate() {
BiMap<String, String> biMap = HashBiMap.create();
biMap.put("1233", "haoc");
biMap.put("1244", "jim");
biMap.put("1255", "jack");
// k->v
String v1 = biMap.get("1233");
String v2 = biMap.get("1244");
String v3 = biMap.get("1255");
System.out.println(v1);
System.out.println(v2);
System.out.println(v3);
// 做键值翻转
BiMap<String, String> inverseBiMap = biMap.inverse();
// v->k
String k1 = inverseBiMap.get("haoc");
String k2 = inverseBiMap.get("jim");
String k3 = inverseBiMap.get("jack");
System.out.println(k1);
System.out.println(k2);
System.out.println(k3);
}
示例12: getEnumMap
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
private static BiMap<String, GraphQLType> getEnumMap(Iterable<EnumDescriptor> descriptors) {
HashBiMap<String, GraphQLType> mapping = HashBiMap.create();
for (EnumDescriptor enumDescriptor : descriptors) {
mapping.put(
ProtoToGql.getReferenceName(enumDescriptor), ProtoToGql.convert(enumDescriptor));
}
return mapping;
}
示例13: chain
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
public static <X, Y> BiMap<X, X> chain(Map<X, Y> src, Map<? super Y, X> map) {
BiMap<X, X> result = HashBiMap.create();
for(Entry<X, Y> e : src.entrySet()) {
X k = e.getKey();
Y l = e.getValue();
X m = map.get(l);
if(m != null) {
//System.out.println("Put: " + k + " -> " + m);
result.put(k, m);
}
}
return result;
}
开发者ID:SmartDataAnalytics,项目名称:SubgraphIsomorphismIndex,代码行数:14,代码来源:SubgraphIsomorphismIndexImpl.java
示例14: getTypeMap
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
public static BiMap<String, Integer> getTypeMap()
{
BiMap<String, Integer> typeMap = HashBiMap.create();
typeMap.put(ITEM_NODE_TYPE, ITEM_TYPE);
typeMap.put(PARALLEL_NODE_TYPE, PARALLEL_TYPE);
typeMap.put(SERIAL_NODE_TYPE, SERIAL_TYPE);
typeMap.put(DECISION_NODE_TYPE, DECISION_TYPE);
return typeMap;
}
示例15: getEnumMap
import com.google.common.collect.HashBiMap; //导入方法依赖的package包/类
private static BiMap<String, EnumDescriptor> getEnumMap(Iterable<EnumDescriptor> descriptors) {
HashBiMap<String, EnumDescriptor> mapping = HashBiMap.create();
for (EnumDescriptor enumDescriptor : descriptors) {
mapping.put(ProtoToGql.getReferenceName(enumDescriptor), enumDescriptor);
}
return mapping;
}