Example usage for com.google.common.collect ImmutableMultimap.Builder put

List of usage examples for com.google.common.collect ImmutableMultimap.Builder put

Introduction

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

Prototype

@Deprecated
@Override
public boolean put(K key, V value) 

Source Link

Document

Guaranteed to throw an exception and leave the multimap unmodified.

Usage

From source file:io.prestosql.plugin.raptor.legacy.storage.organization.ShardOrganizerUtil.java

public static Collection<Collection<ShardIndexInfo>> getShardsByDaysBuckets(Table tableInfo,
        Collection<ShardIndexInfo> shards, TemporalFunction temporalFunction) {
    if (shards.isEmpty()) {
        return ImmutableList.of();
    }/*from   w  w  w  . j a v a  2  s . c  om*/

    // Neither bucketed nor temporal, no partitioning required
    if (!tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return ImmutableList.of(shards);
    }

    // if only bucketed, partition by bucket number
    if (tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return Multimaps.index(shards, shard -> shard.getBucketNumber().getAsInt()).asMap().values();
    }

    // if temporal, partition into days first
    ImmutableMultimap.Builder<Long, ShardIndexInfo> shardsByDaysBuilder = ImmutableMultimap.builder();
    shards.stream().filter(shard -> shard.getTemporalRange().isPresent()).forEach(shard -> {
        long day = temporalFunction.getDayFromRange(shard.getTemporalRange().get());
        shardsByDaysBuilder.put(day, shard);
    });

    Collection<Collection<ShardIndexInfo>> byDays = shardsByDaysBuilder.build().asMap().values();

    // if table is bucketed further partition by bucket number
    if (!tableInfo.getBucketCount().isPresent()) {
        return byDays;
    }

    ImmutableList.Builder<Collection<ShardIndexInfo>> sets = ImmutableList.builder();
    for (Collection<ShardIndexInfo> s : byDays) {
        sets.addAll(Multimaps.index(s, ShardIndexInfo::getBucketNumber).asMap().values());
    }
    return sets.build();
}

From source file:com.facebook.presto.raptor.storage.organization.ShardOrganizerUtil.java

public static Collection<Collection<ShardIndexInfo>> getShardsByDaysBuckets(Table tableInfo,
        Collection<ShardIndexInfo> shards) {
    // Neither bucketed nor temporal, no partitioning required
    if (!tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return ImmutableList.of(shards);
    }/*  ww w.j a v a  2  s  .  com*/

    // if only bucketed, partition by bucket number
    if (tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return Multimaps.index(shards, shard -> shard.getBucketNumber().getAsInt()).asMap().values();
    }

    // if temporal, partition into days first
    ImmutableMultimap.Builder<Long, ShardIndexInfo> shardsByDaysBuilder = ImmutableMultimap.builder();
    shards.stream().filter(shard -> shard.getTemporalRange().isPresent()).forEach(shard -> {
        long day = determineDay(shard.getTemporalRange().get());
        shardsByDaysBuilder.put(day, shard);
    });

    Collection<Collection<ShardIndexInfo>> byDays = shardsByDaysBuilder.build().asMap().values();

    // if table is bucketed further partition by bucket number
    if (!tableInfo.getBucketCount().isPresent()) {
        return byDays;
    }

    ImmutableList.Builder<Collection<ShardIndexInfo>> sets = ImmutableList.builder();
    for (Collection<ShardIndexInfo> s : byDays) {
        sets.addAll(Multimaps.index(s, ShardIndexInfo::getBucketNumber).asMap().values());
    }
    return sets.build();
}

From source file:io.leishvl.core.xml.GbSeqXmlBinder.java

/**
 * Infers the possible countries of the species from which the DNA sequence was obtained and 
 * returns a map of Java {@link Locale} where the key of the map is the GenBank field that was
 * used to infer the country. The country is inferred from the annotations of the GenBank file 
 * format, using the fields in the following order:
 * <ol>/* ww  w.  j a  v  a2  s .  c om*/
 * <li>If a country entry exists in the features of the file, then this is returned to 
 * the caller and no other check is performed;</li>
 * <li>Definition field;</li>
 * <li>Title field; or</li>
 * <li>Check PubMed title and abstract fields.</li>
 * </ol>
 * @param sequence - sequence to be analyzed
 * @return a map of Java {@link Locale} inferred from the input sequence, where the key of the map
 *         is the GenBank field used to infer the country.
 */
public static ImmutableMultimap<String, Locale> inferCountry(final GBSeq sequence) {
    checkArgument(sequence != null, "Uninitialized or invalid sequence");
    final ImmutableMultimap.Builder<String, Locale> builder = new ImmutableMultimap.Builder<>();
    // infer from features
    final String countryFeature = countryFeature(sequence);
    Locale locale = isNotBlank(countryFeature) ? countryFeatureToLocale(countryFeature) : null;
    if (locale != null) {
        builder.put("features", locale);
    } else {
        // infer from definition
        // TODO

        // infer from title
        // TODO

        // infer from PubMed title and abstract fields
        // TODO
    }
    return builder.build();
}

From source file:com.facebook.presto.raptor.storage.TemporalCompactionSetCreator.java

private static Multimap<Long, ShardMetadata> getShardsByDays(Set<ShardMetadata> shardMetadata, Type type) {
    // bucket shards by the start day
    ImmutableMultimap.Builder<Long, ShardMetadata> shardsByDays = ImmutableMultimap.builder();

    // skip shards that do not have temporal information
    shardMetadata.stream().filter(shard -> shard.getRangeStart().isPresent() && shard.getRangeEnd().isPresent())
            .forEach(shard -> {/*from  w ww .j  a  va  2 s  . com*/
                long day = determineDay(shard.getRangeStart().getAsLong(), shard.getRangeEnd().getAsLong(),
                        type);
                shardsByDays.put(day, shard);
            });
    return shardsByDays.build();
}

From source file:com.facebook.buck.apple.xcode.RuleDependencyFinder.java

/**
 * Create a map from targets to the tests that test them by examining
 * {@link com.facebook.buck.apple.IosTest#getSourceUnderTest()}.
 *//*w  w w. j a v  a 2s.co m*/
private static ImmutableMultimap<BuildRule, BuildRule> buildRuleToTestRulesMap(PartialGraph graph) {
    ImmutableMultimap.Builder<BuildRule, BuildRule> ruleToTestRulesBuilder = ImmutableMultimap.builder();
    for (BuildTarget target : graph.getTargets()) {
        BuildRule rule = graph.getDependencyGraph().findBuildRuleByTarget(target);
        if (rule.getType().equals(IosTestDescription.TYPE)) {
            IosTest testBuildable = (IosTest) Preconditions.checkNotNull(rule.getBuildable());
            for (BuildRule sourceRule : testBuildable.getSourceUnderTest()) {
                ruleToTestRulesBuilder.put(sourceRule, rule);
            }
        }
    }
    return ruleToTestRulesBuilder.build();
}

From source file:org.apache.beam.sdk.extensions.sql.impl.ScalarFunctionImpl.java

/** Creates {@link org.apache.calcite.schema.Function} for each method in a given class. */
public static ImmutableMultimap<String, Function> createAll(Class<?> clazz) {
    final ImmutableMultimap.Builder<String, Function> builder = ImmutableMultimap.builder();
    for (Method method : clazz.getMethods()) {
        if (method.getDeclaringClass() == Object.class) {
            continue;
        }//from  w  w w . j a  va  2s .co m
        if (!Modifier.isStatic(method.getModifiers()) && !classHasPublicZeroArgsConstructor(clazz)) {
            continue;
        }
        final Function function = create(method);
        builder.put(method.getName(), function);
    }
    return builder.build();
}

From source file:org.apache.beam.sdk.extensions.sql.impl.UdfImpl.java

/** Creates {@link org.apache.calcite.schema.ScalarFunction} for each method in a given class. */
public static ImmutableMultimap<String, ScalarFunction> createAll(Class<?> clazz) {
    final ImmutableMultimap.Builder<String, ScalarFunction> builder = ImmutableMultimap.builder();
    for (Method method : clazz.getMethods()) {
        if (method.getDeclaringClass() == Object.class) {
            continue;
        }//from  w  w w.j a va2s  . c  om
        if (!Modifier.isStatic(method.getModifiers()) && !classHasPublicZeroArgsConstructor(clazz)) {
            continue;
        }
        final ScalarFunction function = create(method);
        builder.put(method.getName(), function);
    }
    return builder.build();
}

From source file:eu.eubrazilcc.lvl.core.xml.GbSeqXmlBinder.java

/**
 * Infers the possible countries of the species from which the DNA sequence was obtained and 
 * returns a map of Java {@link Locale} where the key of the map is the GenBank field that was
 * used to infer the country. The country is inferred from the annotations of the GenBank file 
 * format, using the fields in the following order:
 * <ol>/*from www . ja v a  2  s. co  m*/
 * <li>If a country entry exists in the features of the file, then this is returned to 
 * the caller and no other check is performed;</li>
 * <li>Definition field;</li>
 * <li>Title field; or</li>
 * <li>Check PubMed title and abstract fields.</li>
 * </ol>
 * @param sequence - sequence to be analyzed
 * @return a map of Java {@link Locale} inferred from the input sequence, where the key of the map
 *         is the GenBank field used to infer the country.
 */
public static final ImmutableMultimap<String, Locale> inferCountry(final GBSeq sequence) {
    checkArgument(sequence != null, "Uninitialized or invalid sequence");
    final ImmutableMultimap.Builder<String, Locale> builder = new ImmutableMultimap.Builder<String, Locale>();
    // infer from features
    final String countryFeature = countryFeature(sequence);
    Locale locale = isNotBlank(countryFeature) ? countryFeatureToLocale(countryFeature) : null;
    if (locale != null) {
        builder.put("features", locale);
    } else {
        // infer from definition
        // TODO

        // infer from title
        // TODO

        // infer from PubMed title and abstract fields
        // TODO
    }
    return builder.build();
}

From source file:org.sonar.plugins.csharp.RoslynProfileExporter.java

static Multimap<String, RuleKey> activeRoslynRulesByPartialRepoKey(Iterable<RuleKey> activeRules) {
    ImmutableMultimap.Builder<String, RuleKey> builder = ImmutableMultimap.builder();

    for (RuleKey activeRule : activeRules) {
        if (activeRule.repository().startsWith(ROSLYN_REPOSITORY_PREFIX)) {
            String pluginKey = activeRule.repository().substring(ROSLYN_REPOSITORY_PREFIX.length());
            builder.put(pluginKey, activeRule);
        } else if (CSharpSonarRulesDefinition.REPOSITORY_KEY.equals(activeRule.repository())) {
            builder.put(SONARANALYZER_PARTIAL_REPO_KEY, activeRule);
        }//ww w. java 2s .co  m
    }

    return builder.build();
}

From source file:com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.java

/**
 * Computes the set of {@link Label}s corresponding to a set of Skylark {@link LoadStatement}s.
 *
 * @param imports a collection of Skylark {@link LoadStatement}s
 * @param containingFileLabel the {@link Label} of the file containing the load statements
 * @return an {@link ImmutableMap} which maps a {@link String} used in the load statement to its
 *     corresponding {@Label}. Returns {@code null} if any Skyframe dependencies are unavailable.
 * @throws SkylarkImportFailedException if no package can be found that contains the loaded file
 *///from www  . ja  v  a  2s.c o  m
@Nullable
static ImmutableMap<String, Label> findLabelsForLoadStatements(ImmutableCollection<SkylarkImport> imports,
        Label containingFileLabel, Environment env) throws SkylarkImportFailedException, InterruptedException {
    Preconditions.checkArgument(!containingFileLabel.getPackageIdentifier().getRepository().isDefault());
    Map<String, Label> outputMap = Maps.newHashMapWithExpectedSize(imports.size());

    // Filter relative vs. absolute paths.
    ImmutableSet.Builder<PathFragment> absoluteImportsToLookup = new ImmutableSet.Builder<>();
    // We maintain a multimap from path fragments to their correspond import strings, to cover the
    // (unlikely) case where two distinct import strings generate the same path fragment.
    ImmutableMultimap.Builder<PathFragment, String> pathToImports = new ImmutableMultimap.Builder<>();
    for (SkylarkImport imp : imports) {
        if (imp.hasAbsolutePath()) {
            absoluteImportsToLookup.add(imp.getAbsolutePath());
            pathToImports.put(imp.getAbsolutePath(), imp.getImportString());
        } else {
            outputMap.put(imp.getImportString(), imp.getLabel(containingFileLabel));
        }
    }

    // Look up labels for absolute paths.
    ImmutableMap<PathFragment, Label> absoluteLabels = labelsForAbsoluteImports(absoluteImportsToLookup.build(),
            env);
    if (absoluteLabels == null) {
        return null;
    }
    for (Entry<PathFragment, Label> entry : absoluteLabels.entrySet()) {
        PathFragment currPath = entry.getKey();
        Label currLabel = entry.getValue();
        for (String importString : pathToImports.build().get(currPath)) {
            outputMap.put(importString, currLabel);
        }
    }

    ImmutableMap<String, Label> immutableOutputMap = ImmutableMap.copyOf(outputMap);
    return immutableOutputMap;
}