Example usage for com.google.common.collect MultimapBuilder hashKeys

List of usage examples for com.google.common.collect MultimapBuilder hashKeys

Introduction

In this page you can find the example usage for com.google.common.collect MultimapBuilder hashKeys.

Prototype

public static MultimapBuilderWithKeys<Object> hashKeys() 

Source Link

Document

Uses a HashMap to map keys to value collections.

Usage

From source file:com.google.gerrit.server.notedb.RevisionNoteBuilder.java

private ListMultimap<Integer, Comment> buildCommentMap() {
    ListMultimap<Integer, Comment> all = MultimapBuilder.hashKeys().arrayListValues().build();

    for (Comment c : baseComments) {
        if (!delete.contains(c.key) && !put.containsKey(c.key)) {
            all.put(c.key.patchSetId, c);
        }/*from w  ww .j  a  v a2 s .c o  m*/
    }
    for (Comment c : put.values()) {
        if (!delete.contains(c.key)) {
            all.put(c.key.patchSetId, c);
        }
    }
    return all;
}

From source file:com.google.gerrit.server.schema.Schema_108.java

private void updateProjectGroups(ReviewDb db, Repository repo, RevWalk rw, Set<Change.Id> changes, UpdateUI ui)
        throws OrmException, IOException {
    // Match sorting in ReceiveCommits.
    rw.reset();/*  w ww .  j ava  2  s .  c  o  m*/
    rw.sort(RevSort.TOPO);
    rw.sort(RevSort.REVERSE, true);

    RefDatabase refdb = repo.getRefDatabase();
    for (Ref ref : refdb.getRefs(Constants.R_HEADS).values()) {
        RevCommit c = maybeParseCommit(rw, ref.getObjectId(), ui);
        if (c != null) {
            rw.markUninteresting(c);
        }
    }

    ListMultimap<ObjectId, Ref> changeRefsBySha = MultimapBuilder.hashKeys().arrayListValues().build();
    ListMultimap<ObjectId, PatchSet.Id> patchSetsBySha = MultimapBuilder.hashKeys().arrayListValues().build();
    for (Ref ref : refdb.getRefs(RefNames.REFS_CHANGES).values()) {
        ObjectId id = ref.getObjectId();
        if (ref.getObjectId() == null) {
            continue;
        }
        id = id.copy();
        changeRefsBySha.put(id, ref);
        PatchSet.Id psId = PatchSet.Id.fromRef(ref.getName());
        if (psId != null && changes.contains(psId.getParentKey())) {
            patchSetsBySha.put(id, psId);
            RevCommit c = maybeParseCommit(rw, id, ui);
            if (c != null) {
                rw.markStart(c);
            }
        }
    }

    GroupCollector collector = GroupCollector.createForSchemaUpgradeOnly(changeRefsBySha, db);
    RevCommit c;
    while ((c = rw.next()) != null) {
        collector.visit(c);
    }

    updateGroups(db, collector, patchSetsBySha);
}

From source file:to.lean.tools.gmail.importer.gmail.Mailbox.java

Multimap<LocalMessage, Message> mapMessageIds(Iterable<LocalMessage> localMessages) {
    Multimap<LocalMessage, Message> results = MultimapBuilder.hashKeys().linkedListValues().build();

    Gmail gmail = gmailService.getServiceWithRetries();
    BatchRequest batch = gmail.batch();// w w  w  .  j  a  va2s  . com

    try {
        for (LocalMessage localMessage : localMessages) {
            gmail.users().messages().list(user.getEmailAddress())
                    .setQ("rfc822msgid:" + localMessage.getMessageId()).setFields("messages(id)")
                    .queue(batch, new JsonBatchCallback<ListMessagesResponse>() {
                        @Override
                        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders)
                                throws IOException {
                            System.err.println("Could not get message: " + localMessage.getMessageId());
                            System.err.println("  because: " + e);
                        }

                        @Override
                        public void onSuccess(ListMessagesResponse response, HttpHeaders responseHeaders)
                                throws IOException {
                            if (!response.isEmpty()) {
                                results.putAll(localMessage, response.getMessages());
                                System.err.println("For " + localMessage.getMessageId() + " got:");
                                response.getMessages().stream().forEach(
                                        message -> System.err.println("  message id: " + message.getId()));
                            }
                        }
                    });
        }
        if (batch.size() > 0) {
            batch.execute();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return results;
}

From source file:com.google.gerrit.server.change.WalkSorter.java

public Iterable<PatchSetData> sort(Iterable<ChangeData> in) throws OrmException, IOException {
    ListMultimap<Project.NameKey, ChangeData> byProject = MultimapBuilder.hashKeys().arrayListValues().build();
    for (ChangeData cd : in) {
        byProject.put(cd.change().getProject(), cd);
    }/*  ww w  .java 2s  .c o  m*/

    List<List<PatchSetData>> sortedByProject = new ArrayList<>(byProject.keySet().size());
    for (Map.Entry<Project.NameKey, Collection<ChangeData>> e : byProject.asMap().entrySet()) {
        sortedByProject.add(sortProject(e.getKey(), e.getValue()));
    }
    Collections.sort(sortedByProject, PROJECT_LIST_SORTER);
    return Iterables.concat(sortedByProject);
}

From source file:cherry.foundation.testtool.stub.StubConfigurer.java

private Multimap<String, Method> createMethodMap(Method[] methods) {
    Multimap<String, Method> map = MultimapBuilder.hashKeys().arrayListValues().build();
    for (Method m : methods) {
        map.put(getMethodDescription(m, false, false, true, false, false), m);
        map.put(getMethodDescription(m, false, false, true, true, false), m);
        map.put(getMethodDescription(m, false, false, true, true, true), m);
    }/*from   www. j a  va2  s  .c o m*/
    return map;
}

From source file:com.github.jsdossier.RenderTaskExecutor.java

/**
 * Submits tasks to render documentation for the given types.
 *
 * @param types the types to generate documentation for.
 * @return a self reference./*from   www  . ja v  a  2s  .  c o m*/
 */
public RenderTaskExecutor renderDocumentation(Iterable<NominalType> types) {
    // First, group all types by output paths, forced to lower case strings.
    // Any types with a collision must be rendered together to ensure no data mysteriously
    // disappears when running on a case insensitive file system (OSX is case-insensitive,
    // but case-preserving).
    Multimap<String, NominalType> normalizedPathToTypes = MultimapBuilder.hashKeys().arrayListValues().build();
    for (NominalType type : types) {
        String normalized = dfs.getPath(type).toAbsolutePath().normalize().toString().toLowerCase();
        normalizedPathToTypes.put(normalized, type);
    }

    for (String path : normalizedPathToTypes.keySet()) {
        RenderDocumentationTaskSupplier supplier = documentationTaskSupplierFactory
                .create(ImmutableList.copyOf(normalizedPathToTypes.get(path)));
        for (Callable<Path> task : supplier.get()) {
            submit(task);
        }
    }

    return this;
}

From source file:de.metas.ui.web.order.sales.purchasePlanning.process.WEBUI_SalesOrder_Apply_Availability_Row.java

private Multimap<PurchaseRow, PurchaseRow> extractLineRow2availabilityRows() {
    final PurchaseView view = getView();

    final ListMultimap<PurchaseRow, PurchaseRow> lineRow2AvailabilityRows = getSelectedRowIds().stream()

            .map(PurchaseRowId::fromDocumentId) // map to PurchaseRowIds
            .filter(PurchaseRowId::isAvailabilityRowId)
            .filter(availabilityRowId -> availabilityRowId.getAvailabilityType().equals(Type.AVAILABLE))

            .map(availabilityRowId -> ImmutablePair.of( // map to pair (availabilityRowId, availabilityRow)
                    availabilityRowId, view.getById(availabilityRowId.toDocumentId())))
            .filter(availabilityRowId2row -> isPositive(availabilityRowId2row.getRight().getQtyToPurchase()))

            .map(availabilityRowId2row -> ImmutablePair.of( // map to pair (lineRow, availabilityRow)
                    view.getById(availabilityRowId2row.getLeft().toLineRowId().toDocumentId()),
                    availabilityRowId2row.getRight()))
            .filter(lineRow2availabilityRow -> !lineRow2availabilityRow.getLeft().isProcessed())

            .collect(Multimaps.toMultimap(IPair::getLeft, IPair::getRight,
                    MultimapBuilder.hashKeys().arrayListValues()::build));

    return ImmutableMultimap.copyOf(lineRow2AvailabilityRows);
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableRuntimeContext.java

public static SortedSetMultimap<TableContext, TableRuntimeContext> buildSortedPartitionMap() {
    return MultimapBuilder.hashKeys()
            .treeSetValues(Comparator.comparingInt(TableRuntimeContext::getPartitionSequence)).build();
}

From source file:com.google.gerrit.server.index.change.StalenessChecker.java

public static SetMultimap<Project.NameKey, RefState> parseStates(Iterable<byte[]> states) {
    RefState.check(states != null, null);
    SetMultimap<Project.NameKey, RefState> result = MultimapBuilder.hashKeys().hashSetValues().build();
    for (byte[] b : states) {
        RefState.check(b != null, null);
        String s = new String(b, UTF_8);
        List<String> parts = Splitter.on(':').splitToList(s);
        RefState.check(parts.size() == 3 && !parts.get(0).isEmpty() && !parts.get(1).isEmpty(), s);
        result.put(new Project.NameKey(parts.get(0)), RefState.create(parts.get(1), parts.get(2)));
    }/*from  w w  w  .ja  v a 2  s  . c om*/
    return result;
}

From source file:com.google.gerrit.server.change.GetBlame.java

private List<BlameInfo> blame(ObjectId id, String path, Repository repository, RevWalk revWalk)
        throws IOException {
    ListMultimap<BlameInfo, RangeInfo> ranges = MultimapBuilder.hashKeys().arrayListValues().build();
    List<BlameInfo> result = new ArrayList<>();
    if (blameCache.findLastCommit(repository, id, path) == null) {
        return result;
    }/*from  w  w w.ja v a2  s . com*/

    List<Region> blameRegions = blameCache.get(repository, id, path);
    int from = 1;
    for (Region region : blameRegions) {
        RevCommit commit = revWalk.parseCommit(region.getSourceCommit());
        BlameInfo blameInfo = toBlameInfo(commit, region.getSourceAuthor());
        ranges.put(blameInfo, new RangeInfo(from, from + region.getCount() - 1));
        from += region.getCount();
    }

    for (BlameInfo key : ranges.keySet()) {
        key.ranges = ranges.get(key);
        result.add(key);
    }
    return result;
}