List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:grakn.core.graql.executor.WriteExecutor.java
/** * <a href=https://en.wikipedia.org/wiki/Composition_of_relations>Compose</a> two Multimaps together, * treating them like many-to-many relations. *//* ww w .j a v a 2s. c o m*/ private static Multimap<Writer, Writer> writerDependencies(Multimap<Writer, Variable> writerToVar, Multimap<Variable, Writer> varToWriter) { Multimap<Writer, Writer> dependency = HashMultimap.create(); for (Map.Entry<Writer, Variable> entry : writerToVar.entries()) { Writer dependant = entry.getKey(); Variable intermediateVar = entry.getValue(); for (Writer depended : varToWriter.get(intermediateVar)) { dependency.put(dependant, depended); } } return dependency; }
From source file:org.jboss.errai.idea.plugin.ui.TemplateUtil.java
private static void _scanTag(Multimap<String, TemplateDataField> foundTags, XmlTag xmlTag, String dataFieldTagAttribute) { XmlAttribute xmlAttribute = xmlTag.getAttribute(dataFieldTagAttribute); if (xmlAttribute != null) { foundTags.put(xmlAttribute.getValue(), new TemplateDataField(xmlTag, xmlAttribute.getValue())); }/*from ww w . ja va2 s . c o m*/ }
From source file:org.eclipse.papyrus.uml.diagram.activity.activitygroup.utils.Utils.java
/** * Get the the multimap relative a request and a {@link Iterable} of {@link EReference} * // w w w.j a v a2 s .com * @param request * @param references * @return */ protected static Multimap<EReference, EObject> getReferenceMultimap(IGroupRequest request, Iterable<EReference> references) { Object elementAdapter = request.getTargetElement().getAdapter(EObject.class); if (elementAdapter instanceof EObject && references != null) { Multimap<EReference, EObject> result = ArrayListMultimap.create(); EObject targetElement = (EObject) elementAdapter; if (targetElement != null) { for (EReference ref : references) { if (ref.isMany()) { Collection<EObject> values = (Collection<EObject>) targetElement.eGet(ref); for (EObject v : values) { result.put(ref, v); } } else { Object value = targetElement.eGet(ref); ; if (value instanceof EObject) { result.put(ref, (EObject) value); } } } } return result; } return ArrayListMultimap.create(); }
From source file:org.sonar.plugins.gosu.codenarc.Converter.java
@SafeVarargs private static void insertRules(Multimap<RuleSet, Rule> rules, String version, Properties props, Map<String, AptResult> parametersByRule, Class<? extends AbstractRule>... ruleClasses) throws Exception { for (Class<? extends AbstractRule> ruleClass : ruleClasses) { rules.put(RuleSet.getCategory(ruleClass), new Rule(ruleClass, version, props, parametersByRule)); }/*from w w w . j a va 2 s .c o m*/ }
From source file:de.unisb.cs.st.javalanche.mutation.analyze.AnalyzeUtil.java
/** * Returns a multimap that contains a mapping between the tests and the * mutations that are detected by the test. * //ww w . j av a2 s . c o m * @param mutations * the mutations to check. * @return the multimap between the tests and mutations. */ public static Multimap<String, Mutation> getDetectedByTest(Iterable<Mutation> mutations) { Multimap<String, Mutation> mm = HashMultimap.create(); for (Mutation mutation : mutations) { if (mutation.isKilled()) { MutationTestResult mutationResult = mutation.getMutationResult(); Collection<TestMessage> errors = mutationResult.getErrors(); Collection<TestMessage> failures = mutationResult.getFailures(); Set<TestMessage> all = new HashSet<TestMessage>(errors); all.addAll(failures); for (TestMessage testMessage : all) { String testCaseName = testMessage.getTestCaseName(); mm.put(testCaseName, mutation); } } } return mm; }
From source file:cosmos.records.JsonRecords.java
/** * Builds a {@link MultimapRecord} from the provided {@link JsonObject} using a docid * from the {@link DocIdGenerator}. This method will support lists of values for a key * in the {@link JsonObject} but will fail on values which are {@link JsonObject}s and * values which have nested {@link JsonArray}s. * @param map The {@link JsonObject} to build this {@link MultimapRecord} from * @param generator {@link DocIdGenerator} to construct a docid for this {@link MultimapRecord} * @return A {@link MultimapRecord} built from the provided arguments. *//*from w w w. ja va 2 s. c o m*/ protected static MultimapRecord asMultimapRecord(JsonObject map, DocIdGenerator generator) { Multimap<Column, RecordValue<?>> data = HashMultimap.create(); for (Entry<String, JsonElement> entry : map.entrySet()) { final Column key = Column.create(entry.getKey()); final JsonElement value = entry.getValue(); if (value.isJsonNull()) { data.put(key, null); } else if (value.isJsonPrimitive()) { JsonPrimitive primitive = (JsonPrimitive) value; // Numbers if (primitive.isNumber()) { NumberRecordValue<?> v; double d = primitive.getAsDouble(); if ((int) d == d) { v = new IntegerRecordValue((int) d, Defaults.EMPTY_VIS); } else if ((long) d == d) { v = new LongRecordValue((long) d, Defaults.EMPTY_VIS); } else { v = new DoubleRecordValue(d, Defaults.EMPTY_VIS); } data.put(key, v); } else if (primitive.isString()) { // String data.put(key, new StringRecordValue(primitive.getAsString(), Defaults.EMPTY_VIS)); } else if (primitive.isBoolean()) { // Boolean data.put(key, new BooleanRecordValue(primitive.getAsBoolean(), Defaults.EMPTY_VIS)); } else if (primitive.isJsonNull()) { // Is this redundant? data.put(key, null); } else { throw new RuntimeException("Unhandled primitive: " + primitive); } } else if (value.isJsonArray()) { // Multimaps should handle the multiple values, not fail JsonArray values = value.getAsJsonArray(); for (JsonElement element : values) { if (element.isJsonNull()) { data.put(key, null); } else if (element.isJsonPrimitive()) { JsonPrimitive primitive = (JsonPrimitive) element; // Numbers if (primitive.isNumber()) { NumberRecordValue<?> v; double d = primitive.getAsDouble(); if ((int) d == d) { v = new IntegerRecordValue((int) d, Defaults.EMPTY_VIS); } else if ((long) d == d) { v = new LongRecordValue((long) d, Defaults.EMPTY_VIS); } else { v = new DoubleRecordValue(d, Defaults.EMPTY_VIS); } data.put(key, v); } else if (primitive.isString()) { // String data.put(key, new StringRecordValue(primitive.getAsString(), Defaults.EMPTY_VIS)); } else if (primitive.isBoolean()) { // Boolean data.put(key, new BooleanRecordValue(primitive.getAsBoolean(), Defaults.EMPTY_VIS)); } else if (primitive.isJsonNull()) { // Is this redundant? data.put(key, null); } else { throw new RuntimeException("Unhandled Json primitive: " + primitive); } } else { throw new RuntimeException("Expected a Json primitive"); } } } else { throw new RuntimeException("Expected a String, Number or Boolean"); } } return new MultimapRecord(data, generator.getDocId(data), Defaults.EMPTY_VIS); }
From source file:com.zimbra.cs.db.DbPendingAclPush.java
public static Multimap<Integer, Integer> getEntries(Date uptoTime) throws ServiceException { Multimap<Integer, Integer> mboxIdToItemIds = HashMultimap.create(); DbConnection conn = null;// w w w . j ava2 s .co m PreparedStatement stmt = null; ResultSet rs = null; ZimbraLog.misc.debug("Getting entries recorded before %s for ACL push", uptoTime); try { conn = DbPool.getConnection(); stmt = conn.prepareStatement( "SELECT mailbox_id, item_id FROM " + TABLE_PENDING_ACL_PUSH + " WHERE date < ?"); stmt.setLong(1, uptoTime.getTime()); rs = stmt.executeQuery(); while (rs.next()) { mboxIdToItemIds.put(rs.getInt(1), rs.getInt(2)); } } catch (SQLException e) { throw ServiceException.FAILURE("Unable to get entries recorded before " + uptoTime + " for ACL push", e); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); DbPool.quietClose(conn); } return mboxIdToItemIds; }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.java
static private void extractTimestampResults(@Output Multimap<Cell, Long> ret, Map<ByteBuffer, List<ColumnOrSuperColumn>> results) { for (Entry<ByteBuffer, List<ColumnOrSuperColumn>> result : results.entrySet()) { byte[] row = CassandraKeyValueServices.getBytesFromByteBuffer(result.getKey()); for (ColumnOrSuperColumn col : result.getValue()) { Pair<byte[], Long> pair = CassandraKeyValueServices.decomposeName(col.column); ret.put(Cell.create(row, pair.lhSide), pair.rhSide); }//from ww w . j a v a2s . c om } }
From source file:com.foundationdb.server.types.service.ResolvablesRegistry.java
private static <R extends TOverload, V extends TValidatedOverload> ListMultimap<String, ScalarsGroup<V>> createScalars( InstanceFinder finder, TCastResolver castResolver, Class<R> plainClass, Function<R, V> validator) { Multimap<String, V> overloadsByName = ArrayListMultimap.create(); int errors = 0; for (R scalar : finder.find(plainClass)) { try {/*from w ww .j ava 2s.c o m*/ V validated = validator.apply(scalar); String[] names = validated.registeredNames(); for (int i = 0; i < names.length; ++i) names[i] = names[i].toLowerCase(); for (String name : names) overloadsByName.put(name, validated); } catch (RuntimeException e) { rejectTOverload(scalar, e); ++errors; } catch (AssertionError e) { rejectTOverload(scalar, e); ++errors; } } if (errors > 0) { StringBuilder sb = new StringBuilder("Found ").append(errors).append(" error"); if (errors != 1) sb.append('s'); sb.append(" while collecting scalar functions. Check logs for details."); throw new AkibanInternalException(sb.toString()); } ArrayListMultimap<String, ScalarsGroup<V>> results = ArrayListMultimap.create(); for (Map.Entry<String, Collection<V>> entry : overloadsByName.asMap().entrySet()) { String overloadName = entry.getKey(); Collection<V> allOverloads = entry.getValue(); for (Collection<V> priorityGroup : scalarsByPriority(allOverloads)) { ScalarsGroup<V> scalarsGroup = new ScalarsGroupImpl<>(priorityGroup, castResolver); results.put(overloadName, scalarsGroup); } } results.trimToSize(); return Multimaps.unmodifiableListMultimap(results); }
From source file:com.zimbra.cs.db.DbBlobConsistency.java
public static int getNumRows(DbConnection conn, Mailbox mbox, String tableName, String idColName, Multimap<Integer, Integer> idRevs) throws ServiceException { Set<Integer> mail_itemIds = new HashSet<Integer>(); Multimap<Integer, Integer> rev_itemIds = HashMultimap.create(); for (Integer itemId : idRevs.keySet()) { Collection<Integer> revs = idRevs.get(itemId); for (int rev : revs) { if (rev == 0) { mail_itemIds.add(itemId); } else { rev_itemIds.put(itemId, rev); }/*from ww w . jav a2 s . co m*/ } } PreparedStatement stmt = null; ResultSet rs = null; try { StringBuffer sql = new StringBuffer(); boolean revisionTable = tableName.startsWith(DbMailItem.TABLE_REVISION); sql.append("SELECT COUNT(*) FROM ").append(DbMailbox.qualifyTableName(mbox, tableName)) .append(" WHERE ").append(DbMailItem.IN_THIS_MAILBOX_AND); if (!revisionTable || mail_itemIds.size() > 0) { if (mail_itemIds.size() == 0) { sql.append(idColName).append(" in ('')"); } else { sql.append(DbUtil.whereIn(idColName, mail_itemIds.size())); } } if (revisionTable) { if (mail_itemIds.size() > 0 && rev_itemIds.size() > 0) { sql.append(" OR "); } if (rev_itemIds.size() > 0) { sql.append(DbUtil.whereIn(Db.getInstance().concat(idColName, "'-'", "version"), rev_itemIds.size())); } } stmt = conn.prepareStatement(sql.toString()); int pos = 1; pos = DbMailItem.setMailboxId(stmt, mbox, pos); for (int itemId : mail_itemIds) { stmt.setInt(pos++, itemId); } if (revisionTable) { for (Integer itemId : rev_itemIds.keySet()) { Collection<Integer> revs = rev_itemIds.get(itemId); for (int rev : revs) { stmt.setString(pos++, itemId + "-" + rev); } } } rs = stmt.executeQuery(); rs.next(); return rs.getInt(1); } catch (SQLException e) { throw ServiceException.FAILURE("getting number of rows for matching id's in " + tableName, e); } finally { DbPool.closeResults(rs); DbPool.quietCloseStatement(stmt); } }