当前位置: 首页>>代码示例>>Java>>正文


Java Multimaps.invertFrom方法代码示例

本文整理汇总了Java中com.google.common.collect.Multimaps.invertFrom方法的典型用法代码示例。如果您正苦于以下问题:Java Multimaps.invertFrom方法的具体用法?Java Multimaps.invertFrom怎么用?Java Multimaps.invertFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.Multimaps的用法示例。


在下文中一共展示了Multimaps.invertFrom方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildInitialState

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private static Set<InstanceTaskConfig> buildInitialState(Map<Integer, ITaskConfig> tasks) {
  // Translate tasks into instance IDs.
  Multimap<ITaskConfig, Integer> instancesByConfig = HashMultimap.create();
  Multimaps.invertFrom(Multimaps.forMap(tasks), instancesByConfig);

  // Reduce instance IDs into contiguous ranges.
  Map<ITaskConfig, Set<Range<Integer>>> rangesByConfig =
      Maps.transformValues(instancesByConfig.asMap(), Numbers::toRanges);

  ImmutableSet.Builder<InstanceTaskConfig> builder = ImmutableSet.builder();
  for (Map.Entry<ITaskConfig, Set<Range<Integer>>> entry : rangesByConfig.entrySet()) {
    builder.add(new InstanceTaskConfig()
        .setTask(entry.getKey().newBuilder())
        .setInstances(IRange.toBuildersSet(convertRanges(entry.getValue()))));
  }

  return builder.build();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:19,代码来源:SchedulerThriftInterface.java

示例2: invertFrom

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
 * Creates a new multimap that reverses the keys and values in {@code map}.
 * 
 * @param map
 * @return
 */
public static IntMultimap invertFrom(Multimap<? extends Integer, ? extends Integer> map) {
  if (map instanceof IntMultimap) {
    IntMultimap other = (IntMultimap) map;
    // This is unnecessary, but it makes this method easier to implement.
    other.reindexItems();

    int[] newSortedKeys = Arrays.copyOf(other.sortedValues, other.sortedValues.length);
    int[] newSortedValues = Arrays.copyOf(other.sortedKeys, other.sortedKeys.length);
   
    ArrayUtils.sortKeyValuePairs(newSortedKeys, newSortedValues, 0, newSortedKeys.length);

    return new IntMultimap(newSortedKeys, newSortedValues);
  } else {
    IntMultimap inverse = IntMultimap.create();
    Multimaps.invertFrom(map, inverse);
    return inverse;
  }
}
 
开发者ID:jayantk,项目名称:jklol,代码行数:25,代码来源:IntMultimap.java

示例3: reverse

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
 * Return a <b>new</b> <tt>Graph</tt> with the same nodes as this graph but
 * with the edges reversed.
 *
 * @return the reversed graph
 */
public synchronized Graph<T> reverse() {
    Multimap<T, T> reverseEdges = HashMultimap.create();
    Multimaps.invertFrom(this.edges, reverseEdges);

    return new Graph<T>(new HashSet<T>(this.nodes), reverseEdges);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:13,代码来源:Graph.java

示例4: instancesToConfigGroups

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private static Set<ConfigGroup> instancesToConfigGroups(Map<Integer, ITaskConfig> tasks) {
  Multimap<ITaskConfig, Integer> instancesByDetails = Multimaps.invertFrom(
      Multimaps.forMap(tasks),
      HashMultimap.create());
  return ImmutableSet.copyOf(
      Iterables.transform(instancesByDetails.asMap().entrySet(), TO_GROUP));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:8,代码来源:ReadOnlySchedulerImpl.java

示例5: getReqRelationByCommit

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
 * get requirement id by commit id
 * @param commitId commit id to search for
 * @return all requirements that are related to the {@code commitId}
 * @throws IOException
 */
public Set<String> getReqRelationByCommit(String commitId) throws IOException {
    SetMultimap<String, String> relations = getAllReqCommitRelations();
    SetMultimap<String, String> relationsComReq = HashMultimap.create();
    Multimaps.invertFrom(relations, relationsComReq);
    return relationsComReq.get(commitId);
}
 
开发者ID:AMOSTeam3,项目名称:amos-ss15-proj3,代码行数:13,代码来源:DataSource.java

示例6: getRemoteDeviceImplementation

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private synchronized DInterface getRemoteDeviceImplementation(Device device, Class<?> implementationType) {

        if (isRemoteImplementLocked(device))
            return null;

        setRemoteImplementLock(device);

        // system wide check
        // gathering all possible bridges...
        ListMultimap<Integer, HostDevice> bridges = ArrayListMultimap.create();
        Map<HostDevice, HostDevice.Interface> bridgeInterfaces = new HashMap<>();
        for (HostDevice host : devices.stream().distinct()
                .filter(d -> d instanceof HostDevice)
                .filter(d -> !d.equals(getLocalDevice()))
                .filter(d -> !d.equals(device))
                .map(d -> (HostDevice) d)
                .collect(Collectors.toList())) {

            try {
                HostDevice.Interface hostInterface = Blackbird.this.interfaceDevice(host, HostDevice.Interface.class);
                int distance = hostInterface.getImplementationDistanceTo(device);

                if (distance != -1) {
                    bridges.put(distance, host);
                    bridgeInterfaces.put(host, hostInterface);
                }
            } catch (Exception ignored) {
            }

        }

        ListMultimap<HostDevice, Integer> distanceMap = Multimaps.invertFrom(bridges, ArrayListMultimap.create());
        //List<Integer> distances = StreamSupport.stream(bridges.keySet()).collect(Collectors.toList());
        //distances = StreamSupport.stream(distances).sorted((a, b) -> a - b).collect(Collectors.toList());

        //...and try to use them
        DInterface implementation = null;
        if (!bridges.isEmpty()) {

            @SuppressWarnings("OptionalGetWithoutIsPresent")
            int minDistance = bridges.keySet().stream().mapToInt(i -> i).min().getAsInt();
            HostDevice bridge = bridges.get(minDistance).get(0); // any bridge with min distance

            HostDevice.Interface bridgeInterface = bridgeInterfaces.get(bridge);

            implementation = bridgeInterface.interfaceDevice(device, (Class<DInterface>) implementationType);

            logger.info("{}, acquired remote implementation from {}", device, bridge);


        }

        clearRemoteImplementLock(device);

        return implementation;

    }
 
开发者ID:MatzeS,项目名称:blackbird,代码行数:58,代码来源:Blackbird.java

示例7: reverse

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private static Multimap<Integer, KBPString> reverse(Map<KBPString, Integer> CASesToIds) {
  return Multimaps.invertFrom(
      Multimaps.forMap(CASesToIds),
      ArrayListMultimap.<Integer, KBPString>create());
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:6,代码来源:CorefAnnotation.java

示例8: setupModelRegistry

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
@Override
public IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry()
{
    isLoading = true;
    loadBlocks();
    loadVariantItemModels();
    missingModel = ModelLoaderRegistry.getMissingModel();
    stateModels.put(MODEL_MISSING, missingModel);

    final Set<ResourceLocation> textures = Sets.newHashSet(ModelLoaderRegistry.getTextures());
    textures.remove(TextureMap.LOCATION_MISSING_TEXTURE);
    textures.addAll(LOCATIONS_BUILTIN_TEXTURES);

    textureMap.loadSprites(resourceManager, new ITextureMapPopulator()
    {
        public void registerSprites(TextureMap map)
        {
            for(ResourceLocation t : textures)
            {
                map.registerSprite(t);
            }
        }
    });

    IBakedModel missingBaked = missingModel.bake(missingModel.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE);
    Map<IModel, IBakedModel> bakedModels = Maps.newHashMap();
    HashMultimap<IModel, ModelResourceLocation> models = HashMultimap.create();
    Multimaps.invertFrom(Multimaps.forMap(stateModels), models);

    if (firstLoad)
    {
        firstLoad = false;
        for (ModelResourceLocation mrl : stateModels.keySet())
        {
            bakedRegistry.putObject(mrl, missingBaked);
        }
        return bakedRegistry;
    }

    ProgressBar bakeBar = ProgressManager.push("ModelLoader: baking", models.keySet().size());

    for(IModel model : models.keySet())
    {
        bakeBar.step("[" + Joiner.on(", ").join(models.get(model)) + "]");
        if(model == getMissingModel())
        {
            bakedModels.put(model, missingBaked);
        }
        else
        {
            bakedModels.put(model, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE));
        }
    }

    ProgressManager.pop(bakeBar);

    for (Entry<ModelResourceLocation, IModel> e : stateModels.entrySet())
    {
        bakedRegistry.putObject(e.getKey(), bakedModels.get(e.getValue()));
    }
    return bakedRegistry;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:63,代码来源:ModelLoader.java

示例9: configure

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public void configure(List<String> containers, Multimap<String, URI> container2Uris) {
	this.containers = containers;
	this.container2URIs = HashMultimap.create(container2Uris);
	this.uri2container = Multimaps.invertFrom(HashMultimap.create(container2Uris), HashMultimap.<URI, String>create());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:6,代码来源:ResourceSetBasedAllContainersState.java

示例10: SimpleNamespaceContext

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
 * Constructor for SimpleNamespaceContext
 * @param namespaces A map where the key is a prefix, and the value is a namespace.
 */
public SimpleNamespaceContext(Map<String, String> namespaces){
    this.namespaces = addConstants(namespaces);
    prefixes = Multimaps.invertFrom(Multimaps.forMap(this.namespaces), ArrayListMultimap.create());
}
 
开发者ID:tajakobsen,项目名称:unxml,代码行数:9,代码来源:SimpleNamespaceContext.java

示例11: invertKeyValues

import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public static Multimap<String, String> invertKeyValues(Multimap<String, String> multimap) {
    Check.notNull(multimap, "multimap");

    Multimap<String, String> result = HashMultimap.create();

    Multimaps.invertFrom(multimap, result);

    return result;
}
 
开发者ID:imagopole,项目名称:omero-csv-tools,代码行数:10,代码来源:MultimapsUtil.java


注:本文中的com.google.common.collect.Multimaps.invertFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。