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


Java BiMap.put方法代碼示例

本文整理匯總了Java中com.google.common.collect.BiMap.put方法的典型用法代碼示例。如果您正苦於以下問題:Java BiMap.put方法的具體用法?Java BiMap.put怎麽用?Java BiMap.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.BiMap的用法示例。


在下文中一共展示了BiMap.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configureResourceSetContainerState

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
private void configureResourceSetContainerState(final List<N4JSProject> allProjects) {
	// a container is a project.
	List<String> containers = new LinkedList<>();
	BiMap<String, N4JSProject> container2project = HashBiMap.create();

	// the URIs of all resources directly contained in a project/container.
	Multimap<String, URI> container2Uris = HashMultimap.create();

	for (N4JSProject project : allProjects) {
		String container = FileBasedWorkspace.N4FBPRJ + project.getLocation();
		container2project.put(container, project);
		containers.add(container);

		for (IN4JSSourceContainer sourceContainer : project.getSourceContainers()) {
			Iterables.addAll(container2Uris.get(container), sourceContainer);
		}
	}

	// Define the Mapping of Resources (URIs to Container === Projects),
	rsbAcs.configure(containers, container2Uris);
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:22,代碼來源:N4HeadlessCompiler.java

示例2: fixOids

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
private void fixOids(IdEObject idEObject, OidProvider oidProvider, BiMap<Long, IdEObject> temp) {
	if (idEObject == null) {
		return;
	}
	if (temp.containsValue(idEObject)) {
		return;
	}
	((IdEObjectImpl) idEObject).setOid(oidProvider.newOid(idEObject.eClass()));
	if (objects.containsValue(idEObject)) {
		temp.put(idEObject.getOid(), idEObject);
	}
	for (EReference eReference : idEObject.eClass().getEAllReferences()) {
		Object val = idEObject.eGet(eReference);
		if (eReference.isMany()) {
			List list = (List) val;
			for (Object o : list) {
				fixOids((IdEObject) o, oidProvider, temp);
			}
		} else {
			fixOids((IdEObject) val, oidProvider, temp);
		}
	}
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:25,代碼來源:IfcModel.java

示例3: lookupFluidForBlock

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
public static Fluid lookupFluidForBlock(Block block)
{
    if (fluidBlocks == null)
    {
        BiMap<Block, Fluid> tmp = HashBiMap.create();
        for (Fluid fluid : fluids.values())
        {
            if (fluid.canBePlacedInWorld() && fluid.getBlock() != null)
            {
                tmp.put(fluid.getBlock(), fluid);
            }
        }
        fluidBlocks = tmp;
    }
    return fluidBlocks.get(block);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:17,代碼來源:FluidRegistry.java

示例4: modifyTypes

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
/** Applies the supplied modifications to the GraphQLTypes. */
private static BiMap<String, GraphQLType> modifyTypes(
    BiMap<String, GraphQLType> mapping,
    ImmutableListMultimap<String, TypeModification> modifications) {
  BiMap<String, GraphQLType> result = HashBiMap.create(mapping.size());
  for (String key : mapping.keySet()) {
    if (mapping.get(key) instanceof GraphQLObjectType) {
      GraphQLObjectType val = (GraphQLObjectType) mapping.get(key);
      if (modifications.containsKey(key)) {
        for (TypeModification modification : modifications.get(key)) {
          val = modification.apply(val);
        }
      }
      result.put(key, val);
    } else {
      result.put(key, mapping.get(key));
    }
  }
  return result;
}
 
開發者ID:google,項目名稱:rejoiner,代碼行數:21,代碼來源:ProtoRegistry.java

示例5: loadStringToStringBiMap

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
public static BiMap<String, String> loadStringToStringBiMap(String file, int from, int to) throws IOException {

    BiMap<String, String> res = HashBiMap.create();
    BufferedReader reader = IOUtils.getBufferedFileReader(file);
    String line;
    while ((line = reader.readLine()) != null) {
      String[] tokens = line.split("\t");
      if (res.containsKey(tokens[from]))
        throw new RuntimeException("Map already contains key: " + tokens[from]);
      if (res.inverse().containsKey(tokens[to]))
        throw new RuntimeException("Map already contains value: " + tokens[to]);
      res.put(tokens[from], tokens[to]);
    }
    reader.close();
    return res;
  }
 
開發者ID:cgraywang,項目名稱:TextHIN,代碼行數:17,代碼來源:FileUtils.java

示例6: testTypeMap

import com.google.common.collect.BiMap; //導入方法依賴的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

示例7: testConflictInsertKV

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
/**
 * BiMap存儲數據時出現衝突
 * 存儲時,如果key相同,則會覆蓋,則逆轉後不會有問題
 * 存儲時,如果key不同,value有相同,則逆轉時會拋出異常IllegalArgumentException
 */
@Test
public void testConflictInsertKV() {
    // 存儲相同key數據,此時會覆蓋k1=v1
    BiMap<String, String> biMap1 = HashBiMap.create();
    biMap1.put("k1", "v1");
    biMap1.put("k1", "v2");
    System.out.println("biMap1: " + biMap1);

    // 獲取的隻有 v2=k1
    BiMap<String, String> inverseBiMap1 = biMap1.inverse();
    System.out.println("inverseBiMap1: " + inverseBiMap1);

    System.out.println("--------------------------------------");

    // 存儲相同的value數據
    BiMap<String, String> biMap2 = HashBiMap.create();
    biMap2.put("k1", "v1");

    // 此時拋出異常 java.lang.IllegalArgumentException: value already present: v1
    biMap2.put("k2", "v1");
    System.out.println("biMap2: " + biMap2);

    BiMap<String, String> inverseBiMap2 = biMap2.inverse();
    System.out.println("inverseBiMap2: " + inverseBiMap2);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:31,代碼來源:HashBiMapDemo.java

示例8: testFixedConflict

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
/**
 * value如果有衝突時會拋異常,此時可以選擇強製覆蓋, forcePut
 */
@Test
public void testFixedConflict() {
    BiMap<String, String> biMap = HashBiMap.create();
    biMap.put("k1", "v1");

    // 此時會強製覆蓋,連原來的k1=v1都不存在
    biMap.forcePut("k2", "v1");

    // biMap: {k2=v1}
    System.out.println("biMap2: " + biMap);

    BiMap<String, String> inverseBiMap = biMap.inverse();

    // inverseBiMap: {v1=k2}
    System.out.println("inverseBiMap: " + inverseBiMap);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:20,代碼來源:HashBiMapDemo.java

示例9: testKeyValueCheck

import com.google.common.collect.BiMap; //導入方法依賴的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

示例10: testUpdateBiMapDate

import com.google.common.collect.BiMap; //導入方法依賴的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

示例11: mapDistinctValues

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
private static <T> BiMap<T,Integer> mapDistinctValues(Collection<T> distinct) {
  BiMap<T,Integer> mapping = HashBiMap.create(distinct.size());
  int encoding = 0;
  for (T t : distinct) {
    mapping.put(t, encoding);
    encoding++;
  }
  return mapping;
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:10,代碼來源:CategoricalValueEncodings.java

示例12: checkDoubleOidsPlusReferences

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
private void checkDoubleOidsPlusReferences(BiMap<IdEObject, Long> done, IdEObject idEObject) {
	if (idEObject == null) {
		return;
	}
	if (idEObject.eClass().getEAnnotation("wrapped") != null) {
		return;
	}
	if (done.containsKey(idEObject)) {
		return;
	}
	if (done.containsValue(idEObject.getOid())) {
		showBackReferences(idEObject);
		IdEObject existing = done.inverse().get(idEObject.getOid());
		showBackReferences(existing);
		throw new RuntimeException("Double oid: " + idEObject.getOid() + " " + idEObject + ", " + existing);
	}
	done.put(idEObject, idEObject.getOid());
	for (EReference eReference : idEObject.eClass().getEAllReferences()) {
		if (eReference.isMany()) {
			List list = (List) idEObject.eGet(eReference);
			for (Object o : list) {
				checkDoubleOidsPlusReferences(done, (IdEObject) o);
			}
		} else {
			checkDoubleOidsPlusReferences(done, (IdEObject) idEObject.eGet(eReference));
		}
	}
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:30,代碼來源:IfcModel.java

示例13: loadProperties

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
public static BiMap<Short, String> loadProperties(String propertyFileName) throws IOException {

    BiMap<Short, String> res = HashBiMap.create();
    BufferedReader reader = IOUtils.getBufferedFileReader(propertyFileName);

    String line;
    short id = 1;
    while ((line = reader.readLine()) != null) {
      res.put(id++, line);
    }
    return res;
  }
 
開發者ID:cgraywang,項目名稱:TextHIN,代碼行數:13,代碼來源:FreebaseUtils.java

示例14: loadString2IntegerBiMap

import com.google.common.collect.BiMap; //導入方法依賴的package包/類
public static BiMap<String, Integer> loadString2IntegerBiMap(String file, String delimiter) throws IOException {

    BiMap<String, Integer> res = HashBiMap.create();
    BufferedReader reader = IOUtils.getBufferedFileReader(file);
    String line;
    while ((line = reader.readLine()) != null) {

      String[] tokens = line.split(delimiter);
      res.put(tokens[0], Integer.parseInt(tokens[1]));

    }
    reader.close();
    return res;
  }
 
開發者ID:cgraywang,項目名稱:TextHIN,代碼行數:15,代碼來源:FileUtils.java

示例15: loadIntegerToIntegerBiMap

import com.google.common.collect.BiMap; //導入方法依賴的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


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