本文整理汇总了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);
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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;
}
示例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]"));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例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;
}
示例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;
}