List of usage examples for com.google.common.collect Multimaps transformValues
public static <K, V1, V2> ListMultimap<K, V2> transformValues(ListMultimap<K, V1> fromMultimap, final Function<? super V1, V2> function)
From source file:org.jclouds.openstack.nova.v2_0.compute.functions.OrphanedGroupsByRegionId.java
public Multimap<String, String> apply(Set<? extends NodeMetadata> deadNodes) { Iterable<? extends NodeMetadata> nodesWithGroup = filter(deadNodes, NodePredicates.hasGroup()); Set<RegionAndName> regionAndGroupNames = ImmutableSet .copyOf(filter(transform(nodesWithGroup, new Function<NodeMetadata, RegionAndName>() { @Override/* w w w . j av a 2 s .co m*/ public RegionAndName apply(NodeMetadata input) { String regionId = input.getLocation().getScope() == LocationScope.HOST ? input.getLocation().getParent().getId() : input.getLocation().getId(); return RegionAndName.fromRegionAndName(regionId, input.getGroup()); } }), allNodesInGroupTerminated)); Multimap<String, String> regionToRegionAndGroupNames = Multimaps.transformValues( Multimaps.index(regionAndGroupNames, RegionAndName.REGION_FUNCTION), RegionAndName.NAME_FUNCTION); return regionToRegionAndGroupNames; }
From source file:org.agorava.core.utils.URLUtils.java
/** * @param parameters map to build the query string from * @return a query string corresponding to the map *///from w w w . j a v a 2s .c o m private static String mapToQueryString(Multimap<String, Object> parameters) { if (parameters.size() == 0) return EMPTY_STRING; Multimap<String, String> urlEncodeMap = Multimaps.transformValues(parameters, new formUrlEncodeFunc()); return queryMapJoiner.join(urlEncodeMap.entries()); }
From source file:net.hydromatic.optiq.jdbc.OptiqSchema.java
public OptiqSchema(OptiqSchema parent, final Schema schema) { this.parent = parent; this.schema = schema; assert (parent == null) == (this instanceof OptiqRootSchema); this.compositeTableMap = CompositeMap.of(Maps.transformValues(tableMap, new Function<TableEntry, Table>() { public Table apply(TableEntry input) { return input.getTable(); }//from w w w . j a v a 2s.co m }), Maps.transformValues( Multimaps.filterEntries(tableFunctionMap, new Predicate<Map.Entry<String, TableFunctionEntry>>() { public boolean apply(Map.Entry<String, TableFunctionEntry> input) { return input.getValue().getTableFunction().getParameters().isEmpty(); } }).asMap(), new Function<Collection<TableFunctionEntry>, Table>() { public Table apply(Collection<TableFunctionEntry> input) { // At most one function with zero parameters. TableFunctionEntry entry = input.iterator().next(); return entry.getTableFunction().apply(ImmutableList.of()); } }), Compatible.INSTANCE.asMap(schema.getTableNames(), new Function<String, Table>() { public Table apply(String input) { return schema.getTable(input); } })); // TODO: include schema's table functions in this map. this.compositeTableFunctionMap = Multimaps.transformValues(tableFunctionMap, new Function<TableFunctionEntry, TableFunction>() { public TableFunction apply(TableFunctionEntry input) { return input.getTableFunction(); } }); this.compositeSubSchemaMap = CompositeMap.of(subSchemaMap, Compatible.INSTANCE .<String, OptiqSchema>asMap(schema.getSubSchemaNames(), new Function<String, OptiqSchema>() { public OptiqSchema apply(String input) { return addSchema(schema.getSubSchema(input)); } })); }
From source file:com.yodle.vantage.component.dao.IssueDao.java
public Map<String, Collection<Issue>> getIssuesDirectlyAffectingVersions(String component) { List<Map<String, Object>> rs = jdbcTemplate .queryForList(/*from www.j a va 2s . co m*/ "MATCH (c:Component {name:{1}})<-[:VERSION_OF]-(v:Version)<-[:PRECEDES|:AFFECTS*]-(i:Issue)" + "MATCH (i)-[:AFFECTS]->(av:Version)" + "WHERE NOT (v)<-[:PRECEDES|:FIXED_BY*]-(i)" + "OPTIONAL MATCH (i)-[:FIXED_BY]->(fv:Version)" + "RETURN c.name, v.version, i.id, i.level, i.message, av.version, fv.version", component); ImmutableListMultimap<String, Map<String, Object>> grouped = Multimaps.index(rs, (row -> (String) row.get("v.version"))); return Multimaps.transformValues(grouped, (this::toIssue)).asMap(); }
From source file:com.facebook.presto.sql.planner.plan.UnionNode.java
/** * Returns the input to output symbol mapping for the given source channel. * A single input symbol can map to multiple output symbols, thus requiring a Multimap. *//*from w w w . ja v a 2 s.co m*/ public Multimap<Symbol, QualifiedNameReference> outputSymbolMap(int sourceIndex) { return Multimaps.transformValues(FluentIterable.from(getOutputSymbols()) .toMap(outputToSourceSymbolFunction(sourceIndex)).asMultimap().inverse(), Symbol::toQualifiedNameReference); }
From source file:msi.gama.lang.gaml.resource.GamlResource.java
private ModelDescription buildModelDescription(final LinkedHashMultimap<String, GamlResource> resources) { // Initializations GAML.getExpressionFactory().resetParser(); final ModelFactory f = GAML.getModelFactory(); final String modelPath = GamlResourceServices.getModelPathOf(this); final String projectPath = GamlResourceServices.getProjectPathOf(this); final boolean isEdited = GamlResourceServices.isEdited(this); final ValidationContext context = GamlResourceServices.getValidationContext(this); // If the resources imported are null, no need to go through their // validation if (resources == null) { final List<ISyntacticElement> self = Collections.singletonList(getSyntacticContents()); return f.createModelDescription(projectPath, modelPath, self, context, isEdited, null); }/*from ww w .j a va2 s . c o m*/ // If there are no micro-models final Set<String> keySet = resources.keySet(); if (keySet.size() == 1 && keySet.contains(null)) { final Iterable<ISyntacticElement> selfAndImports = Iterables.concat( Collections.singleton(getSyntacticContents()), Multimaps.transformValues(resources, TO_SYNTACTIC_CONTENTS).get(null)); return f.createModelDescription(projectPath, modelPath, selfAndImports, context, isEdited, null); } final ListMultimap<String, ISyntacticElement> models = ArrayListMultimap.create(); models.put(null, getSyntacticContents()); models.putAll(Multimaps.transformValues(resources, TO_SYNTACTIC_CONTENTS)); final List<ISyntacticElement> ownImports = models.removeAll(null); final Map<String, ModelDescription> compiledMicroModels = new THashMap<String, ModelDescription>(); for (final String aliasName : models.keySet()) { final ModelDescription mic = GAML.getModelFactory().createModelDescription(projectPath, modelPath, models.get(aliasName), context, isEdited, null); mic.setAlias(aliasName); compiledMicroModels.put(aliasName, mic); } return f.createModelDescription(projectPath, modelPath, ownImports, context, isEdited, compiledMicroModels); }
From source file:io.prestosql.sql.planner.plan.SetOperationNode.java
/** * Returns the input to output symbol mapping for the given source channel. * A single input symbol can map to multiple output symbols, thus requiring a Multimap. *///from w w w. j av a 2 s. com public Multimap<Symbol, SymbolReference> outputSymbolMap(int sourceIndex) { return Multimaps.transformValues(FluentIterable.from(getOutputSymbols()) .toMap(outputToSourceSymbolFunction(sourceIndex)).asMultimap().inverse(), Symbol::toSymbolReference); }
From source file:com.b2international.snowowl.core.compare.CompareResultsDsvExporter.java
public File export(IProgressMonitor monitor) throws IOException { CsvMapper mapper = new CsvMapper(); CsvSchema schema = mapper.schemaFor(CompareData.class).withColumnSeparator(delimiter).withHeader().sortedBy( "componentType", "componentId", "componentType", "label", "changeKind", "attribute", "from", "to"); try (SequenceWriter writer = mapper.writer(schema).writeValues(outputPath.toFile())) { monitor.beginTask("Exporting compare results to DSV", compareResults.getTotalNew() + compareResults.getTotalChanged() + compareResults.getTotalDeleted()); ListMultimap<Short, ComponentIdentifier> newComponentIdentifiers = Multimaps .index(compareResults.getNewComponents(), ComponentIdentifier::getTerminologyComponentId); ListMultimap<Short, String> newComponentIds = ImmutableListMultimap.copyOf( Multimaps.transformValues(newComponentIdentifiers, ComponentIdentifier::getComponentId)); for (short terminologyComponentId : newComponentIds.keySet()) { for (List<String> componentIds : Lists.partition(newComponentIds.get(terminologyComponentId), PARTITION_SIZE)) {//from ww w . j a va 2s . c om RevisionIndexRequestBuilder<CollectionResource<IComponent>> componentFetchRequest = fetcherFunction .apply(terminologyComponentId, componentIds); if (componentFetchRequest == null) { break; } CollectionResource<IComponent> components = componentFetchRequest .build(repositoryUuid, compareBranch) .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync(); for (IComponent component : components) { writer.write(new CompareData(component, ChangeKind.ADDED)); } monitor.worked(components.getItems().size()); } } ListMultimap<Short, ComponentIdentifier> changedComponentIdentifiers = Multimaps .index(compareResults.getChangedComponents(), ComponentIdentifier::getTerminologyComponentId); ListMultimap<Short, String> changedComponentIds = ImmutableListMultimap.copyOf( Multimaps.transformValues(changedComponentIdentifiers, ComponentIdentifier::getComponentId)); ListMultimap<String, IComponent> componentPairs = ArrayListMultimap.create(PARTITION_SIZE, 2); for (short terminologyComponentId : changedComponentIds.keySet()) { for (List<String> componentIds : Lists.partition(changedComponentIds.get(terminologyComponentId), PARTITION_SIZE)) { componentPairs.clear(); RevisionIndexRequestBuilder<CollectionResource<IComponent>> componentFetchRequest = fetcherFunction .apply(terminologyComponentId, componentIds); if (componentFetchRequest == null) { break; } componentFetchRequest.build(repositoryUuid, baseBranch) .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync() .forEach(c -> componentPairs.put(c.getId(), c)); componentFetchRequest.build(repositoryUuid, compareBranch) .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync() .forEach(c -> componentPairs.put(c.getId(), c)); for (Entry<String, List<IComponent>> entry : Multimaps.asMap(componentPairs).entrySet()) { IComponent baseComponent = entry.getValue().get(0); IComponent compareComponent = entry.getValue().get(1); Collection<CompareData> compareResults = getCompareResultsOfComponent.apply(baseComponent, compareComponent); for (CompareData d : compareResults) { writer.write(d); } } monitor.worked(componentPairs.keySet().size()); } } ListMultimap<Short, ComponentIdentifier> deletedComponentIdentifiers = Multimaps .index(compareResults.getDeletedComponents(), ComponentIdentifier::getTerminologyComponentId); ListMultimap<Short, String> deletedComponentIds = ImmutableListMultimap.copyOf( Multimaps.transformValues(deletedComponentIdentifiers, ComponentIdentifier::getComponentId)); for (short terminologyComponentId : deletedComponentIds.keySet()) { for (List<String> componentIds : Lists.partition(deletedComponentIds.get(terminologyComponentId), PARTITION_SIZE)) { RevisionIndexRequestBuilder<CollectionResource<IComponent>> componentFetchRequest = fetcherFunction .apply(terminologyComponentId, componentIds); if (componentFetchRequest == null) { break; } CollectionResource<IComponent> components = componentFetchRequest .build(repositoryUuid, baseBranch) .execute(ApplicationContext.getServiceForClass(IEventBus.class)).getSync(); for (IComponent component : components) { writer.write(new CompareData(component, ChangeKind.DELETED)); } monitor.worked(components.getItems().size()); } } } finally { monitor.done(); } return outputPath.toFile(); }
From source file:com.google.gerrit.server.git.GroupCollector.java
private static ListMultimap<ObjectId, PatchSet.Id> transformRefs(ListMultimap<ObjectId, Ref> refs) { return Multimaps.transformValues(refs, r -> PatchSet.Id.fromRef(r.getName())); }
From source file:com.twitter.aurora.scheduler.storage.mem.MemTaskStore.java
private Multimap<IJobKey, String> taskIdsByJobKey(Iterable<Task> toIndex) { return Multimaps.transformValues( Multimaps.index(toIndex, Functions.compose(Tasks.SCHEDULED_TO_JOB_KEY, TO_SCHEDULED)), TO_ID); }