List of usage examples for com.google.common.collect ImmutableListMultimap get
@Override
public ImmutableList<V> get(@Nullable K key)
From source file:com.google.gerrit.server.git.MergeSuperSet.java
private ChangeSet completeChangeSetWithoutTopic(ReviewDb db, ChangeSet changes, CurrentUser user) throws IOException, OrmException { Collection<ChangeData> visibleChanges = new ArrayList<>(); Collection<ChangeData> nonVisibleChanges = new ArrayList<>(); // For each target branch we run a separate rev walk to find open changes // reachable from changes already in the merge super set. ImmutableListMultimap<Branch.NameKey, ChangeData> bc = byBranch( Iterables.concat(changes.changes(), changes.nonVisibleChanges())); for (Branch.NameKey b : bc.keySet()) { OpenRepo or = getRepo(b.getParentKey()); List<RevCommit> visibleCommits = new ArrayList<>(); List<RevCommit> nonVisibleCommits = new ArrayList<>(); for (ChangeData cd : bc.get(b)) { checkState(cd.hasChangeControl(), "completeChangeSet forgot to set changeControl for current user" + " at ChangeData creation time"); boolean visible = changes.ids().contains(cd.getId()); if (visible && !cd.changeControl().isVisible(db, cd)) { // We thought the change was visible, but it isn't. // This can happen if the ACL changes during the // completeChangeSet computation, for example. visible = false;//from w w w. j a va 2s. c o m } Collection<RevCommit> toWalk = visible ? visibleCommits : nonVisibleCommits; // Pick a revision to use for traversal. If any of the patch sets // is visible, we use the most recent one. Otherwise, use the current // patch set. PatchSet ps = cd.currentPatchSet(); boolean visiblePatchSet = visible; if (!cd.changeControl().isPatchVisible(ps, cd)) { Iterable<PatchSet> visiblePatchSets = cd.visiblePatchSets(); if (Iterables.isEmpty(visiblePatchSets)) { visiblePatchSet = false; } else { ps = Iterables.getLast(visiblePatchSets); } } if (submitType(cd, ps, visiblePatchSet) == SubmitType.CHERRY_PICK) { if (visible) { visibleChanges.add(cd); } else { nonVisibleChanges.add(cd); } continue; } // Get the underlying git commit object String objIdStr = ps.getRevision().get(); RevCommit commit = or.rw.parseCommit(ObjectId.fromString(objIdStr)); // Always include the input, even if merged. This allows // SubmitStrategyOp to correct the situation later, assuming it gets // returned by byCommitsOnBranchNotMerged below. toWalk.add(commit); } Set<String> emptySet = Collections.emptySet(); Set<String> visibleHashes = walkChangesByHashes(visibleCommits, emptySet, or, b); List<ChangeData> cds = byCommitsOnBranchNotMerged(or, db, user, b, visibleHashes); for (ChangeData chd : cds) { chd.changeControl(user); visibleChanges.add(chd); } Set<String> nonVisibleHashes = walkChangesByHashes(nonVisibleCommits, visibleHashes, or, b); Iterables.addAll(nonVisibleChanges, byCommitsOnBranchNotMerged(or, db, user, b, nonVisibleHashes)); } return new ChangeSet(visibleChanges, nonVisibleChanges); }
From source file:com.google.api.server.spi.swagger.SwaggerGenerator.java
public Swagger writeSwagger(Iterable<ApiConfig> configs, boolean writeInternal, SwaggerContext context, SchemaRepository repo) throws ApiConfigException { ImmutableListMultimap<ApiKey, ? extends ApiConfig> configsByKey = FluentIterable.from(configs) .index(CONFIG_TO_ROOTLESS_KEY); Swagger swagger = new Swagger().produces("application/json").consumes("application/json") .scheme(context.scheme).host(context.hostname).basePath(context.basePath) .info(new Info().title(context.hostname).version(context.docVersion)); for (ApiKey apiKey : configsByKey.keySet()) { writeApi(apiKey, configsByKey.get(apiKey), swagger, context, writeInternal, repo); }/*from w w w .ja v a2s.c o m*/ return swagger; }
From source file:org.nla.tarotdroid.biz.computers.GuavaGameSetStatisticsComputer.java
/** * Returns for each bet the number of games this bet has been called. * @return for each bet the number of games this bet has been called as a Map<BetType, Double>. *//*from w w w . jav a 2 s .com*/ public Map<BetType, Integer> getBetCount() { // transform StandardBaseGame into BetType Function<StandardBaseGame, BetType> gameToBetTypeFunction = new Function<StandardBaseGame, BetType>() { @Override public BetType apply(final StandardBaseGame stdBaseGame) { return stdBaseGame.getBet().getBetType(); } }; // group standard games by bet type ImmutableListMultimap<BetType, StandardBaseGame> betTypeMultimap = Multimaps .index(this.gameSet.getStandardGames(), gameToBetTypeFunction); // build return object Map<BetType, Integer> toReturn = newHashMap(); for (BetType betType : betTypeMultimap.keys()) { toReturn.put(betType, betTypeMultimap.get(betType).size()); } this.betSeriesCount = toReturn.keySet().size(); return toReturn; }
From source file:org.nla.tarotdroid.biz.computers.GuavaGameSetStatisticsComputer.java
/** * TODO IMPROVE /*from w ww . j av a 2s. c om*/ * @return */ public Map<String, Integer> getFullBetCount() { // transform BaseGame into string description Function<BaseGame, String> gameToStringFunction = new Function<BaseGame, String>() { @Override public String apply(final BaseGame baseGame) { if (baseGame instanceof StandardBaseGame) { return "Standard"; } else if (baseGame instanceof BelgianBaseGame) { return "Belge"; } else if (baseGame instanceof PassedGame) { return "Passe"; } else if (baseGame instanceof PenaltyGame) { return "Fausse donne"; } else { throw new IllegalArgumentException("GetFullBetCount() Unknow game type"); } } }; // group games by string description ImmutableListMultimap<String, BaseGame> descriptionMultimap = Multimaps.index(this.gameSet.getGames(), gameToStringFunction); // build return object Map<String, Integer> toReturn = newHashMap(); for (String description : descriptionMultimap.keys()) { toReturn.put(description, descriptionMultimap.get(description).size()); } this.fullBetSeriesCount = toReturn.keySet().size(); return toReturn; }
From source file:org.nla.tarotdroid.biz.computers.GuavaGameSetStatisticsComputer.java
/** * Returns for each bet the number of games this king has been called. * @return for each bet the number of games this king has been called as a Map<KingType, Double>. */// w ww . j a va 2s . com public Map<KingType, Integer> getKingCount() { // transform StandardTarot5Game into BetType Function<StandardTarot5Game, KingType> gameToBetTypeFunction = new Function<StandardTarot5Game, KingType>() { @Override public KingType apply(final StandardTarot5Game stdBaseGame) { return stdBaseGame.getCalledKing().getKingType(); } }; // group standard games by bet type ImmutableListMultimap<KingType, StandardTarot5Game> kingTypeMultimap = Multimaps .index(this.gameSet.getStandard5Games(), gameToBetTypeFunction); // build return object Map<KingType, Integer> toReturn = newHashMap(); for (KingType kingType : kingTypeMultimap.keys()) { toReturn.put(kingType, kingTypeMultimap.get(kingType).size()); } this.kingSeriesCount = toReturn.keySet().size(); return toReturn; }
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 ww w . j av a2s . c o m 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; }
From source file:org.nla.tarotdroid.biz.computers.GuavaGameSetStatisticsComputer.java
/** * Returns for each player the number of games he has been called. * @return for each player the number of games he has been called as a Map<Player, Integer>. *//*from w w w. j a va2s . c o m*/ public Map<Player, Integer> getCalledCount() { // transform StandardBaseGame into Player Function<StandardTarot5Game, Player> gameSetToCalledPlayerFunction = new Function<StandardTarot5Game, Player>() { @Override public Player apply(final StandardTarot5Game stdBaseGame) { return stdBaseGame.getCalledPlayer(); } }; // group standard games by player ImmutableListMultimap<Player, StandardTarot5Game> calledPlayerMultimap = Multimaps .index(this.gameSet.getStandard5Games(), gameSetToCalledPlayerFunction); // build return object Map<Player, Integer> toReturn = newHashMap(); for (Player player : calledPlayerMultimap.keys()) { toReturn.put(player, calledPlayerMultimap.get(player).size()); } this.calledPlayerSeriesCount = toReturn.keySet().size(); return toReturn; }
From source file:com.google.api.server.spi.discovery.DiscoveryGenerator.java
public Result writeDiscovery(Iterable<ApiConfig> configs, DiscoveryContext context, SchemaRepository schemaRepository) { ImmutableListMultimap<ApiKey, ApiConfig> configsByKey = Multimaps.index(configs, new Function<ApiConfig, ApiKey>() { @Override/*from ww w . ja v a2 s .c o m*/ public ApiKey apply(ApiConfig config) { return config.getApiKey(); } }); ImmutableMap.Builder<ApiKey, RestDescription> builder = ImmutableMap.builder(); for (ApiKey apiKey : configsByKey.keySet()) { builder.put(apiKey, writeApi(apiKey, configsByKey.get(apiKey), context, schemaRepository)); } ImmutableMap<ApiKey, RestDescription> discoveryDocs = builder.build(); return Result.builder().setDiscoveryDocs(discoveryDocs) .setDirectory(generateDirectory(discoveryDocs, context)).build(); }
From source file:org.eclipse.sw360.components.summary.ComponentSummary.java
private Component makeExportSummary(Component document, ImmutableListMultimap<String, Release> fullReleases) { if (releaseRepository == null) { throw new IllegalStateException("Cannot make export summary without database connection!"); }/*from w ww . j a va2 s . c o m*/ Component copy = new Component(); copyField(document, copy, Component._Fields.ID); copyField(document, copy, Component._Fields.NAME); copyField(document, copy, Component._Fields.LANGUAGES); copyField(document, copy, Component._Fields.OPERATING_SYSTEMS); copyField(document, copy, Component._Fields.SOFTWARE_PLATFORMS); copyField(document, copy, Component._Fields.CREATED_BY); copyField(document, copy, Component._Fields.CREATED_ON); copyField(document, copy, Component._Fields.VENDOR_NAMES); final ImmutableList<Release> releases = fullReleases.get(document.getId()); for (Release release : releases) { Release exportRelease = new Release(); copyField(release, exportRelease, Release._Fields.NAME); copyField(release, exportRelease, Release._Fields.VERSION); exportRelease.setComponentId(""); copy.addToReleases(exportRelease); } return copy; }
From source file:dynamicrefactoring.domain.xml.writer.JDOMXMLRefactoringWriterImp.java
/** * Crea el elemento categorization que contiene las categorias a las que * pertenece una refactorizacion dentro de las clasificaciones existentes. * //from w ww .j a v a 2s .c o m * @param categoriesMapByParent * mapa que contiene como claves los nombres de las * clasificaciones y como valores las categorias a las que la * refactorizacion pertenece en esa clasificacion * @return elemento de jdom con la categorizacion de la refactorizacion */ private Element createCategorizationElement(ImmutableListMultimap<String, Category> categoriesMapByParent) { Element categorizationElement = new Element(XMLRefactoringReaderImp.CATEGORIZATION_ELEMENT); for (String classificationName : categoriesMapByParent.keySet()) { Element classificationElement = new Element(XMLRefactoringReaderImp.CLASSIFICATION_ELEMENT); classificationElement.setAttribute(XMLRefactoringReaderImp.CLASSIFICATION_NAME_ATTRIBUTE, classificationName); for (Category c : categoriesMapByParent.get(classificationName)) { Element categoryElement = new Element(XMLRefactoringReaderImp.CATEGORY_ELEMENT); categoryElement.addContent(c.getName()); classificationElement.addContent(categoryElement); } categorizationElement.addContent(classificationElement); } return categorizationElement; }