Example usage for com.google.common.collect Maps newHashMapWithExpectedSize

List of usage examples for com.google.common.collect Maps newHashMapWithExpectedSize

Introduction

In this page you can find the example usage for com.google.common.collect Maps newHashMapWithExpectedSize.

Prototype

public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize) 

Source Link

Document

Creates a HashMap instance, with a high enough "initial capacity" that it should hold expectedSize elements without growth.

Usage

From source file:org.apache.phoenix.end2end.SpooledSortMergeJoinIT.java

@BeforeClass
@Shadower(classBeingShadowed = BaseClientManagedTimeIT.class)
public static void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    ;/*from w w w  . ja  va  2s .  co m*/
    props.put(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(100));
    // Must update config before starting server
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}

From source file:org.apache.phoenix.end2end.OrderByWithServerClientSpoolingDisabledIT.java

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    // make sure disabling server side spooling has no affect on correctness(existing orderby
    // IT)/*w  w  w .ja  v  a  2  s . co m*/
    props.put(QueryServices.SERVER_ORDERBY_SPOOLING_ENABLED_ATTRIB, Boolean.toString(Boolean.FALSE));
    props.put(QueryServices.CLIENT_ORDERBY_SPOOLING_ENABLED_ATTRIB, Boolean.toString(Boolean.FALSE));
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}

From source file:org.graylog2.utilities.ConfigurationMapConverter.java

/**
 * Converts the values in the map to the requested types. This has been copied from the Graylog web interface
 * and should be removed once we have better configuration objects.
 *//*from  ww w. j av a 2s .co m*/
public static Map<String, Object> convertValues(final Map<String, Object> data,
        final ConfigurationRequest configurationRequest) throws ValidationException {
    final Map<String, Object> configuration = Maps.newHashMapWithExpectedSize(data.size());
    final Map<String, Map<String, Object>> configurationFields = configurationRequest.asList();

    for (final Map.Entry<String, Object> entry : data.entrySet()) {
        final String field = entry.getKey();
        final Map<String, Object> fieldDescription = configurationFields.get(field);
        if (fieldDescription == null || fieldDescription.isEmpty()) {
            throw new ValidationException(field,
                    "Unknown configuration field description for field \"" + field + "\"");
        }

        final String type = (String) fieldDescription.get("type");

        // Decide what to cast to. (string, bool, number)
        Object value;
        switch (type) {
        case "text":
        case "dropdown":
            value = entry.getValue() == null ? "" : String.valueOf(entry.getValue());
            break;
        case "number":
            try {
                value = Integer.parseInt(String.valueOf(entry.getValue()));
            } catch (NumberFormatException e) {
                // If a numeric field is optional and not provided, use null as value
                if ("true".equals(String.valueOf(fieldDescription.get("is_optional")))) {
                    value = null;
                } else {
                    throw new ValidationException(field, e.getMessage());
                }
            }
            break;
        case "boolean":
            value = "true".equalsIgnoreCase(String.valueOf(entry.getValue()));
            break;
        default:
            throw new ValidationException(field, "Unknown configuration field type \"" + type + "\"");
        }

        configuration.put(field, value);
    }

    return configuration;
}

From source file:io.druid.query.topn.TopNQueryRunnerTestHelper.java

public static Result<TopNResultValue> createExpectedRows(String date, String[] columnNames,
        Iterable<Object[]> values) {
    List<Map> expected = Lists.newArrayList();
    for (Object[] value : values) {
        Preconditions.checkArgument(value.length == columnNames.length);
        Map<String, Object> theVals = Maps.newHashMapWithExpectedSize(value.length);
        for (int i = 0; i < columnNames.length; i++) {
            theVals.put(columnNames[i], value[i]);
        }/*from ww w  .  j av a  2s  .c  o  m*/
        expected.add(theVals);
    }
    return new Result<TopNResultValue>(new DateTime(date), new TopNResultValue(expected));
}

From source file:com.opengamma.core.AbstractSourceWithExternalBundle.java

public static <V extends UniqueIdentifiable & ExternalBundleIdentifiable> Map<ExternalIdBundle, Collection<V>> getAllMultiThread(
        final PoolExecutor executor, final SourceWithExternalBundle<V> source,
        final Collection<ExternalIdBundle> bundles, final VersionCorrection versionCorrection) {
    final PoolExecutor.Service<Void> jobs = executor.createService(null);
    final Map<ExternalIdBundle, Collection<V>> results = Maps.newHashMapWithExpectedSize(bundles.size());
    for (final ExternalIdBundle bundle : bundles) {
        jobs.execute(new Runnable() {
            @Override// w  w w. ja v a  2 s .co m
            public void run() {
                final Collection<V> result = source.get(bundle, versionCorrection);
                if ((result != null) && !result.isEmpty()) {
                    results.put(bundle, result);
                }
            }
        });
    }
    try {
        jobs.join();
    } catch (InterruptedException e) {
        throw new OpenGammaRuntimeException("Interrupted", e);
    }
    return results;
}

From source file:co.cask.cdap.common.conf.ConfigurationJsonTool.java

public static void exportToJson(Configuration configuration, Appendable output) {
    Map<String, String> map = Maps.newHashMapWithExpectedSize(configuration.size());
    for (Map.Entry<String, String> entry : configuration) {
        map.put(entry.getKey(), entry.getValue());
    }/*from   w ww. ja va2  s  .com*/
    new GsonBuilder().setPrettyPrinting().create().toJson(map, output);
}

From source file:org.apache.druid.query.topn.TopNQueryRunnerTestHelper.java

public static Result<TopNResultValue> createExpectedRows(String date, String[] columnNames,
        Iterable<Object[]> values) {
    List<Map> expected = Lists.newArrayList();
    for (Object[] value : values) {
        Preconditions.checkArgument(value.length == columnNames.length);
        Map<String, Object> theVals = Maps.newHashMapWithExpectedSize(value.length);
        for (int i = 0; i < columnNames.length; i++) {
            theVals.put(columnNames[i], value[i]);
        }//  ww w .jav  a  2 s .com
        expected.add(theVals);
    }
    return new Result<TopNResultValue>(DateTimes.of(date), new TopNResultValue(expected));
}

From source file:org.apache.phoenix.end2end.ParallelStatsEnabledIT.java

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.params.UrlSolrParams.java

private static Map<String, String[]> createMultiMap(String urlParams) {
    Multimap<String, String> map = getQueryMap(urlParams);

    Map<String, Collection<String>> colMap = map.asMap();

    Map<String, String[]> arrMap = Maps.newHashMapWithExpectedSize(colMap.size());

    for (Map.Entry<String, Collection<String>> entry : colMap.entrySet()) {
        arrMap.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
    }/*www  .  jav a2s  . c o m*/

    return arrMap;
}

From source file:com.palantir.common.collect.Maps2.java

public static <K, V> Map<K, V> createConstantValueMap(Set<K> keys, V v) {
    Map<K, V> ret = Maps.newHashMapWithExpectedSize(keys.size());
    for (K k : keys) {
        ret.put(k, v);//from  w w  w . j av  a  2s .  co  m
    }
    return ret;
}