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.b2international.snowowl.snomed.api.impl.domain.AxiomInputCreator.java
private String toOwlExpression(final SnomedBrowserAxiom browserAxiom) { final ListMultimap<Integer, Relationship> relationships = ArrayListMultimap.create(); for (final ISnomedBrowserRelationship relationship : browserAxiom.getRelationships()) { final long typeId = Long.valueOf(relationship.getType().getConceptId()); final long targetId = Long.valueOf(relationship.getTarget().getConceptId()); relationships.put(relationship.getGroupId(), new Relationship(relationship.getGroupId(), typeId, targetId)); }/*from w w w . j a v a 2 s. c o m*/ final AxiomRepresentation axiomRepresentation = new AxiomRepresentation(); axiomRepresentation.setPrimitive(browserAxiom.getDefinitionStatus().isPrimitive()); final Long conceptId = Long.valueOf(browserAxiom.getReferencedComponentId()); if (browserAxiom.isNamedConceptOnLeft()) { axiomRepresentation.setLeftHandSideNamedConcept(conceptId); axiomRepresentation.setRightHandSideRelationships(Multimaps.asMap(relationships)); } else { axiomRepresentation.setRightHandSideNamedConcept(conceptId); axiomRepresentation.setLeftHandSideRelationships(Multimaps.asMap(relationships)); } return getConversionService().convertRelationshipsToAxiom(axiomRepresentation); }
From source file:de.bund.bfr.knime.openkrise.common.DeliveryUtils.java
public static Map<String, Set<String>> getWarnings(Connection conn) { boolean useSerialAsID = hasUniqueSerials(conn); SetMultimap<String, String> warnings = LinkedHashMultimap.create(); getDeliveries(conn, getStationIds(conn, useSerialAsID), getDeliveryIds(conn, useSerialAsID), warnings); return Multimaps.asMap(warnings); }
From source file:dagger.internal.codegen.MapMultibindingValidator.java
private void checkForDuplicateMapKeys(dagger.model.Binding multiboundMapBinding, ImmutableSet<ContributionBinding> contributions, DiagnosticReporter diagnosticReporter) { ImmutableSetMultimap<Object, ContributionBinding> contributionsByMapKey = ImmutableSetMultimap .copyOf(Multimaps.index(contributions, ContributionBinding::mapKey)); for (Set<ContributionBinding> contributionsForOneMapKey : Multimaps.asMap(contributionsByMapKey).values()) { if (contributionsForOneMapKey.size() > 1) { diagnosticReporter.reportBinding(ERROR, multiboundMapBinding, duplicateMapKeyErrorMessage(contributionsForOneMapKey, multiboundMapBinding.key())); }/* w ww .j av a2s. c om*/ } }
From source file:bzh.plantkelt.motscroises.Dictionnary.java
public void dump(int maxPatterns) { // Sort patterns by frequency List<Map.Entry<String, List<String>>> entries = new ArrayList<>(Multimaps.asMap(patterns).entrySet()); Collections.sort(entries, new Comparator<Map.Entry<String, List<String>>>() { @Override// ww w.jav a 2 s . c o m public int compare(Map.Entry<String, List<String>> e1, Map.Entry<String, List<String>> e2) { return Integer.compare(e2.getValue().size(), e1.getValue().size()); } }); System.out.println(maxPatterns + " most common patterns:"); int n = 0; for (Map.Entry<String, List<String>> entry : entries) { System.out.println(String.format("%20s : %8d", entry.getKey(), entry.getValue().size())); n++; if (n > maxPatterns) break; } System.out.println("Letters frequencies:"); for (char letter = 'A'; letter <= 'Z'; letter++) { System.out.println(letter + ": " + alphabetFrequencies.freq(letter)); } System.out.println("Word length frequencies:"); for (int i = 1; i < lengthFrequencies.length; i++) { System.out.println(i + ": " + lengthFrequencies[i]); } System.out.println("Number of patterns: " + patterns.keySet().size()); System.out.println("Number of patterns entries: " + patterns.size()); }
From source file:com.google.errorprone.bugpatterns.inject.guice.AssistedParameters.java
@Override public final Description matchMethod(MethodTree constructor, final VisitorState state) { if (!IS_CONSTRUCTOR_WITH_INJECT_OR_ASSISTED.matches(constructor, state)) { return Description.NO_MATCH; }//from w w w .jav a 2 s. c om // Gather @Assisted parameters, partition by type MultiMatchResult<VariableTree> assistedParameters = ASSISTED_PARAMETER_MATCHER.multiMatchResult(constructor, state); if (!assistedParameters.matches()) { return Description.NO_MATCH; } Multimap<Type, VariableTree> parametersByType = partitionParametersByType( assistedParameters.matchingNodes(), state); // If there's more than one parameter with the same type, they could conflict unless their // @Assisted values are different. List<ConflictResult> conflicts = new ArrayList<>(); for (Map.Entry<Type, Collection<VariableTree>> typeAndParameters : parametersByType.asMap().entrySet()) { Collection<VariableTree> parametersForThisType = typeAndParameters.getValue(); if (parametersForThisType.size() < 2) { continue; } // Gather the @Assisted value from each parameter. If any value is repeated amongst the // parameters in this type, it's a compile error. ImmutableListMultimap<String, VariableTree> keyForAssistedVariable = Multimaps .index(parametersForThisType, VALUE_FROM_ASSISTED_ANNOTATION); for (Entry<String, List<VariableTree>> assistedValueToParameters : Multimaps .asMap(keyForAssistedVariable).entrySet()) { if (assistedValueToParameters.getValue().size() > 1) { conflicts.add(ConflictResult.create(typeAndParameters.getKey(), assistedValueToParameters.getKey(), assistedValueToParameters.getValue())); } } } if (conflicts.isEmpty()) { return Description.NO_MATCH; } return buildDescription(constructor).setMessage(buildErrorMessage(conflicts)).build(); }
From source file:de.bund.bfr.knime.openkrise.MyKrisenInterfacesNodeModel.java
/** * {@inheritDoc}//www. j a v a 2 s . com */ @Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { try (Connection conn = set.isUseExternalDb() ? createLocalConnection(KnimeUtils.getFile(removeNameOfDB(set.getDbPath())).getAbsolutePath()) : DBKernel.getLocalConn(true)) { boolean useSerialAsID = !set.isAnonymize() && DeliveryUtils.hasUniqueSerials(conn); Map<Integer, String> stationIds = DeliveryUtils.getStationIds(conn, useSerialAsID); Map<Integer, String> deliveryIds = DeliveryUtils.getDeliveryIds(conn, useSerialAsID); SetMultimap<String, String> warnings = LinkedHashMultimap.create(); List<Delivery> deliveries = DeliveryUtils.getDeliveries(conn, stationIds, deliveryIds, warnings); BufferedDataTable stationTable = getStationTable(conn, stationIds, deliveries, exec, useSerialAsID); BufferedDataTable deliveryTable = getDeliveryTable(conn, stationIds, deliveryIds, exec, useSerialAsID); BufferedDataTable deliveryConnectionsTable = getDeliveryConnectionsTable(deliveries, deliveryTable, exec); if (!warnings.isEmpty()) { for (Map.Entry<String, Set<String>> entry : Multimaps.asMap(warnings).entrySet()) { setWarningMessage(entry.getKey() + ":"); for (String w : entry.getValue()) { setWarningMessage("\t" + w); } } setWarningMessage("Look into the console - there are plausibility issues..."); } return new BufferedDataTable[] { stationTable, deliveryTable, deliveryConnectionsTable }; } }
From source file:io.prestosql.plugin.raptor.legacy.storage.organization.ShardCompactionManager.java
private void discoverShards() { log.info("Discovering shards that need compaction..."); Set<ShardMetadata> allShards = shardManager.getNodeShards(currentNodeIdentifier); ListMultimap<Long, ShardMetadata> tableShards = Multimaps.index(allShards, ShardMetadata::getTableId); for (Entry<Long, List<ShardMetadata>> entry : Multimaps.asMap(tableShards).entrySet()) { long tableId = entry.getKey(); if (!metadataDao.isCompactionEligible(tableId)) { continue; }/*from www. j a v a 2 s . c om*/ List<ShardMetadata> shards = entry.getValue(); Collection<OrganizationSet> organizationSets = filterAndCreateCompactionSets(tableId, shards); log.info("Created %s organization set(s) for table ID %s", organizationSets.size(), tableId); for (OrganizationSet set : organizationSets) { organizer.enqueue(set); } } }
From source file:de.bund.bfr.knime.nls.NlsUtils.java
public static Map<String, List<Double>> getVariableValues(BufferedDataTable table, String id, Function f, Map<String, Double> fixed) { ListMultimap<String, Double> values = ArrayListMultimap.create(); for (DataRow row : getRowsById(table, id)) { Map<String, Double> newValues = new LinkedHashMap<>(); for (String var : f.getVariables()) { newValues.put(var, IO.getDouble(row.getCell(table.getSpec().findColumnIndex(var)))); }//from w w w. ja v a2 s . c o m if (newValues.values().stream().allMatch(v -> v != null && Double.isFinite(v)) && fixed.entrySet().stream().allMatch(e -> e.getValue().equals(newValues.get(e.getKey())))) { newValues.forEach((var, value) -> values.put(var, value)); } } return Multimaps.asMap(values); }
From source file:de.bund.bfr.knime.pmm.common.XLSReader.java
public Map<String, KnimeTuple> getTimeSeriesTuples(File file, String sheet, Map<String, Object> columnMappings, String timeUnit, String concentrationUnit, String agentColumnName, Map<String, AgentXml> agentMappings, String matrixColumnName, Map<String, MatrixXml> matrixMappings, boolean preserveIds, List<Integer> usedIds) throws Exception { Workbook wb = getWorkbook(file);//from w w w. ja v a 2s .c o m Sheet s = wb.getSheet(sheet); warnings.clear(); evaluator = wb.getCreationHelper().createFormulaEvaluator(); if (s == null) { throw new Exception("Sheet not found"); } Map<String, KnimeTuple> tuples = new LinkedHashMap<>(); Map<String, Integer> columns = getColumns(s); Map<String, Integer> miscColumns = new LinkedHashMap<>(); Integer idColumn = null; Integer commentColumn = null; Integer timeColumn = null; Integer logcColumn = null; Integer stdDevColumn = null; Integer nMeasureColumn = null; Integer agentDetailsColumn = null; Integer matrixDetailsColumn = null; Integer agentColumn = null; Integer matrixColumn = null; String timeColumnName = null; String logcColumnName = null; String stdDevColumnName = null; String nMeasureColumnName = null; if (agentColumnName != null) { agentColumn = columns.get(agentColumnName); } if (matrixColumnName != null) { matrixColumn = columns.get(matrixColumnName); } for (String column : columns.keySet()) { if (columnMappings.containsKey(column)) { Object mapping = columnMappings.get(column); if (mapping instanceof MiscXml) { miscColumns.put(column, columns.get(column)); } else if (mapping.equals(ID_COLUMN)) { idColumn = columns.get(column); } else if (mapping.equals(MdInfoXml.ATT_COMMENT)) { commentColumn = columns.get(column); } else if (mapping.equals(AttributeUtilities.TIME)) { timeColumn = columns.get(column); timeColumnName = column; } else if (mapping.equals(AttributeUtilities.CONCENTRATION)) { logcColumn = columns.get(column); logcColumnName = column; } else if (mapping.equals(XLSReader.CONCENTRATION_STDDEV_COLUMN)) { stdDevColumn = columns.get(column); stdDevColumnName = column; } else if (mapping.equals(XLSReader.CONCENTRATION_MEASURE_NUMBER)) { nMeasureColumn = columns.get(column); nMeasureColumnName = column; } else if (mapping.equals(AttributeUtilities.AGENT_DETAILS)) { agentDetailsColumn = columns.get(column); } else if (mapping.equals(AttributeUtilities.MATRIX_DETAILS)) { matrixDetailsColumn = columns.get(column); } } } List<Integer> newIds = new ArrayList<>(); ListMultimap<String, Row> rowsById = LinkedListMultimap.create(); if (idColumn != null) { for (int i = 1; !isEndOfFile(s, i); i++) { Row row = s.getRow(i); Cell idCell = row.getCell(idColumn); if (hasData(idCell)) { rowsById.put(getData(idCell), row); } } } for (Map.Entry<String, List<Row>> entry : Multimaps.asMap(rowsById).entrySet()) { KnimeTuple tuple = new KnimeTuple(SchemaFactory.createDataSchema()); PmmXmlDoc timeSeriesXml = new PmmXmlDoc(); String idString = entry.getKey(); Row firstRow = entry.getValue().get(0); Cell commentCell = null; Cell agentDetailsCell = null; Cell matrixDetailsCell = null; Cell agentCell = null; Cell matrixCell = null; if (commentColumn != null) { commentCell = firstRow.getCell(commentColumn); } if (agentDetailsColumn != null) { agentDetailsCell = firstRow.getCell(agentDetailsColumn); } if (matrixDetailsColumn != null) { matrixDetailsCell = firstRow.getCell(matrixDetailsColumn); } if (agentColumn != null) { agentCell = firstRow.getCell(agentColumn); } if (matrixColumn != null) { matrixCell = firstRow.getCell(matrixColumn); } int id; if (preserveIds && !usedIds.isEmpty()) { id = usedIds.remove(0); } else { id = MathUtilities.getRandomNegativeInt(); } newIds.add(id); tuple = new KnimeTuple(SchemaFactory.createDataSchema()); tuple.setValue(TimeSeriesSchema.ATT_COMBASEID, idString); tuple.setValue(TimeSeriesSchema.ATT_CONDID, id); timeSeriesXml = new PmmXmlDoc(); PmmXmlDoc dataInfo = new PmmXmlDoc(); PmmXmlDoc agentXml = new PmmXmlDoc(); PmmXmlDoc matrixXml = new PmmXmlDoc(); if (commentCell != null) { dataInfo.add(new MdInfoXml(null, null, getData(commentCell), null, null)); } else { dataInfo.add(new MdInfoXml(null, null, null, null, null)); } if (hasData(agentCell) && agentMappings.get(getData(agentCell)) != null) { agentXml.add(agentMappings.get(getData(agentCell))); } else { agentXml.add(new AgentXml()); } if (hasData(matrixCell) && matrixMappings.get(getData(matrixCell)) != null) { matrixXml.add(matrixMappings.get(getData(matrixCell))); } else { matrixXml.add(new MatrixXml()); } if (hasData(agentDetailsCell)) { ((AgentXml) agentXml.get(0)).setDetail(getData(agentDetailsCell)); } if (hasData(matrixDetailsCell)) { ((MatrixXml) matrixXml.get(0)).setDetail(getData(matrixDetailsCell)); } tuple.setValue(TimeSeriesSchema.ATT_MDINFO, dataInfo); tuple.setValue(TimeSeriesSchema.ATT_AGENT, agentXml); tuple.setValue(TimeSeriesSchema.ATT_MATRIX, matrixXml); PmmXmlDoc miscXML = new PmmXmlDoc(); for (String column : miscColumns.keySet()) { MiscXml misc = (MiscXml) columnMappings.get(column); Cell cell = firstRow.getCell(miscColumns.get(column)); if (hasData(cell)) { try { misc.setValue(Double.parseDouble(getData(cell).replace(",", "."))); } catch (NumberFormatException e) { warnings.add(column + " value in row " + (firstRow.getRowNum() + 1) + " is not valid (" + getData(cell) + ")"); misc.setValue(null); } } else { misc.setValue(null); } misc.setOrigUnit(misc.getUnit()); miscXML.add(misc); } tuple.setValue(TimeSeriesSchema.ATT_MISC, miscXML); for (Row row : entry.getValue()) { Cell timeCell = null; Cell logcCell = null; Cell stdDevCell = null; Cell nMeasureCell = null; if (timeColumn != null) { timeCell = row.getCell(timeColumn); } if (logcColumn != null) { logcCell = row.getCell(logcColumn); } if (stdDevColumn != null) { stdDevCell = row.getCell(stdDevColumn); } if (nMeasureColumn != null) { nMeasureCell = row.getCell(nMeasureColumn); } Double time = null; Double logc = null; Double stdDev = null; Integer nMeasure = null; if (hasData(timeCell)) { try { time = Double.parseDouble(getData(timeCell).replace(",", ".")); } catch (NumberFormatException e) { warnings.add(timeColumnName + " value in row " + (row.getRowNum() + 1) + " is not valid (" + getData(timeCell) + ")"); } } else if (timeColumn != null) { warnings.add(timeColumnName + " value in row " + (row.getRowNum() + 1) + " is missing"); } if (hasData(logcCell)) { try { logc = Double.parseDouble(getData(logcCell).replace(",", ".")); } catch (NumberFormatException e) { warnings.add(logcColumnName + " value in row " + (row.getRowNum() + 1) + " is not valid (" + getData(logcCell) + ")"); } } else if (logcColumn != null) { warnings.add(logcColumnName + " value in row " + (row.getRowNum() + 1) + " is missing"); } if (hasData(stdDevCell)) { try { stdDev = Double.parseDouble(getData(stdDevCell).replace(",", ".")); } catch (NumberFormatException e) { warnings.add(stdDevColumnName + " value in row " + (row.getRowNum() + 1) + " is not valid (" + getData(stdDevCell) + ")"); } } else if (stdDevColumn != null) { warnings.add(stdDevColumnName + " value in row " + (row.getRowNum() + 1) + " is missing"); } if (hasData(nMeasureCell)) { try { String number = getData(nMeasureCell).replace(",", "."); if (number.contains(".")) { number = number.substring(0, number.indexOf(".")); } nMeasure = Integer.parseInt(number); } catch (NumberFormatException e) { warnings.add(nMeasureColumnName + " value in row " + (row.getRowNum() + 1) + " is not valid (" + getData(nMeasureCell) + ")"); } } else if (nMeasureColumn != null) { warnings.add(nMeasureColumnName + " value in row " + (row.getRowNum() + 1) + " is missing"); } for (String column : miscColumns.keySet()) { PmmXmlDoc misc = tuple.getPmmXml(TimeSeriesSchema.ATT_MISC); Cell cell = row.getCell(miscColumns.get(column)); if (hasData(cell)) { try { String param = ((MiscXml) columnMappings.get(column)).getName(); double value = Double.parseDouble(getData(cell).replace(",", ".")); if (!hasSameValue(param, value, misc)) { warnings.add("Variable conditions cannot be imported: " + "Only first value for " + column + " is used"); } } catch (NumberFormatException e) { } } } timeSeriesXml .add(new TimeSeriesXml(null, time, timeUnit, logc, concentrationUnit, stdDev, nMeasure)); } tuple.setValue(TimeSeriesSchema.ATT_TIMESERIES, timeSeriesXml); tuples.put(idString, tuple); } usedIds.clear(); usedIds.addAll(newIds); return tuples; }
From source file:com.google.cloud.pubsub.AckDeadlineRenewer.java
private void renewAckDeadlines() { ListMultimap<String, String> messagesToRenewNext = LinkedListMultimap.create(); // At every activation we renew all ack deadlines that will expire in the following // RENEW_THRESHOLD_MILLIS long threshold = clock.millis() + RENEW_THRESHOLD_MILLIS; Message message;/*from ww w . j a v a 2 s .c o m*/ while ((message = nextMessageToRenew(threshold)) != null) { // If the expected deadline is null the message was removed and we must ignore it, otherwise // we renew its ack deadline if (message.expectedDeadline() != null) { messagesToRenewNext.put(message.messageId().subscription(), message.messageId().ackId()); } } for (Map.Entry<String, List<String>> entry : Multimaps.asMap(messagesToRenewNext).entrySet()) { // We send all ack deadline renewals for a subscription pubsub.modifyAckDeadlineAsync(entry.getKey(), MIN_DEADLINE_MILLIS, TimeUnit.MILLISECONDS, entry.getValue()); } unsetAndScheduleNextRenewal(); }