Example usage for com.google.common.collect ImmutableMultimap builder

List of usage examples for com.google.common.collect ImmutableMultimap builder

Introduction

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

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Document

Returns a new builder.

Usage

From source file:com.github.explainable.benchmark.preparedstmt.PrepStmtBenchmark2.java

public static void main(String[] args) throws Exception {
    List<View> preparedStmts = SecurityViewReader.readViews(PREPARED_STATEMENT_FILE, FBFlatSchema.SCHEMA);

    List<String> sqlPreparedStmts = SecurityViewReader.readSqlViews(PREPARED_STATEMENT_FILE,
            FBFlatSchema.SCHEMA);//w  w w  .  j av  a 2  s . c o  m

    List<View> securityViews = SecurityViewReader.readViews(SECURITY_VIEW_FILE, FBFlatSchema.SCHEMA);

    System.out.format("# Name: %s%n", PrepStmtBenchmark2.class.getName());
    System.out.format("# Date: %s%n", new Date());
    System.out.format("# Host: %s%n", InetAddress.getLocalHost().getHostName());

    SqlExecGenerator.Builder gen = SqlExecGenerator.builder();
    ImmutableMultimap.Builder<String, View> preparedViewsBuilder = ImmutableMultimap.builder();

    CCJSqlParserManager parser = new CCJSqlParserManager();
    ViewExtractionPipeline extractor = ViewExtractionPipeline.create(FBFlatSchema.SCHEMA);

    for (int i = 0; i < preparedStmts.size(); i++) {
        String viewName = "V" + (i + 1);

        String stmt = sqlPreparedStmts.get(i);
        SqlExecTemplate.Builder builder = SqlExecTemplate.builder(viewName);
        for (int argIndex = 1; stmt.contains("\'$" + argIndex + "\'"); argIndex++) {
            builder.addArg(CONSTANTS);
        }

        gen.add(builder.build());

        Select parsedStmt = (Select) parser.parse(new StringReader(stmt));
        List<View> extractedViews = extractor.execute(parsedStmt);
        preparedViewsBuilder.putAll(viewName, extractedViews);
    }

    ImmutableMultimap<String, View> preparedViews = preparedViewsBuilder.build();
    SqlExecGenerator execGenerator = gen.build();

    for (BenchmarkStage lastStage : ACTIVE_STAGES) {
        System.out.format("%s = [%n", lastStage);
        for (int threadCount = MIN_THREAD_COUNT; threadCount <= MAX_THREAD_COUNT; threadCount++) {
            System.out.print("\t[ ");
            System.out.flush();

            for (int trialNum = 0; trialNum <= TRIAL_COUNT; trialNum++) {
                CountDownLatch doneSignal = new CountDownLatch(threadCount);
                long startTimeMillis = System.currentTimeMillis();

                for (int i = 0; i < threadCount; i++) {
                    new Thread(new PrepStmtBenchmark2(securityViews, preparedViews, execGenerator, doneSignal,
                            BENCHMARK_TRIALS / threadCount, lastStage)).start();
                }

                doneSignal.await();
                long endTimeMillis = System.currentTimeMillis();

                if (trialNum > 0) {
                    System.out.format("%.2f", .001 * (endTimeMillis - startTimeMillis));
                    if (trialNum < TRIAL_COUNT) {
                        System.out.print(", ");
                    }
                    System.out.flush();
                }
            }
            System.out.format(" ], # %d thread(s)%n", threadCount);
        }
        System.out.println("]");
    }
}

From source file:com.google.idea.blaze.base.rulemaps.ReverseDependencyMap.java

public static ImmutableMultimap<Label, Label> createRdepsMap(Map<Label, RuleIdeInfo> ruleMap) {
    ImmutableMultimap.Builder<Label, Label> builder = ImmutableMultimap.builder();
    for (Map.Entry<Label, RuleIdeInfo> entry : ruleMap.entrySet()) {
        Label label = entry.getKey();
        RuleIdeInfo ruleIdeInfo = entry.getValue();
        for (Label dep : Iterables.concat(ruleIdeInfo.dependencies, ruleIdeInfo.runtimeDeps)) {
            if (ruleMap.containsKey(dep)) {
                builder.put(dep, label);
            }/*from  w w  w. j av  a2 s. c  om*/
        }
    }
    return builder.build();
}

From source file:com.google.idea.blaze.base.targetmaps.ReverseDependencyMap.java

public static ImmutableMultimap<TargetKey, TargetKey> createRdepsMap(TargetMap targetMap) {
    ImmutableMultimap.Builder<TargetKey, TargetKey> builder = ImmutableMultimap.builder();
    for (TargetIdeInfo target : targetMap.targets()) {
        TargetKey key = target.key;//w ww.  jav  a  2s.  c om
        for (Dependency dep : target.dependencies) {
            TargetKey depKey = dep.targetKey;
            if (targetMap.contains(depKey)) {
                builder.put(depKey, key);
            }
        }
    }
    return builder.build();
}

From source file:com.spectralogic.ds3client.networking.HeadersImpl.java

private static ImmutableMultimap<String, String> toMultiMap(final Header[] headers) {
    final ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();

    for (final Header header : headers) {
        builder.put(header.getName().toLowerCase(), header.getValue());
    }/*from  w  w  w.j av  a  2 s.  com*/

    return builder.build();
}

From source file:pt.ua.tm.neji.core.parser.ParserSupport.java

private static void generateGDepMap() {
    ImmutableMultimap.Builder<ParserLanguage, ParserLevel> builder = ImmutableMultimap.builder();

    builder.put(ParserLanguage.ENGLISH, ParserLevel.TOKENIZATION);
    builder.put(ParserLanguage.ENGLISH, ParserLevel.POS);
    builder.put(ParserLanguage.ENGLISH, ParserLevel.CHUNKING);
    builder.put(ParserLanguage.ENGLISH, ParserLevel.LEMMATIZATION);
    builder.put(ParserLanguage.ENGLISH, ParserLevel.DEPENDENCY);

    supportMaps.put(ParserTool.GDEP, builder.build());
}

From source file:com.facebook.buck.android.exopackage.ExopackageUtil.java

public static ImmutableMultimap<Path, Path> applyFilenameFormat(Multimap<String, Path> filesToHashes,
        Path deviceDir, String filenameFormat) {
    ImmutableMultimap.Builder<Path, Path> filesBuilder = ImmutableMultimap.builder();
    for (Map.Entry<String, Path> entry : filesToHashes.entries()) {
        filesBuilder.put(deviceDir.resolve(String.format(filenameFormat, entry.getKey())), entry.getValue());
    }/*from   w ww  .  j  ava2 s  .c  om*/
    return filesBuilder.build();
}

From source file:com.palantir.atlasdb.cleaner.CleanupFollower.java

public static CleanupFollower create(Iterable<Schema> schemas) {
    ImmutableMultimap.Builder<String, OnCleanupTask> cleanupTasksByTable = ImmutableMultimap.builder();
    for (Schema schema : schemas) {
        cleanupTasksByTable.putAll(schema.getCleanupTasksByTable());
    }/*  www . j  a  v  a  2 s .  c om*/
    return new CleanupFollower(cleanupTasksByTable.build());
}

From source file:org.commoncrawl.util.TLDNamesCollection.java

private static void initialize() {
    synchronized (TLDNamesCollection.class) {
        if (tldToSecondaryNameMap == null) {

            try {

                ImmutableMultimap.Builder<String, String> builder = new ImmutableMultimap.Builder<String, String>();

                InputStream inputStream = ClassLoader.getSystemClassLoader()
                        .getResourceAsStream("effective_tld_list.txt");

                try {

                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(inputStream, Charset.forName("UTF-8")));

                    String line = null;

                    while ((line = reader.readLine()) != null) {
                        if (!line.startsWith("//")) {
                            if (line.length() != 0) {
                                int indexOfDot = line.lastIndexOf(".");
                                if (indexOfDot == -1) {
                                    builder.put(line.trim(), "");
                                } else {
                                    String leftSide = line.substring(0, indexOfDot).trim();
                                    String rightSide = line.substring(indexOfDot + 1).trim();
                                    builder.put(rightSide, leftSide);
                                }/*ww  w. jav a 2  s  .  c  om*/
                            }
                        }
                    }

                    tldToSecondaryNameMap = builder.build();
                } finally {
                    inputStream.close();
                }
            } catch (IOException e) {
                LOG.error(CCStringUtils.stringifyException(e));
                throw new RuntimeException(e);
            }
        }
    }
}

From source file:com.facebook.buck.cxx.CxxPreprocessorFlags.java

/**
 * Converts from CxxConstructorArg.preprocessorFlags and
 * CxxConstructorArg.langPreprocessorFlags to the multimap
 * of (source type: [flag, flag2, ...]) pairs.
 *
 * If the list version of the arg is present, fills every source
 * type with the list's value.//w w w  . j  a  v  a2  s .c  om
 *
 * Otherwise, converts the map version of the arg to a multimap.
 */
public static ImmutableMultimap<CxxSource.Type, String> fromArgs(Optional<ImmutableList<String>> defaultFlags,
        Optional<ImmutableMap<CxxSource.Type, ImmutableList<String>>> perLanguageFlags) {

    ImmutableMultimap.Builder<CxxSource.Type, String> result = ImmutableMultimap.builder();
    if (defaultFlags.isPresent()) {
        for (CxxSource.Type type : CxxSource.Type.values()) {
            result.putAll(type, defaultFlags.get());
        }
    }
    if (perLanguageFlags.isPresent()) {
        for (ImmutableMap.Entry<CxxSource.Type, ImmutableList<String>> entry : perLanguageFlags.get()
                .entrySet()) {
            result.putAll(entry.getKey(), entry.getValue());
        }
    }
    return result.build();
}

From source file:com.github.flaxsearch.api.DocumentData.java

public DocumentData(Document document) {
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    for (IndexableField field : document) {
        builder.put(field.name(), field.stringValue());
    }//from  w  ww. ja v a  2s .  c o m
    this.fields = builder.build();
}