本文整理汇总了Java中com.google.common.collect.BiMap.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java BiMap.containsKey方法的具体用法?Java BiMap.containsKey怎么用?Java BiMap.containsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.BiMap
的用法示例。
在下文中一共展示了BiMap.containsKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: onSubstituteActivated
import com.google.common.collect.BiMap; //导入方法依赖的package包/类
@Override
public void onSubstituteActivated(Map<ResourceLocation, ?> slaveset, Block original, Block replacement, ResourceLocation name)
{
final BiMap<Block, Item> blockItemMap = (BiMap<Block, Item>)slaveset.get(BLOCK_TO_ITEM);
if (blockItemMap.containsKey(original))
{
Item i = blockItemMap.get(original);
if (i instanceof ItemBlock)
{
try
{
FinalFieldHelper.setField(blockField, i, replacement);
}
catch (Exception e)
{
throw Throwables.propagate(e);
}
}
blockItemMap.forcePut(replacement,i);
}
}
示例4: 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));
}
}
}
示例5: registerFilename
import com.google.common.collect.BiMap; //导入方法依赖的package包/类
@Override
public synchronized boolean registerFilename(UUID id, String filename)
{
BiMap<String, UUID> inverse = state.getRegisteredFilenames().inverse();
if (inverse.containsKey(filename))
{
return inverse.get(filename).equals(id);
}
inverse.put(filename, id);
return true;
}
示例6: convertMappings
import com.google.common.collect.BiMap; //导入方法依赖的package包/类
public static void convertMappings(Mappings mappings, BiMap<ClassEntry,ClassEntry> changes) {
// sort the changes so classes are renamed in the correct order
// ie. if we have the mappings a->b, b->c, we have to apply b->c before a->b
LinkedHashMap<ClassEntry,ClassEntry> sortedChanges = Maps.newLinkedHashMap();
int numChangesLeft = changes.size();
while (!changes.isEmpty()) {
Iterator<Map.Entry<ClassEntry,ClassEntry>> iter = changes.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<ClassEntry,ClassEntry> change = iter.next();
if (changes.containsKey(change.getValue())) {
sortedChanges.put(change.getKey(), change.getValue());
iter.remove();
}
}
// did we remove any changes?
if (numChangesLeft - changes.size() > 0) {
// keep going
numChangesLeft = changes.size();
} else {
// can't sort anymore. There must be a loop
break;
}
}
if (!changes.isEmpty()) {
throw new Error("Unable to sort class changes! There must be a cycle.");
}
// convert the mappings in the correct class order
for (Map.Entry<ClassEntry,ClassEntry> entry : sortedChanges.entrySet()) {
mappings.renameObfClass(entry.getKey().getName(), entry.getValue().getName());
}
}
示例7: lookup
import com.google.common.collect.BiMap; //导入方法依赖的package包/类
/**
* Looks up the specified input value to the corresponding value with the specified map.
*
* @param map bidirectional mapping
* @param input input type
* @param cls class of output value
* @param <I> type of input value
* @param <O> type of output value
* @return the corresponding value stored in the specified map
*/
private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
if (!map.containsKey(input)) {
throw new RuntimeException(
String.format("No mapping found for %s when converting to %s",
input, cls.getName()));
}
return map.get(input);
}
示例8: lookup
import com.google.common.collect.BiMap; //导入方法依赖的package包/类
/**
* Looks up the specified input value to the corresponding value with the specified map.
*
* @param map bidirectional mapping
* @param input input value
* @param cls class of output value
* @param <I> type of input value
* @param <O> type of output value
* @return the corresponding value stored in the specified map
*/
private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
if (!map.containsKey(input)) {
throw new RuntimeException(
String.format("No mapping found for %s when converting to %s", input, cls.getName()));
}
return map.get(input);
}
示例9: lookup
import com.google.common.collect.BiMap; //导入方法依赖的package包/类
/**
* Looks up the specified input value to the corresponding value with the specified map.
*
* @param map bidirectional mapping
* @param input input value
* @param cls class of output value
* @param <I> type of input value
* @param <O> type of output value
* @return the corresponding value stored in the specified map
* @throws NoMappingFoundException if no corresponding value is found
*/
private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
if (!map.containsKey(input)) {
throw new NoMappingFoundException(input, cls);
}
return map.get(input);
}