List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.apache.beam.runners.core.construction.ExecutableStageTranslation.java
/** * Creates a human-readable name for a set of stage names that occur in a single stage. * * <p>This name reflects the nested structure of the stages, as inferred by slashes in the stage * names. Sibling stages will be listed as {A, B}, nested stages as A/B, and according to the * value of truncateSiblingComposites the nesting stops at the first level that siblings are * encountered./* w w w .j a v a 2 s .c om*/ * * <p>This is best understood via examples, of which there are several in the tests for this * class. * * @param names a list of full stage names in this fused operation * @param truncateSiblingComposites whether to recursively descent into composite operations that * have simblings, or stop the recursion at that level. * @return a single string representation of all the stages in this fused operation */ public static String generateNameFromTransformNames(Collection<String> names, boolean truncateSiblingComposites) { Multimap<String, String> groupByOuter = LinkedHashMultimap.create(); for (String name : names) { int index = name.indexOf('/'); if (index == -1) { groupByOuter.put(name, ""); } else { groupByOuter.put(name.substring(0, index), name.substring(index + 1)); } } if (groupByOuter.keySet().size() == 1) { Map.Entry<String, Collection<String>> outer = Iterables.getOnlyElement(groupByOuter.asMap().entrySet()); if (outer.getValue().size() == 1 && outer.getValue().contains("")) { // Names consisted of a single name without any slashes. return outer.getKey(); } else { // Everything is in the same outer stage, enumerate at one level down. return String.format("%s/%s", outer.getKey(), generateNameFromTransformNames(outer.getValue(), truncateSiblingComposites)); } } else { Collection<String> parts; if (truncateSiblingComposites) { // Enumerate the outer stages without their composite structure, if any. parts = groupByOuter.keySet(); } else { // Enumerate the outer stages with their composite structure, if any. parts = groupByOuter.asMap().entrySet().stream() .map(outer -> String .format("%s/%s", outer.getKey(), generateNameFromTransformNames(outer.getValue(), truncateSiblingComposites)) .replaceAll("/$", "")) .collect(Collectors.toList()); } return String.format("{%s}", Joiner.on(", ").join(parts)); } }
From source file:org.eclipse.xtext.scoping.impl.MultimapBasedScope.java
public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions, boolean ignoreCase) { Multimap<QualifiedName, IEObjectDescription> map = null; for (IEObjectDescription description : descriptions) { if (map == null) map = LinkedHashMultimap.create(5, 2); if (ignoreCase) map.put(description.getName().toLowerCase(), description); else/*from w w w .j a v a2 s .c o m*/ map.put(description.getName(), description); } if (map == null || map.isEmpty()) { return parent; } return new MultimapBasedScope(parent, map, ignoreCase); }
From source file:com.yammer.collections.azure.AzureTestUtil.java
@SafeVarargs private static void setupColumnQueries(String tableName, AzureTableRequestFactory azureTableRequestFactoryMock, AzureTableCloudClient azureTableCloudClientMock, Table.Cell<Bytes, Bytes, Bytes>... cells) { TableQuery<AzureEntity> emptyQueryMock = mock(TableQuery.class); when(azureTableRequestFactoryMock.selectAllForColumn(anyString(), anyString())).thenReturn(emptyQueryMock); when(azureTableRequestFactoryMock.containsValueForColumnQuery(anyString(), anyString(), anyString())) .thenReturn(emptyQueryMock); when(azureTableCloudClientMock.execute(emptyQueryMock)).thenReturn(Collections.<AzureEntity>emptyList()); Multimap<Bytes, Table.Cell<Bytes, Bytes, Bytes>> columnCellMap = HashMultimap.create(); for (Table.Cell<Bytes, Bytes, Bytes> cell : cells) { columnCellMap.put(cell.getColumnKey(), cell); TableQuery<AzureEntity> columnValueQueryMock = mock(TableQuery.class); when(azureTableRequestFactoryMock.containsValueForColumnQuery(tableName, encode(cell.getColumnKey()), encode(cell.getValue()))).thenReturn(columnValueQueryMock); when(azureTableCloudClientMock.execute(columnValueQueryMock)) .thenReturn(Collections.singletonList(ENCODE_CELL.apply(cell))); }/* www . ja va 2s .c o m*/ for (Map.Entry<Bytes, Collection<Table.Cell<Bytes, Bytes, Bytes>>> entry : columnCellMap.asMap() .entrySet()) { // row query TableQuery<AzureEntity> columnQueryMock = mock(TableQuery.class); when(azureTableRequestFactoryMock.selectAllForColumn(tableName, encode(entry.getKey()))) .thenReturn(columnQueryMock); when(azureTableCloudClientMock.execute(columnQueryMock)) .thenReturn(Collections2.transform(entry.getValue(), ENCODE_CELL)); } }
From source file:com.google.acai.Dependencies.java
/** * Returns a directed graph representing the dependencies of {@code testingServices}. *//* ww w. j a va 2s . com*/ private static DirectedGraph<TestingService> buildDependencyGraph(Set<TestingService> testingServices) { DirectedGraph<TestingService> dependencyGraph = new DirectedGraph<>(testingServices); Multimap<Class<? extends TestingService>, TestingService> servicesByClass = HashMultimap.create(); for (TestingService testingService : testingServices) { servicesByClass.put(testingService.getClass(), testingService); } for (TestingService testingService : testingServices) { for (TestingService dependency : getDependencies(testingService, servicesByClass)) { dependencyGraph.addEdge(dependency, testingService); } } return dependencyGraph; }
From source file:io.crate.sql.tree.Literal.java
public static Literal fromObject(Object value) { Literal literal = null;// www . j a v a2 s . com if (value == null) { literal = NullLiteral.INSTANCE; } else if (value instanceof String) { literal = new StringLiteral((String) value); } else if (value instanceof Number) { if (value instanceof Float || value instanceof Double) { literal = new DoubleLiteral(value.toString()); } else if (value instanceof Short || value instanceof Integer || value instanceof Long) { literal = new LongLiteral(value.toString()); } } else if (value instanceof Boolean) { literal = (Boolean) value ? BooleanLiteral.TRUE_LITERAL : BooleanLiteral.FALSE_LITERAL; } else if (value instanceof Object[]) { List<Expression> expressions = new ArrayList<>(); for (Object o : (Object[]) value) { expressions.add(fromObject(o)); } literal = new ArrayLiteral(expressions); } else if (value instanceof Map) { Multimap<String, Expression> map = HashMultimap.create(); @SuppressWarnings("unchecked") Map<String, Object> valueMap = (Map<String, Object>) value; for (Map.Entry<String, Object> entry : valueMap.entrySet()) { map.put(entry.getKey(), fromObject(entry.getValue())); } literal = new ObjectLiteral(map); } return literal; }
From source file:com.paolodragone.wsn.util.Senses.java
public static ListMultimap<String, Sense> buildWordSensesMap(Collection<Sense> senses) { Multimap<String, Sense> wordSensesMap = ArrayListMultimap.create(); ListMultimap<String, Sense> wordSensesSortedMap = ArrayListMultimap.create(); for (Sense sense : senses) { wordSensesMap.put(sense.getWord().toLowerCase(), sense); }//from ww w. j a v a 2 s.co m for (String word : wordSensesMap.keySet()) { List<Sense> senseList = new ArrayList<>(wordSensesMap.get(word)); sortSenseList(senseList); wordSensesSortedMap.putAll(word, senseList); } return wordSensesSortedMap; }
From source file:com.isotrol.impe3.freemarker.wrap.ModelUtils.java
static Multimap<String, String> buildURIQueryParameters(List<String> args, int index) { if (args == null || (args.size() - index) < 2) { return ImmutableMultimap.of(); }/* ww w. ja v a 2s .c o m*/ final int n = args.size(); final Multimap<String, String> map = LinkedListMultimap.create(n / 2); for (int i = index; (args.size() - i) >= 2; i += 2) { String p = args.get(i); String v = args.get(i + 1); if (p != null && v != null) { map.put(p, v); } } return map; }
From source file:org.caleydo.view.domino.internal.NodeDataItem.java
public static void update(final Set<NodeGroup> mouseOvers, final Set<NodeGroup> selections) { final NodeDataItem i = instance; if (i == null) return;//from w w w . j av a 2 s.c om Set<NodeGroup> toShow = selections; if (!mouseOvers.isEmpty()) { toShow = mouseOvers; } String text; if (toShow.isEmpty()) { text = "No Selection"; } else { Multimap<Node, NodeGroup> nodes = HashMultimap.create(); for (NodeGroup group : toShow) { Node n = group.getNode(); nodes.put(n, group); } StringBuilder b = new StringBuilder(); for (ILabeled node : ImmutableSortedSet.orderedBy(Labels.BY_LABEL).addAll(nodes.keySet()).build()) { Node n = (Node) node; addNodeInfos(b, n, nodes.get(n)); b.append('\n'); } b.setLength(b.length() - 1); text = b.toString(); } final String t = text; Display.getDefault().asyncExec(new Runnable() { @Override public void run() { i.updateImpl(t); } }); }
From source file:grakn.core.graql.gremlin.RelationTypeInference.java
private static void addAllPossibleRelations(Multimap<Type, RelationType> relationMap, Type metaType) { metaType.subs().forEach(type -> type.playing().flatMap(Role::relations) .forEach(relationType -> relationMap.put(type, relationType))); }
From source file:fr.jcgay.maven.plugin.buildplan.display.AbstractTableDescriptor.java
protected static Map<TableColumn, Integer> findMaxSize(Collection<MojoExecution> executions, TableColumn... columns) { Map<TableColumn, Integer> result = new HashMap<TableColumn, Integer>(); Multimap<TableColumn, Integer> count = ArrayListMultimap.create(); for (MojoExecution execution : executions) { for (TableColumn column : columns) { switch (column) { case ARTIFACT_ID: count.put(column, safeLength(execution.getArtifactId())); break; case EXECUTION_ID: count.put(column, safeLength(execution.getExecutionId())); break; case GOAL: count.put(column, safeLength(execution.getGoal())); break; case PHASE: MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); if (mojoDescriptor != null && mojoDescriptor.getPhase() != null) { count.put(column, safeLength(mojoDescriptor.getPhase())); } else { count.put(column, safeLength(execution.getLifecyclePhase())); }//from w w w . ja va2s. co m } } } for (TableColumn column : TableColumn.values()) { count.put(column, column.title().length()); } for (TableColumn key : count.keySet()) { result.put(key, Collections.max(count.get(key))); } return result; }