当前位置: 首页>>代码示例>>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;未经允许,请勿转载。