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.googlesource.gerrit.plugins.examples.deployedonincludedinextension.DeployedOnIncludedInExtension.java

@Override
public ListMultimap<String, String> getIncludedIn(String project, String commit, Collection<String> tags,
        Collection<String> branches) {
    ListMultimap<String, String> m = MultimapBuilder.hashKeys().arrayListValues().build();
    m.put(PROD, "A");
    m.put(PROD, "B");
    m.put(PROD, "C");
    m.put(STAGING, "X");
    m.put(STAGING, "Y");
    m.put(STAGING, "Z");
    return m;/*w  w  w  . j av a 2 s. c  o  m*/
}

From source file:com.google.gerrit.server.config.TrackingFooters.java

public ListMultimap<String, String> extract(List<FooterLine> lines) {
    ListMultimap<String, String> r = MultimapBuilder.hashKeys().arrayListValues().build();
    if (lines == null) {
        return r;
    }//ww  w . j a v a  2 s  . com

    for (FooterLine footer : lines) {
        for (TrackingFooter config : trackingFooters) {
            if (footer.matches(config.footerKey())) {
                Matcher m = config.match().matcher(footer.getValue());
                while (m.find()) {
                    String id = m.groupCount() > 0 ? m.group(1) : m.group();
                    if (!id.isEmpty()) {
                        r.put(config.system(), id);
                    }
                }
            }
        }
    }
    return r;
}

From source file:org.chaston.oakfunds.storage.RecordTypeRegistryImpl.java

@Inject
RecordTypeRegistryImpl(Set<RecordType> recordTypes) {
    Map<String, RecordType> recordTypesBuilder = new HashMap<>();
    Map<String, RecordValidator> recordValidatorsBuilder = new HashMap<>();
    Multimap<String, RecordType> assignableRecordTypesBuilder = MultimapBuilder.hashKeys().hashSetValues()
            .build();/* w w w.ja va 2  s  .co m*/
    for (RecordType recordType : recordTypes) {
        if (recordTypesBuilder.containsKey(recordType.getName())) {
            throw new IllegalStateException(
                    "RecordType " + recordType.getName() + " was bound more than once.");
        }
        recordTypesBuilder.put(recordType.getName(), recordType);
        recordValidatorsBuilder.put(recordType.getName(), new RecordValidator(recordType));
        assignableRecordTypesBuilder.put(recordType.getName(), recordType);
        RecordType parentType = recordType.getParentType();
        while (parentType != null) {
            assignableRecordTypesBuilder.put(parentType.getName(), recordType);
            parentType = parentType.getParentType();
        }
    }
    this.recordTypes = ImmutableMap.copyOf(recordTypesBuilder);
    this.recordValidators = ImmutableMap.copyOf(recordValidatorsBuilder);
    this.assignableRecordTypes = ImmutableMultimap.copyOf(assignableRecordTypesBuilder);
}

From source file:com.google.template.soy.internal.proto.Field.java

/** Returns the set of fields indexed by soy accessor name for the given type. */
public static <T extends Field> ImmutableMap<String, T> getFieldsForType(Descriptor descriptor,
        Set<FieldDescriptor> extensions, Factory<T> factory) {
    ImmutableMap.Builder<String, T> fields = ImmutableMap.builder();
    for (FieldDescriptor fieldDescriptor : descriptor.getFields()) {
        if (ProtoUtils.shouldJsIgnoreField(fieldDescriptor)) {
            continue;
        }//  w w w.  j  a v  a 2 s  .  co  m
        T field = factory.create(fieldDescriptor);
        fields.put(field.getName(), field);
    }

    SetMultimap<String, T> extensionsBySoyName = MultimapBuilder.hashKeys().hashSetValues().build();
    for (FieldDescriptor extension : extensions) {
        T field = factory.create(extension);
        extensionsBySoyName.put(field.getName(), field);
    }

    for (Map.Entry<String, Set<T>> group : Multimaps.asMap(extensionsBySoyName).entrySet()) {
        Set<T> ambiguousFields = group.getValue();
        String fieldName = group.getKey();
        if (ambiguousFields.size() == 1) {
            fields.put(fieldName, Iterables.getOnlyElement(ambiguousFields));
        } else {
            T value = factory.createAmbiguousFieldSet(ambiguousFields);
            logger.severe("Proto " + descriptor.getFullName() + " has multiple extensions with the name \""
                    + fieldName + "\": " + fullFieldNames(ambiguousFields)
                    + "\nThis field will not be accessible from soy");
            fields.put(fieldName, value);
        }
    }

    return fields.build();
}

From source file:com.facebook.buck.apple.clang.VFSOverlay.java

@JsonProperty("roots")
private ImmutableList<VirtualDirectory> computeRoots() {
    Multimap<Path, Pair<Path, Path>> byParent = MultimapBuilder.hashKeys().hashSetValues().build();
    overlays.forEach((virtual, real) -> {
        byParent.put(virtual.getParent(), new Pair<>(virtual.getFileName(), real));
    });//from   w  w w  .  j  a va2  s.co m
    return byParent.asMap().entrySet().stream()
            .map(e -> new VirtualDirectory(e.getKey(),
                    e.getValue().stream().map(x -> new VirtualFile(x.getFirst(), x.getSecond()))
                            .collect(ImmutableList.toImmutableList())))
            .collect(ImmutableList.toImmutableList());
}

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

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    ListMultimap<Account.Id, Change.Id> imports = MultimapBuilder.hashKeys().arrayListValues().build();
    try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
            ResultSet rs = stmt.executeQuery("SELECT account_id, change_id FROM starred_changes")) {
        while (rs.next()) {
            Account.Id accountId = new Account.Id(rs.getInt(1));
            Change.Id changeId = new Change.Id(rs.getInt(2));
            imports.put(accountId, changeId);
        }/*ww  w .j a va2  s  .c o m*/
    }

    if (imports.isEmpty()) {
        return;
    }

    try (Repository git = repoManager.openRepository(allUsersName); RevWalk rw = new RevWalk(git)) {
        BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
        ObjectId id = StarredChangesUtil.writeLabels(git, StarredChangesUtil.DEFAULT_LABELS);
        for (Map.Entry<Account.Id, Change.Id> e : imports.entries()) {
            bru.addCommand(new ReceiveCommand(ObjectId.zeroId(), id,
                    RefNames.refsStarredChanges(e.getValue(), e.getKey())));
        }
        bru.execute(rw, new TextProgressMonitor());
    } catch (IOException ex) {
        throw new OrmException(ex);
    }
}

From source file:com.google.template.soy.types.proto.SoyProtoType.java

SoyProtoType(SoyTypeRegistry typeRegistry, Descriptor descriptor, Set<FieldDescriptor> extensions) {
    this.typeDescriptor = descriptor;

    ImmutableMap.Builder<String, Field> fields = ImmutableMap.builder();
    for (FieldDescriptor fieldDescriptor : descriptor.getFields()) {
        if (Protos.shouldJsIgnoreField(fieldDescriptor)) {
            continue;
        }/*  w w  w.  j  a  v  a2 s.  c  o m*/
        NormalField field = new NormalField(typeRegistry, fieldDescriptor);
        fields.put(field.getName(), field);
    }

    SetMultimap<String, ExtensionField> extensionsBySoyName = MultimapBuilder.hashKeys().hashSetValues()
            .build();
    for (FieldDescriptor extension : extensions) {
        ExtensionField field = new ExtensionField(typeRegistry, extension);
        extensionsBySoyName.put(field.getName(), field);
    }

    for (Map.Entry<String, Set<ExtensionField>> group : Multimaps.asMap(extensionsBySoyName).entrySet()) {
        String fieldName = group.getKey();
        Set<ExtensionField> ambiguousFields = group.getValue();
        if (ambiguousFields.size() == 1) {
            fields.put(fieldName, Iterables.getOnlyElement(ambiguousFields));
        } else {
            AmbiguousFieldSet value = new AmbiguousFieldSet(fieldName, ambiguousFields);

            logger.severe("Proto " + descriptor.getFullName() + " has multiple extensions with the name \""
                    + fieldName + "\": " + value.getFullFieldNames()
                    + "\nThis field will not be accessible from soy");
            fields.put(fieldName, value);
        }
    }

    this.fields = fields.build();
}

From source file:com.jcwhatever.nucleus.collections.timed.TimedSetMultimap.java

@Override
protected Multimap<K, V> createMultimap() {
    return MultimapBuilder.hashKeys().hashSetValues().build();
}

From source file:com.google.gerrit.server.notedb.rebuild.EventSorter.java

void sort() {
    // First pass: sort by natural order.
    PriorityQueue<Event> todo = new PriorityQueue<>(out);

    // Populate waiting map after initial sort to preserve natural order.
    waiting = MultimapBuilder.hashKeys().arrayListValues().build();
    deps = MultimapBuilder.hashKeys().hashSetValues().build();
    for (Event e : todo) {
        for (Event d : e.deps) {
            deps.put(e, d);//  ww w.  j  a  v a  2 s .c om
            waiting.put(d, e);
        }
    }

    // Second pass: enforce dependencies.
    int size = out.size();
    while (!todo.isEmpty()) {
        process(todo.remove(), todo);
    }
    checkState(sorted.size() == size, "event sort expected %s elements, got %s", size, sorted.size());

    // Modify out in-place a la Collections#sort.
    out.clear();
    out.addAll(sorted);
}

From source file:org.gradle.plugins.ide.idea.model.internal.IdeaDependenciesOptimizer.java

private Multimap<Object, GeneratedIdeaScope> collectScopesByDependency(Collection<Dependency> deps) {
    Multimap<Object, GeneratedIdeaScope> scopesByDependencyKey = MultimapBuilder.hashKeys()
            .enumSetValues(GeneratedIdeaScope.class).build();
    for (Dependency dep : deps) {
        scopesByDependencyKey.put(getKey(dep), GeneratedIdeaScope.nullSafeValueOf(dep.getScope()));
    }//from w w  w.  j  av a2 s .co  m
    return scopesByDependencyKey;
}