List of usage examples for com.google.common.collect Multimaps index
public static <K, V> ImmutableListMultimap<K, V> index(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:eu.itesla_project.ucte.network.ext.UcteNetworkExt.java
private void updateSubstation() { if (substations == null) { LOGGER.trace("Update substations..."); substations = new ArrayList<>(); node2voltageLevel = new HashMap<>(); UndirectedGraph<UcteNodeCode, Object> graph = createSubstationGraph(network); for (Set<UcteNodeCode> substationNodes : new ConnectivityInspector<>(graph).connectedSets()) { // the main node of the substation is not an xnode and the one with the highest voltage // level and the lowest busbar number. UcteNodeCode mainNode = substationNodes.stream().sorted((nodeCode1, nodeCode2) -> { if (nodeCode1.getUcteCountryCode() == UcteCountryCode.XX && nodeCode2.getUcteCountryCode() != UcteCountryCode.XX) { return 1; } else if (nodeCode1.getUcteCountryCode() != UcteCountryCode.XX && nodeCode2.getUcteCountryCode() == UcteCountryCode.XX) { return -1; } else { int c = Float.compare(nodeCode2.getVoltageLevelCode().getVoltageLevel(), nodeCode1.getVoltageLevelCode().getVoltageLevel()); if (c == 0) { c = nodeCode2.getBusbar().compareTo(nodeCode1.getBusbar()); }/*from w w w . j a v a2 s .c o m*/ return c; } }).findFirst().get(); Multimap<UcteVoltageLevelCode, UcteNodeCode> nodesByVoltageLevel = Multimaps.index(substationNodes, nodeCode -> { return nodeCode.getVoltageLevelCode(); }); String substationName = mainNode.getUcteCountryCode().getUcteCode() + mainNode.getGeographicalSpot(); List<UcteVoltageLevel> voltageLevels = new ArrayList<>(); UcteSubstation substation = new UcteSubstation(substationName, voltageLevels); substations.add(substation); LOGGER.trace("Define substation {}", substationName); for (Map.Entry<UcteVoltageLevelCode, Collection<UcteNodeCode>> entry : nodesByVoltageLevel.asMap() .entrySet()) { UcteVoltageLevelCode vlc = entry.getKey(); Collection<UcteNodeCode> voltageLevelNodes = entry.getValue(); String voltageLevelName = mainNode.getUcteCountryCode().getUcteCode() + mainNode.getGeographicalSpot() + vlc.ordinal(); UcteVoltageLevel voltageLevel = new UcteVoltageLevel(voltageLevelName, substation, voltageLevelNodes); voltageLevels.add(voltageLevel); for (UcteNodeCode voltageLevelNode : voltageLevelNodes) { node2voltageLevel.put(voltageLevelNode, voltageLevel); } LOGGER.trace("Define voltage level {} as a group of {} nodes", voltageLevelName, voltageLevelNodes); } } } }
From source file:org.caleydo.view.domino.api.model.typed.TypedSets.java
/** * convert a inhomogenous set of {@link TypedID} to a collection of {@link TypedSet}s * * @param set//from w ww . jav a2s . co m * @return */ public static Collection<TypedSet> toTypedSets(Set<TypedID> set) { if (set instanceof SingleTypedIDSet) { // its just a wrapper return Collections.singleton(((SingleTypedIDSet) set).getData()); } // compress to typed sets ListMultimap<IDType, TypedID> index = Multimaps.index(set, TypedID.TO_IDTYPE); Collection<TypedSet> new_ = new ArrayList<>(index.keySet().size()); for (IDType idType : index.keySet()) { List<TypedID> same = index.get(idType); new_.add(new TypedSet(ImmutableSet.copyOf(Lists.transform(same, TypedID.TO_ID)), idType)); } return new_; }
From source file:com.arpnetworking.tsdcore.sinks.MonitordSink.java
private Multimap<String, AggregatedData> prepareData(final PeriodicData periodicData) { // Transform the data list to a multimap by metric name // Ie, get all the statistics for a unique metric return Multimaps.index(periodicData.getData(), input -> input.getFQDSN().getService() + "_" + periodicData.getPeriod().toString(ISOPeriodFormat.standard()) + "_" + input.getFQDSN().getMetric() + "_" + periodicData.getDimensions().get("host") + "_" + input.getFQDSN().getCluster()); }
From source file:com.yodle.vantage.component.dao.IssueDao.java
public Map<Version, Collection<Issue>> getIssuesByDependenciesOf(String component, String version) { List<Map<String, Object>> rs = jdbcTemplate.queryForList( "MATCH (c_par:Component {name:{1}})<-[:VERSION_OF]-(v_par:Version {version:{2}})-[:DEPENDS_ON]->" + "(v:Version)<-[:PRECEDES|:AFFECTS*]-(i:Issue)" + "MATCH (v)-[:VERSION_OF]->(c:Component)" + "MATCH (i)-[:AFFECTS]->(av:Version)" + "WHERE NOT (v)<-[:PRECEDES|:FIXED_BY*]-(i) " + "OPTIONAL MATCH (i)-[:FIXED_BY]->(fv:Version)" + "RETURN v.version, c.name, i.id, i.level, i.message, av.version, fv.version", component, version);/*from w w w . j a v a 2 s.co m*/ ImmutableListMultimap<Version, Map<String, Object>> grouped = Multimaps.index(rs, (row -> new Version((String) row.get("c.name"), (String) row.get("v.version")))); return Multimaps.transformValues(grouped, this::toIssue).asMap(); }
From source file:net.bunselmeyer.mongo.maven.plugin.MigrateMojo.java
protected ImmutableListMultimap<MIGRATION_CHECK, MigrationDetails> buildStatusIndex( Set<Class<? extends Migration>> allMigrations) { Iterable<MigrationDetails> migrationStatus = Iterables.transform(allMigrations, new Function<Class<? extends Migration>, MigrationDetails>() { public MigrationDetails apply(Class<? extends Migration> input) { if (input == null) { return new MigrationDetails(MIGRATION_CHECK.ERROR, "Failed to load migration from classloader.", input); }/*from ww w. j a va 2s . c o m*/ Connection connection = input.getAnnotation(Connection.class); if (connection == null) { return new MigrationDetails(MIGRATION_CHECK.WARNING, "Migration does not have @Connection", input); } if (StringUtils.isBlank(connection.db())) { return new MigrationDetails(MIGRATION_CHECK.ERROR, "Empty db property in @Connection", input); } if (StringUtils.isBlank(connection.version())) { return new MigrationDetails(MIGRATION_CHECK.ERROR, "Empty version property in @Connection", input); } try { DateTime version = DateTime.parse(connection.version()); String host = StringUtils.isNotBlank(connection.host()) ? connection.host() : MigrateMojo.this.host; return version != null ? // new MigrationDetails(input, version, host, connection.db()) : // new MigrationDetails(MIGRATION_CHECK.ERROR, "Failed to parse @version to timestamp in @Connection", input); } catch (Exception e) { return new MigrationDetails(MIGRATION_CHECK.ERROR, "Failed to parse @version to timestamp in @Connection", input); } } }); return Multimaps.index(migrationStatus, new Function<MigrationDetails, MIGRATION_CHECK>() { public MIGRATION_CHECK apply(MigrationDetails input) { return input.status; } }); }
From source file:ru.org.linux.tag.TagPageController.java
private static ImmutableListMultimap<String, Topic> datePartition(Iterable<Topic> topics, final Function<Topic, DateTime> dateExtractor) { final DateMidnight startOfToday = new DateMidnight(); final DateMidnight startOfYesterday = startOfToday.minusDays(1); final DateMidnight startOfYear = startOfToday.withDayOfYear(1); return Multimaps.index(topics, new Function<Topic, String>() { @Override/*w ww . j a v a2s .c o m*/ public String apply(Topic input) { DateTime date = dateExtractor.apply(input); if (date.isAfter(startOfToday)) { return "?"; } else if (date.isAfter(startOfYesterday)) { return ""; } else if (date.isAfter(startOfYear)) { return THIS_YEAR_FORMAT.print(date); } else { return OLD_YEAR_FORMAT.print(date); } } }); }
From source file:com.github.jonross.seq4j.Seq.java
/** * Wraps {@link Multimaps#index(Iterator, Function); treating each element in the * sequence as a value, applies a function t determine the key and uses the * multimap to group all values with the same key. *///from w w w .java2s. c o m public <K> Multimap<K, T> groupBy(Function<? super T, K> f) { return Multimaps.index(this, f); }
From source file:com.b2international.snowowl.snomed.importer.rf2.terminology.ComponentLookup.java
private LongValueMap<String> getStorageKeys(final Collection<String> componentIds) throws IOException { return index.read(editingContext.getBranch(), new RevisionIndexRead<LongValueMap<String>>() { @Override//from w w w . j a v a 2 s.c o m public LongValueMap<String> execute(RevisionSearcher index) throws IOException { final LongValueMap<String> map = PrimitiveMaps .newObjectKeyLongOpenHashMapWithExpectedSize(componentIds.size()); // index componentIds by their category final Multimap<Class<? extends SnomedDocument>, String> idsByType = Multimaps.index(componentIds, id -> SnomedDocument.getType(SnomedIdentifiers.getComponentCategory(id))); for (Class<? extends SnomedDocument> type : idsByType.keySet()) { // execute queries for each type and based on the current clazz extract either refset or concept storage keys final Query<? extends SnomedDocument> query = Query.select(type) .where(SnomedDocument.Expressions.ids(componentIds)).limit(componentIds.size()).build(); final Hits<? extends SnomedDocument> hits = index.search(query); for (SnomedDocument doc : hits) { if (SnomedRefSet.class.isAssignableFrom(clazz)) { map.put(doc.getId(), ((SnomedConceptDocument) doc).getRefSetStorageKey()); } else { map.put(doc.getId(), doc.getStorageKey()); } } } return map; } }); }
From source file:com.qcadoo.mes.deviationCausesReporting.dataProvider.DeviationSummariesDataProvider.java
/** * Get detailed deviation summaries, matching given criteria. Resulting Multimap's keys will be sorted ascending. * //from w ww . jav a2 s . c om * @param criteria * restrictions for deviations to be summarized. * @return Multimap containing deviation summaries, grouped by its reason (cause) type. Multimap's keys will be in ascending * order. */ public Multimap<String, DeviationSummary> getDeviationsByCauseType(final DeviationsReportCriteria criteria) { ImmutableList<DeviationSummary> flatDeviationSummaries = FluentIterable .from(Arrays.asList(DeviationType.values())).transform(QUERY_FOR_DEVIATION_TYPE) .transformAndConcat(buildQueryExecutionFunc(getDataDefinition(), criteria)) .transform(BUILD_SUMMARY_POJO_FROM_PROJECTION) .toSortedList(DeviationCauseHolderComparators.BY_REASON_ASC); return Multimaps.index(flatDeviationSummaries, CAUSE_EXTRACTOR); }
From source file:org.nla.tarotdroid.biz.computers.GuavaGameSetStatisticsComputer.java
/** * Returns for each player the number of games he has been a leading player. * @return for each player the number of games he has been a leading player as a Map<Player, Integer>. *///from w w w.ja v a 2 s .c om public Map<Player, Integer> getLeadingCount() { // transform StandardBaseGame into Player Function<StandardBaseGame, Player> gameSetToLeadingPlayerFunction = new Function<StandardBaseGame, Player>() { @Override public Player apply(final StandardBaseGame stdBaseGame) { return stdBaseGame.getLeadingPlayer(); } }; // group standard games by player ImmutableListMultimap<Player, StandardBaseGame> leadingPlayerMultimap = Multimaps .index(this.gameSet.getStandardGames(), gameSetToLeadingPlayerFunction); // build return object Map<Player, Integer> toReturn = newHashMap(); for (Player player : leadingPlayerMultimap.keys()) { toReturn.put(player, leadingPlayerMultimap.get(player).size()); } this.leadingPlayerSeriesCount = toReturn.keySet().size(); return toReturn; }