本文整理汇总了Java中com.google.common.collect.BiMap.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java BiMap.isEmpty方法的具体用法?Java BiMap.isEmpty怎么用?Java BiMap.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.BiMap
的用法示例。
在下文中一共展示了BiMap.isEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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());
}
}