當前位置: 首頁>>代碼示例>>Java>>正文


Java HashBiMap.create方法代碼示例

本文整理匯總了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]"));
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:26,代碼來源:XMLDataConverterTest.java

示例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);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:21,代碼來源:HashBiMapDemo.java

示例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);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:23,代碼來源:GameData.java

示例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);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:31,代碼來源:HashBiMapDemo.java

示例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);
}
 
開發者ID:ExoMagica,項目名稱:ExoMagica,代碼行數:19,代碼來源:RitualHandler.java

示例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;
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:25,代碼來源:DefaultValidationNotificationService.java

示例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);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:11,代碼來源:DexBuilder.java

示例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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:13,代碼來源:ShellBasedIdMapping.java

示例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"));
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:41,代碼來源:TestShellBasedIdMapping.java

示例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;
  }
 
開發者ID:cgraywang,項目名稱:TextHIN,代碼行數:15,代碼來源:FileUtils.java

示例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);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:32,代碼來源:HashBiMapDemo.java

示例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;
}
 
開發者ID:google,項目名稱:rejoiner,代碼行數:9,代碼來源:ProtoRegistry.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:10,代碼來源:WorkflowNode.java

示例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;
}
 
開發者ID:google,項目名稱:rejoiner,代碼行數:8,代碼來源:GqlInputConverter.java


注:本文中的com.google.common.collect.HashBiMap.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。