本文整理汇总了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();
}
示例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;
}
}
示例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);
}
示例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));
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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());
}
示例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());
}
示例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;
}