List of usage examples for com.google.common.collect Multimaps asMap
@Beta public static <K, V> Map<K, Collection<V>> asMap(Multimap<K, V> multimap)
From source file:com.palantir.atlasdb.keyvalue.cassandra.CQLKeyValueService.java
private Map<byte[], List<Cell>> partitionCellsByPrimaryKey(Collection<Cell> cells) { return Multimaps.asMap(Multimaps.index(cells, Cells.getRowFunction())); }
From source file:elaborate.editor.publish.PublishTask.java
private Map<String, Map<String, List<Long>>> calculateMultivaluedFacetIndex(List<EntryData> entries) { Map<String, ListMultimap<String, Long>> tmpindex = Maps.newHashMap(); for (EntryData entryData : entries) { for (Entry<String, String> entry : entryData.multivaluedFacetValues.entries()) { String facetName = entry.getKey(); String facetValue = entry.getValue(); if (!tmpindex.containsKey(facetName)) { tmpindex.put(facetName, ArrayListMultimap.<String, Long>create()); }/* w ww . j a v a 2s .c om*/ tmpindex.get(facetName).put(facetValue, entryData.entryId); } } Map<String, Map<String, List<Long>>> index = Maps.newHashMap(); for (String metadataField : tmpindex.keySet()) { index.put(metadataField, Multimaps.asMap(tmpindex.get(metadataField))); } return index; }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
private static <E extends Element> HighlightResult<E> getResult(Collection<E> elements, HighlightConditionList highlightConditions) { List<Color> colorList = new ArrayList<>(); ListMultimap<E, Double> alphaValues = ArrayListMultimap.create(); Map<E, Double> thicknessValues = new LinkedHashMap<>(); SetMultimap<E, String> labelLists = LinkedHashMultimap.create(); Map<E, NamedShape> shapes = new LinkedHashMap<>(); elements.forEach(e -> thicknessValues.put(e, 0.0)); for (HighlightCondition condition : highlightConditions.getConditions()) { if (condition.isInvisible()) { continue; }/*from w w w . ja v a2 s . c o m*/ Map<E, Double> values = condition.getValues(elements); if (condition.getColor() != null) { colorList.add(condition.getColor()); for (E e : elements) { List<Double> alphas = alphaValues.get(e); if (!highlightConditions.isPrioritizeColors() || alphas.isEmpty() || Collections.max(alphas) == 0.0) { alphas.add(values.get(e)); } else { alphas.add(0.0); } } } if (condition.isUseThickness()) { elements.forEach(e -> thicknessValues.put(e, thicknessValues.get(e) + values.get(e))); } if (condition.getLabelProperty() != null) { String property = condition.getLabelProperty(); for (E e : elements) { if (values.get(e) != 0.0 && e.getProperties().get(property) != null) { labelLists.put(e, toString(e.getProperties().get(property))); } } } if (condition.getShape() != null) { for (E e : elements) { if (values.get(e) != 0.0 && !shapes.containsKey(e)) { shapes.put(e, condition.getShape()); } } } } Map<E, Paint> colors = new LinkedHashMap<>(); Map<E, String> labels = new LinkedHashMap<>(); Multimaps.asMap(alphaValues).forEach((e, alphas) -> colors.put(e, CanvasUtils .mixColors(e instanceof Edge ? Color.BLACK : Color.WHITE, colorList, alphas, e instanceof Edge))); Multimaps.asMap(labelLists).forEach((e, labelList) -> labels.put(e, Joiner.on("/").join(labelList))); HighlightResult<E> result = new HighlightResult<>(); result.colors = colors; result.thicknessValues = thicknessValues; result.labels = labels; result.shapes = shapes; return result; }
From source file:de.bund.bfr.knime.gis.views.canvas.Canvas.java
@Override public void collapseByPropertyItemClicked() { Set<String> selectedIds = CanvasUtils.getElementIds(getSelectedNodes()); Set<String> idsToCollapse; if (!selectedIds.isEmpty()) { switch (Dialogs.showYesNoCancelDialog(this, "Use only the selected " + naming.nodes() + " for collapsing?", "Confirm")) { case YES: idsToCollapse = selectedIds; break; case NO://ww w . j a v a2 s. c o m idsToCollapse = CanvasUtils.getElementIds(getNodes()); break; case CANCEL: default: return; } } else { idsToCollapse = CanvasUtils.getElementIds(getNodes()); } for (String id : idsToCollapse) { if (collapsedNodes.keySet().contains(id)) { String message; if (idsToCollapse == selectedIds) { message = "Some of the selected " + naming.nodes() + " are already collapsed."; } else { message = "Some of the " + naming.nodes() + " are already collapsed. You have to clear all collapsed " + naming.nodes() + " before."; } Dialogs.showErrorMessage(this, message); return; } } String result = Dialogs.showInputDialog(this, "Select Property for Collapse?", "Collapse by Property", nodeSchema.getMap().keySet()); if (result == null) { return; } SetMultimap<Object, V> nodesByProperty = LinkedHashMultimap.create(); for (String id : idsToCollapse) { V node = nodeSaveMap.get(id); Object value = node.getProperties().get(result); if (value != null) { nodesByProperty.put(value, node); } } ListFilterDialog<Object> dialog = new ListFilterDialog<>(this, KnimeUtils.ORDERING.sortedCopy(nodesByProperty.keySet())); dialog.setVisible(true); if (!dialog.isApproved() || dialog.getFiltered().isEmpty()) { return; } nodesByProperty.keySet().retainAll(dialog.getFiltered()); Set<String> newCollapsedIds = new LinkedHashSet<>(); Multimaps.asMap(nodesByProperty).forEach((property, nodes) -> { String newId = KnimeUtils.createNewValue(property.toString(), nodeSaveMap.keySet()); collapsedNodes.put(newId, CanvasUtils.getElementIds(nodes)); newCollapsedIds.add(newId); }); applyChanges(); setSelectedNodeIdsWithoutListener(newCollapsedIds); call(l -> l.collapsedNodesAndPickingChanged(this)); }
From source file:com.google.devtools.build.lib.analysis.RuleContext.java
/** * Returns the a prerequisites keyed by the CPU of their configurations. * If the split transition is not active (e.g. split() returned an empty * list), the key is an empty Optional./*from w w w .ja v a 2 s . c o m*/ */ public Map<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> getSplitPrerequisites( String attributeName) { checkAttribute(attributeName, Mode.SPLIT); Attribute attributeDefinition = attributes().getAttributeDefinition(attributeName); @SuppressWarnings("unchecked") // Attribute.java doesn't have the BuildOptions symbol. SplitTransition<BuildOptions> transition = (SplitTransition<BuildOptions>) attributeDefinition .getSplitTransition(rule); List<ConfiguredTarget> deps = targetMap.get(attributeName); List<BuildOptions> splitOptions = transition.split(getConfiguration().getOptions()); if (splitOptions.isEmpty()) { // The split transition is not active. Defer the decision on which CPU to use. return ImmutableMap.of(Optional.<String>absent(), deps); } Set<String> cpus = new HashSet<>(); for (BuildOptions options : splitOptions) { // This method should only be called when the split config is enabled on the command line, in // which case this cpu can't be null. cpus.add(options.get(BuildConfiguration.Options.class).cpu); } // Use an ImmutableListMultimap.Builder here to preserve ordering. ImmutableListMultimap.Builder<Optional<String>, TransitiveInfoCollection> result = ImmutableListMultimap .builder(); for (TransitiveInfoCollection t : deps) { if (t.getConfiguration() != null) { result.put(Optional.of(t.getConfiguration().getCpu()), t); } else { // Source files don't have a configuration, so we add them to all architecture entries. for (String cpu : cpus) { result.put(Optional.of(cpu), t); } } } return Multimaps.asMap(result.build()); }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.design.system.model.DefaultSystem.java
@Override public void removeArc(final Arc removed) { Preconditions.checkNotNull(removed); Preconditions.checkArgument(this.graph.containsEdge(removed)); final Network network = removed.getNetwork(); final Set<EnterNode> initials = initial(network); final Update removeUpdate = this.graph.removeAndRealign(removed, this.realignmentProcessor, Multimaps.asMap(ImmutableSetMultimap.copyOf(this.references)), ImmutableSet.copyOf(initials)); removeReferences(removeUpdate.getReferencesRemoved()); this.statesNamingAuthority.release(removed.getName().getText()); updateInitials(initials, removeUpdate); updateAffected(removeUpdate);/*from ww w.j a va 2 s. co m*/ fire(cz.cuni.mff.ms.brodecva.botnicek.ide.design.system.events.ArcRemovedEvent.create(this, removed)); fire(cz.cuni.mff.ms.brodecva.botnicek.ide.design.networks.events.ArcRemovedEvent.create(network, removed)); fire(cz.cuni.mff.ms.brodecva.botnicek.ide.design.arcs.events.ArcRemovedEvent.create(removed)); }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.design.system.model.DefaultSystem.java
@Override public void removeNode(final Node removed) { Preconditions.checkNotNull(removed); Preconditions.checkArgument(this.graph.containsVertex(removed)); final Network network = removed.getNetwork(); checkForReferences(removed, network, "RemovalForbidden"); final Set<EnterNode> initials = initial(network); assert Presence.isPresent(initials); final Update removeUpdate = this.graph.removeAndRealign(removed, this.realignmentProcessor, Multimaps.asMap(ImmutableSetMultimap.copyOf(this.references)), ImmutableSet.copyOf(initials)); this.statesNamingAuthority.release(removed.getName().getText()); removeReferences(removeUpdate.getReferencesRemoved()); updateInitials(initials, removeUpdate); updateAffected(removeUpdate);/* ww w .ja va 2 s . c o m*/ removeFromInitial(removed, initials); removeNodeFromNetwork(removed, network); updateArcs(removeUpdate); fire(NodeRemovedEvent.create(network, removed)); }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueService.java
private <V> Map<InetAddress, List<V>> partitionByHost(Iterable<V> iterable, Function<V, byte[]> keyExtractor) { // Ensure that the same key goes to the same partition. This is important when writing multiple columns // to the same row, since this is a normally a single write in cassandra, whereas splitting the columns // into different requests results in multiple writes. ListMultimap<ByteBuffer, V> partitionedByKey = ArrayListMultimap.create(); for (V value : iterable) { partitionedByKey.put(ByteBuffer.wrap(keyExtractor.apply(value)), value); }//from ww w . j a v a 2 s . com ListMultimap<InetAddress, V> valuesByHost = ArrayListMultimap.create(); for (ByteBuffer key : partitionedByKey.keySet()) { InetAddress host = tokenAwareMapper.getRandomHostForKey(key.array()); valuesByHost.putAll(host, partitionedByKey.get(key)); } return Multimaps.asMap(valuesByHost); }
From source file:org.glowroot.central.repo.SchemaUpgrade.java
@VisibleForTesting static @Nullable Set<String> upgradePermissions(Set<String> permissions) { Set<String> updatedPermissions = new HashSet<>(); ListMultimap<String, String> agentPermissions = ArrayListMultimap.create(); boolean needsUpgrade = false; for (String permission : permissions) { if (permission.startsWith("agent:")) { PermissionParser parser = new PermissionParser(permission); parser.parse();/*from ww w. j av a2 s. c o m*/ String perm = parser.getPermission(); agentPermissions.put(PermissionParser.quoteIfNeededAndJoin(parser.getAgentRollupIds()), perm); if (perm.equals("agent:view")) { needsUpgrade = true; } } else if (permission.equals("admin") || permission.startsWith("admin:")) { updatedPermissions.add(permission); } else { logger.error("unexpected permission: {}", permission); } } if (!needsUpgrade) { return null; } for (Map.Entry<String, List<String>> entry : Multimaps.asMap(agentPermissions).entrySet()) { List<String> perms = entry.getValue(); PermissionParser.upgradeAgentPermissionsFrom_0_9_1_to_0_9_2(perms); for (String perm : perms) { updatedPermissions.add("agent:" + entry.getKey() + ":" + perm.substring("agent:".length())); } } if (updatedPermissions.contains("admin:view") && updatedPermissions.contains("admin:edit")) { updatedPermissions.remove("admin:view"); updatedPermissions.remove("admin:edit"); updatedPermissions.add("admin"); } return updatedPermissions; }