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


Java HashBiMap類代碼示例

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


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

示例1: configureResourceSetContainerState

import com.google.common.collect.HashBiMap; //導入依賴的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: opcodeMap

import com.google.common.collect.HashBiMap; //導入依賴的package包/類
public Map<Integer, Class<? extends NetoJsonMessage>> opcodeMap(String filePath, String messagePackage) throws Exception {

        BiMap<Integer, Class<? extends NetoJsonMessage>> classBiMap = HashBiMap.create();

        File opcodeJsonFile = getFile(filePath);

        ObjectMapper ob = new ObjectMapper();

        JsonNode jsonNode = ob.readTree(opcodeJsonFile);
        Iterator<String> it = jsonNode.fieldNames();

        while(it.hasNext()) {
            StringBuilder sb = new StringBuilder();
            String className = it.next();
            int opcode = jsonNode.get(className).asInt();
            sb.append(messagePackage).append('.').append(className);
            Class<? extends NetoJsonMessage> aClass = (Class<? extends NetoJsonMessage>) Class.forName(sb.toString());
            classBiMap.put(opcode, aClass);
        }

        return classBiMap;
    }
 
開發者ID:veritasware,項目名稱:neto,代碼行數:23,代碼來源:NetoResourceUtil.java

示例3: build

import com.google.common.collect.HashBiMap; //導入依賴的package包/類
GqlInputConverter build() {
  HashBiMap<String, Descriptor> mapping = HashBiMap.create();
  HashBiMap<String, EnumDescriptor> enumMapping = HashBiMap.create(getEnumMap(enumDescriptors));
  LinkedList<Descriptor> loop = new LinkedList<>(descriptors);

  Set<FileDescriptor> fileDescriptorSet = ProtoRegistry.extractDependencies(fileDescriptors);

  for (FileDescriptor fileDescriptor : fileDescriptorSet) {
    loop.addAll(fileDescriptor.getMessageTypes());
    enumMapping.putAll(getEnumMap(fileDescriptor.getEnumTypes()));
  }

  while (!loop.isEmpty()) {
    Descriptor descriptor = loop.pop();
    if (!mapping.containsKey(descriptor.getFullName())) {
      mapping.put(getReferenceName(descriptor), descriptor);
      loop.addAll(descriptor.getNestedTypes());
      enumMapping.putAll(getEnumMap(descriptor.getEnumTypes()));
    }
  }

  return new GqlInputConverter(
      ImmutableBiMap.copyOf(mapping), ImmutableBiMap.copyOf(enumMapping));
}
 
開發者ID:google,項目名稱:rejoiner,代碼行數:25,代碼來源:GqlInputConverter.java

示例4: modifyTypes

import com.google.common.collect.HashBiMap; //導入依賴的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.HashBiMap; //導入依賴的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.HashBiMap; //導入依賴的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: initWidget

import com.google.common.collect.HashBiMap; //導入依賴的package包/類
@PostConstruct
protected void initWidget() {
    for (DayOfWeek day : DayOfWeek.values()) {
        weekStart.addItem(day.toString());
    }

    // TODO: Make this more maintainable
    templateDurationIndexMap = HashBiMap.create();
    templateDuration.addItem("1 Week");
    templateDurationIndexMap.put(1, 0);
    templateDuration.addItem("2 Weeks");
    templateDurationIndexMap.put(2, 1);
    templateDuration.addItem("4 Weeks");
    templateDurationIndexMap.put(4, 2);

    desiredWeightInput.setValidators(new DecimalMinValidator<Integer>(0));
    undesiredWeightInput.setValidators(new DecimalMinValidator<Integer>(0));
}
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:19,代碼來源:TenantConfigurationEditor.java

示例8: lookup

import com.google.common.collect.HashBiMap; //導入依賴的package包/類
public Multimap<K, InsertPosition<K, G, V, T>> lookup(G queryGraph, boolean exactMatch) {

        Set<T> queryGraphTags = extractGraphTagsWrapper(queryGraph);

        Collection<InsertPosition<K, G, V, T>> positions = new LinkedList<>();
        findInsertPositions(positions, rootNode, queryGraph, queryGraphTags, HashBiMap.create(), HashBiMap.create(), true, exactMatch); //, writer);

        Multimap<K, InsertPosition<K, G, V, T>> result = HashMultimap.create();
        logger.debug("Lookup result candidates: " + positions.size());
        for(InsertPosition<K, G, V, T> pos : positions) {
            // Match with the children

            result.put(pos.getNode().getKey(), pos);
            //System.out.println("Node " + pos.node + " with keys " + pos.node.getKeys() + " iso: " + pos.getGraphIso().getInToOut());
//            for(K key : pos.node.getKeys()) {
//                result.put(key, pos);
//            }
        }
        return result;
    }
 
開發者ID:SmartDataAnalytics,項目名稱:SubgraphIsomorphismIndex,代碼行數:21,代碼來源:SubgraphIsomorphismIndexImpl.java

示例9: add

import com.google.common.collect.HashBiMap; //導入依賴的package包/類
/**
     * During the insert procedure, the insert graph is never renamed, because we want to figure out
     * how to remap existing nodes such they become a subgraph of the insertGraph.
     *
     * @param graph
     */
    void add(IndexNode<K, G, V, T> node, K key, G insertGraph, Set<T> insertGraphTags, BiMap<V, V> baseIso, boolean forceInsert) { //, IndentedWriter writer) {
        // The insert graph must be larger than the node Graph


        Collection<InsertPosition<K, G, V, T>> positions = new LinkedList<>();
        HashBiMap<V, V> deltaIso = HashBiMap.create();
        findInsertPositions(positions, node, insertGraph, insertGraphTags, baseIso, deltaIso, false, false); //, writer);

//        positions.forEach(p -> {
//            System.out.println("Insert pos: " + p.getNode().getKey() + " --- " + p.getIso());
//        });

        for(InsertPosition<K, G, V, T> pos : positions) {
            performAdd(key, pos, forceInsert); //, writer);
        }
    }
 
開發者ID:SmartDataAnalytics,項目名稱:SubgraphIsomorphismIndex,代碼行數:23,代碼來源:SubgraphIsomorphismIndexImpl.java

示例10: testConflictInsertKV

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

示例11: testFixedConflict

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

示例12: testKeyValueCheck

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

示例13: testUpdateBiMapDate

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

示例14: onCreate

import com.google.common.collect.HashBiMap; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void onCreate(Map<ResourceLocation, ?> slaveset, BiMap<ResourceLocation, ? extends IForgeRegistry<?>> registries)
{
    final ClearableObjectIntIdentityMap<IBlockState> idMap = new ClearableObjectIntIdentityMap<IBlockState>()
    {
        @SuppressWarnings("deprecation")
        @Override
        public int get(IBlockState key)
        {
            Integer integer = (Integer)this.identityMap.get(key);
            // There are some cases where this map is queried to serialize a state that is valid,
            //but somehow not in this list, so attempt to get real metadata. Doing this hear saves us 7 patches
            if (integer == null && key != null)
                integer = this.identityMap.get(key.getBlock().getStateFromMeta(key.getBlock().getMetaFromState(key)));
            return integer == null ? -1 : integer.intValue();
        }
    };
    ((Map<ResourceLocation,Object>)slaveset).put(BLOCKSTATE_TO_ID, idMap);
    final HashBiMap<Block, Item> map = HashBiMap.create();
    ((Map<ResourceLocation,Object>)slaveset).put(BLOCK_TO_ITEM, map);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:23,代碼來源:GameData.java

示例15: lookupFluidForBlock

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


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