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


Java BiMap.containsKey方法代碼示例

本文整理匯總了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;
  }
 
開發者ID:cgraywang,項目名稱:TextHIN,代碼行數:17,代碼來源:FileUtils.java

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

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

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

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

示例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());
	}
}
 
開發者ID:cccssw,項目名稱:enigma-vk,代碼行數:35,代碼來源:MappingsConverter.java

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

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

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


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