Example usage for com.google.common.collect Multimap put

List of usage examples for com.google.common.collect Multimap put

Introduction

In this page you can find the example usage for com.google.common.collect Multimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:com.zimbra.soap.voice.type.Attr.java

public static Multimap<String, String> toMultimap(List<? extends Attr> attrs) {
    Multimap<String, String> map = ArrayListMultimap.create();
    if (attrs != null) {
        for (Attr a : attrs) {
            map.put(a.getName(), a.getValue());
        }//from ww w.ja v  a  2 s  . com
    }
    return map;
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.yesno.scorers.ConceptOverlapYesNoScorer.java

private static void addAvgMaxMinFeatures(double[] values, ImmutableMap.Builder<String, Double> features,
        Multimap<String, Double> keyword2values, String keyword, String ctype) {
    double avg = DoubleStream.of(values).average().orElse(0);
    features.put(keyword + "-avg@" + ctype, avg);
    keyword2values.put(keyword + "-avg", avg);
    double max = DoubleStream.of(values).max().orElse(0);
    features.put(keyword + "-max@" + ctype, max);
    keyword2values.put(keyword + "-max", max);
    double min = DoubleStream.of(values).min().orElse(0);
    features.put(keyword + "-min@" + ctype, min);
    keyword2values.put(keyword + "-min", min);
}

From source file:com.zimbra.soap.type.KeyValuePair.java

public static Multimap<String, String> toMultimap(List<KeyValuePair> keyValuePairs) {
    Multimap<String, String> map = ArrayListMultimap.create();
    if (keyValuePairs != null) {
        for (KeyValuePair a : keyValuePairs) {
            map.put(a.getKey(), a.getValue());
        }// ww  w.j  a v  a 2s. co  m
    }
    return map;
}

From source file:com.palantir.atlasdb.keyvalue.partition.util.MergeResults.java

private static void mergeAllTimestampsMapIntoMap(Multimap<Cell, Long> globalResult,
        Multimap<Cell, Long> partResult) {
    for (Map.Entry<Cell, Long> e : partResult.entries()) {
        if (!globalResult.containsEntry(e.getKey(), e.getValue())) {
            globalResult.put(e.getKey(), e.getValue());
        }//from   w  w w. j  av a2 s . c om
    }
}

From source file:org.sonar.java.checks.MembersDifferOnlyByCapitalizationCheck.java

private static Multimap<String, Symbol> sortByName(List<Symbol> members) {
    Multimap<String, Symbol> membersByName = LinkedListMultimap.create();
    for (Symbol member : members) {
        membersByName.put(member.name(), member);
    }/*w  w  w.  j  a  v a 2 s  .c o  m*/
    return membersByName;
}

From source file:org.kiji.hive.utils.DataRequestOptimizer.java

/**
 * This method propogates the configuration of a family in a KijiDataRequest by replacing
 * it with a page of fully qualified columns with the same configuration.
 *
 * @param kijiDataRequest to use as a base.
 * @param qualifiersPage a page of fully qualified columns to replace families in the original
 *                        data request with.
 * @return A new data request with the appropriate families replaced with the page of fully
 * qualified columns.// ww  w.j a va  2  s.c o  m
 */
public static KijiDataRequest expandFamilyWithPagedQualifiers(KijiDataRequest kijiDataRequest,
        Collection<KijiColumnName> qualifiersPage) {

    // Organize the page of column names by family.
    Multimap<String, KijiColumnName> familyToQualifiersMap = ArrayListMultimap.create();
    for (KijiColumnName kijiColumnName : qualifiersPage) {
        familyToQualifiersMap.put(kijiColumnName.getFamily(), kijiColumnName);
    }

    // Build a new data request
    KijiDataRequestBuilder qualifierRequestBuilder = KijiDataRequest.builder();
    for (Column column : kijiDataRequest.getColumns()) {
        KijiColumnName kijiColumnName = column.getColumnName();
        if (kijiColumnName.isFullyQualified()
                || !familyToQualifiersMap.containsKey(kijiColumnName.getFamily())) {
            // If the column is fully qualified or it's not in qualifiersPage add this column as is.
            qualifierRequestBuilder.newColumnsDef(column);
        } else {
            // Iterate through the paged qualifiers and add
            for (KijiColumnName columnName : familyToQualifiersMap.get(kijiColumnName.getFamily())) {
                qualifierRequestBuilder.newColumnsDef().withFilter(column.getFilter())
                        .withPageSize(column.getPageSize()).withMaxVersions(column.getMaxVersions())
                        .add(columnName.getFamily(), columnName.getQualifier());
            }
        }
    }
    return qualifierRequestBuilder.build();
}

From source file:com.moz.fiji.hive.utils.DataRequestOptimizer.java

/**
 * This method propogates the configuration of a family in a FijiDataRequest by replacing
 * it with a page of fully qualified columns with the same configuration.
 *
 * @param fijiDataRequest to use as a base.
 * @param qualifiersPage a page of fully qualified columns to replace families in the original
 *                        data request with.
 * @return A new data request with the appropriate families replaced with the page of fully
 * qualified columns./*from   w  ww.j  ava 2  s  . co m*/
 */
public static FijiDataRequest expandFamilyWithPagedQualifiers(FijiDataRequest fijiDataRequest,
        Collection<FijiColumnName> qualifiersPage) {

    // Organize the page of column names by family.
    Multimap<String, FijiColumnName> familyToQualifiersMap = ArrayListMultimap.create();
    for (FijiColumnName fijiColumnName : qualifiersPage) {
        familyToQualifiersMap.put(fijiColumnName.getFamily(), fijiColumnName);
    }

    // Build a new data request
    FijiDataRequestBuilder qualifierRequestBuilder = FijiDataRequest.builder();
    for (Column column : fijiDataRequest.getColumns()) {
        FijiColumnName fijiColumnName = column.getColumnName();
        if (fijiColumnName.isFullyQualified()
                || !familyToQualifiersMap.containsKey(fijiColumnName.getFamily())) {
            // If the column is fully qualified or it's not in qualifiersPage add this column as is.
            qualifierRequestBuilder.newColumnsDef(column);
        } else {
            // Iterate through the paged qualifiers and add
            for (FijiColumnName columnName : familyToQualifiersMap.get(fijiColumnName.getFamily())) {
                qualifierRequestBuilder.newColumnsDef().withFilter(column.getFilter())
                        .withPageSize(column.getPageSize()).withMaxVersions(column.getMaxVersions())
                        .add(columnName.getFamily(), columnName.getQualifier());
            }
        }
    }
    return qualifierRequestBuilder.build();
}

From source file:org.deephacks.tools4j.config.internal.core.jpa.JpaBeanToBeanConverter.java

private static void collectRefs(JpaBean jpaBean, Multimap<BeanId, JpaBean> result) {
    if (result.containsKey(jpaBean.getId())) {
        // break redundant selects and circular recursion
        return;//from  w  ww.  j  a v  a2  s  . c  o m
    }

    for (JpaRef jpaRef : jpaBean.getReferences()) {
        result.put(jpaBean.getId(), jpaRef.getTargetBean());
        collectRefs(jpaRef.getTargetBean(), result);
    }
}

From source file:com.yammer.collections.azure.AzureTestUtil.java

@SafeVarargs
private static void setupRowQueries(String tableName, AzureTableRequestFactory azureTableRequestFactoryMock,
        AzureTableCloudClient azureTableCloudClientMock, Table.Cell<Bytes, Bytes, Bytes>... cells) {

    TableQuery<AzureEntity> emptyQueryMock = mock(TableQuery.class);
    when(azureTableRequestFactoryMock.selectAllForRow(anyString(), anyString())).thenReturn(emptyQueryMock);
    when(azureTableRequestFactoryMock.containsValueForRowQuery(anyString(), anyString(), anyString()))
            .thenReturn(emptyQueryMock);
    when(azureTableCloudClientMock.execute(emptyQueryMock)).thenReturn(Collections.<AzureEntity>emptyList());

    Multimap<Bytes, Table.Cell<Bytes, Bytes, Bytes>> rowCellMap = HashMultimap.create();
    for (Table.Cell<Bytes, Bytes, Bytes> cell : cells) {
        rowCellMap.put(cell.getRowKey(), cell);

        TableQuery<AzureEntity> rowValueQueryMock = mock(TableQuery.class);
        when(azureTableRequestFactoryMock.containsValueForRowQuery(tableName, encode(cell.getRowKey()),
                encode(cell.getValue()))).thenReturn(rowValueQueryMock);
        when(azureTableCloudClientMock.execute(rowValueQueryMock))
                .thenReturn(Collections.singletonList(ENCODE_CELL.apply(cell)));
    }//from  w  w w  . j a  v a2 s .c o m

    for (Map.Entry<Bytes, Collection<Table.Cell<Bytes, Bytes, Bytes>>> entry : rowCellMap.asMap().entrySet()) {
        // row query
        TableQuery<AzureEntity> rowQueryMock = mock(TableQuery.class);
        when(azureTableRequestFactoryMock.selectAllForRow(tableName, encode(entry.getKey())))
                .thenReturn(rowQueryMock);
        when(azureTableCloudClientMock.execute(rowQueryMock))
                .thenReturn(Collections2.transform(entry.getValue(), ENCODE_CELL));
    }
}

From source file:tterrag.potionapi.common.util.ReplaceUtil.java

public static void overwriteEntry(RegistryNamespaced registry, String name, Object object) {
    Object oldThing = registry.getObject(name);
    Repl.overwrite_do(registry, name, object, oldThing);
    Multimap<String, Object> reg = Repl.replacements.get(registry);
    if (reg == null) {
        Repl.replacements.put(registry, reg = ArrayListMultimap.create());
    }/* w  w  w.  j a  va  2  s. co  m*/
    if (!reg.containsKey(name)) {
        reg.put(name, oldThing);
    }
    reg.put(name, object);
    Repl.alterDelegateChain(registry, name, object);
}