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

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

Introduction

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

Prototype

@Deprecated
@Override
public boolean putAll(K key, Iterable<? extends V> values) 

Source Link

Document

Guaranteed to throw an exception and leave the multimap unmodified.

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);//  ww  w .  j a va  2 s.c om

    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.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.//from  w  w w  .ja v a 2  s. c  o m
 *
 * 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.isotrol.impe3.core.impl.RequestParamsFactory.java

/**
 * Returns the collection of request parameters from a multimap object.
 * @param map Multimap./*from   w w w  . j  av a  2 s  . c  om*/
 * @return The request query parameters.
 */
public static RequestParams of(Multimap<String, String> map) {
    if (map == null || map.isEmpty()) {
        return EMPTY;
    }
    final ImmutableMultimap.Builder<CaseIgnoringString, String> builder = ImmutableMultimap.builder();
    for (String key : map.keySet()) {
        final CaseIgnoringString cis = CaseIgnoringString.valueOf(key);
        builder.putAll(cis, map.get(key));
    }
    return new Immutable(builder.build());
}

From source file:com.isotrol.impe3.core.impl.HeadersFactory.java

/**
 * Adds the parameters from a JAX-RS headers object.
 * @param headers HTTP Headers.//  ww w  .j av a 2s. co m
 * @return The request headers.
 */
public static Headers of(HttpHeaders headers) {
    Preconditions.checkNotNull(headers, "The request headers object cannot be null.");
    final ImmutableMultimap.Builder<CaseIgnoringString, String> builder = ImmutableMultimap.builder();
    for (Entry<String, List<String>> entry : headers.getRequestHeaders().entrySet()) {
        List<String> values = entry.getValue();
        if (values != null) {
            builder.putAll(CaseIgnoringString.valueOf(entry.getKey()), values);
        }
    }
    return new Immutable(builder.build());
}

From source file:com.isotrol.impe3.core.impl.RequestParamsFactory.java

/**
 * Returns the collection of request parameters from a JAX-RS headers object.
 * @param info URI information.//from  w  w  w. j  a  v  a2  s .c om
 * @return The request query parameters.
 */
public static RequestParams of(UriInfo info) {
    Preconditions.checkNotNull(info, "The URI object cannot be null.");
    final ImmutableMultimap.Builder<CaseIgnoringString, String> builder = ImmutableMultimap.builder();
    for (Entry<String, List<String>> entry : info.getQueryParameters().entrySet()) {
        List<String> values = entry.getValue();
        if (values != null) {
            builder.putAll(CaseIgnoringString.valueOf(entry.getKey()), values);
        }
    }
    return new Immutable(builder.build());
}

From source file:com.isotrol.impe3.core.impl.RequestParamsFactory.java

/**
 * Adds the parameters from a servlet request.
 * @param request Servlet request./*from ww  w.  ja v a  2 s  .c o  m*/
 * @return The request parameters.
 */
public static RequestParams of(ServletRequest request) {
    Preconditions.checkNotNull(request, "The request cannot be null.");
    final ImmutableMultimap.Builder<CaseIgnoringString, String> builder = ImmutableMultimap.builder();
    @SuppressWarnings("unchecked")
    final Enumeration<String> names = request.getParameterNames();
    if (names != null) {
        while (names.hasMoreElements()) {
            final String parameter = names.nextElement();
            final String[] values = request.getParameterValues(parameter);
            if (values != null && values.length > 0) {
                builder.putAll(CaseIgnoringString.valueOf(parameter), Arrays.asList(values));
            }
        }
    }
    return new Immutable(builder.build());
}

From source file:co.cask.cdap.explore.jdbc.ExploreConnectionParams.java

/**
 * Parse Explore connection url string to retrieve the necessary parameters to connect to CDAP.
 *///  w w  w . j a  v  a  2 s  .co m
public static ExploreConnectionParams parseConnectionUrl(String url) {
    // URI does not accept two semicolons in a URL string, hence the substring
    URI jdbcURI = URI.create(url.substring(ExploreJDBCUtils.URI_JDBC_PREFIX.length()));
    String host = jdbcURI.getHost();
    int port = jdbcURI.getPort();
    ImmutableMultimap.Builder<ExploreConnectionParams.Info, String> builder = ImmutableMultimap.builder();

    // get the query params - javadoc for getQuery says that it decodes the query URL with UTF-8 charset.
    String query = jdbcURI.getQuery();
    if (query != null) {
        for (String entry : Splitter.on("&").split(query)) {
            // Need to do it twice because of error in guava libs Issue: 1577
            int idx = entry.indexOf('=');
            if (idx <= 0) {
                continue;
            }

            ExploreConnectionParams.Info info = ExploreConnectionParams.Info.fromStr(entry.substring(0, idx));
            if (info != null) {
                builder.putAll(info, Splitter.on(',').omitEmptyStrings().split(entry.substring(idx + 1)));
            }
        }
    }
    return new ExploreConnectionParams(host, port, builder.build());
}

From source file:org.sosy_lab.cpachecker.util.LoopStructure.java

/**
 * Build loop-structure information for a CFA.
 * Do not call this method outside of the frontend,
 * use {@link org.sosy_lab.cpachecker.cfa.CFA#getLoopStructure()} instead.
 * @throws ParserException If the structure of the CFA is too complex for determining loops.
 *//*ww  w.  j av  a2s  .co  m*/
public static LoopStructure getLoopStructure(MutableCFA cfa) throws ParserException {
    ImmutableMultimap.Builder<String, Loop> loops = ImmutableMultimap.builder();
    for (String functionName : cfa.getAllFunctionNames()) {
        SortedSet<CFANode> nodes = cfa.getFunctionNodes(functionName);
        loops.putAll(functionName, findLoops(nodes, cfa.getLanguage()));
    }
    return new LoopStructure(loops.build());
}

From source file:org.jclouds.ec2.binders.BindBlockDeviceMappingToIndexedFormParams.java

@SuppressWarnings("unchecked")
@Override/*from   w w w.  j a va2s. c  om*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map");
    Map<String, BlockDevice> blockDeviceMapping = (Map<String, BlockDevice>) input;
    Multimap<String, String> original = queryParser().apply(request.getPayload().getRawContent().toString());
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    builder.putAll("Action", "ModifyInstanceAttribute");
    int amazonOneBasedIndex = 1; // according to docs, counters must start with 1
    for (Entry<String, BlockDevice> ebsBlockDeviceName : blockDeviceMapping.entrySet()) {
        // not null by contract
        builder.put(format(deviceNamePattern, amazonOneBasedIndex), ebsBlockDeviceName.getKey());
        builder.put(format(deleteOnTerminationPattern, amazonOneBasedIndex),
                String.valueOf(ebsBlockDeviceName.getValue().isDeleteOnTermination()));
        builder.put(format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDeviceName.getValue().getVolumeId());
        amazonOneBasedIndex++;
    }
    builder.putAll("InstanceId", original.get("InstanceId"));
    request.setPayload(newUrlEncodedFormPayload(builder.build()));
    return request;
}

From source file:com.nesscomputing.httpclient.response.HttpResponseContentConverter.java

private Multimap<String, String> headersFor(Map<String, List<String>> allHeaders) {
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    for (Entry<String, List<String>> e : allHeaders.entrySet()) {
        builder.putAll(e.getKey(), e.getValue());
    }//from   www .j  a  v a 2s.  co  m

    return builder.build();
}