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.terasology.i18n.gson.I18nMapTypeAdapter.java

@Override
public I18nMap deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonPrimitive()) {
        return new I18nMap(json.getAsString());
    } else if (json.isJsonObject()) {
        JsonObject obj = json.getAsJsonObject();
        Map<Locale, String> values = Maps.newHashMapWithExpectedSize(obj.entrySet().size());
        for (Map.Entry<String, JsonElement> item : obj.entrySet()) {
            if (item.getValue().isJsonPrimitive()) {
                values.put(Locale.forLanguageTag(item.getKey()), item.getValue().getAsString());
            } else {
                throw new JsonParseException(
                        "Expected locale string pair, found " + item.getKey() + "'" + item.getValue() + "'");
            }/*  w  ww. j  ava  2  s.c  o  m*/
        }
        return new I18nMap(values);
    } else {
        throw new JsonParseException("Invalid I18nMap: '" + json + "'");
    }
}

From source file:com.netflix.karyon.swagger.modules.AppModule.java

private Map<String, String> createServletParams() {
    Map<String, String> servletParams = Maps.newHashMapWithExpectedSize(2);
    // For static resources like HTML, JS, or CSS that should get served by the servlet container
    // Note that this is only effective when we are using a filter to handle requests - can't do that till we fix # 1068
    servletParams.put(ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, "/(docs|js)/.*");
    // Need this to avoid issue reference here: http://stackoverflow.com/questions/15767973/jersey-what-does-couldnt-find-grammar-element-mean
    servletParams.put("com.sun.jersey.config.feature.DisableWADL", "true");
    return servletParams;

}

From source file:com.google.cloud.datastore.DatastoreHelper.java

private static List<Entity> compileEntities(Key[] keys, Iterator<Entity> entities) {
    Map<Key, Entity> map = Maps.newHashMapWithExpectedSize(keys.length);
    while (entities.hasNext()) {
        Entity entity = entities.next();
        map.put(entity.getKey(), entity);
    }/* w w w  .  ja va  2s . c  o m*/
    List<Entity> list = new ArrayList<>(keys.length);
    for (Key key : keys) {
        // this will include nulls for nonexistent keys
        list.add(map.get(key));
    }
    return list;
}

From source file:com.voxelplugineering.voxelsniper.brush.effect.morphological.BlendMaterialOperation.java

public BlendMaterialOperation() {
    mats = Maps.newHashMapWithExpectedSize(10);
}

From source file:com.lyndir.lhunath.snaplog.data.object.media.aws.S3MediaData.java

/**
 * Create a new {@link S3MediaData} instance.
 *
 * @param media The {@link S3Media} that we hold data for.
 *///from  ww  w .j a  v  a2 s .  com
public S3MediaData(final S3Media media) {

    checkNotNull(media, "Given media must not be null.");

    this.media = media;

    s3Objects = Maps.newHashMapWithExpectedSize(Quality.values().length);
}

From source file:com.palantir.atlasdb.table.description.Schemas.java

public static void createTables(KeyValueService kvs, Map<String, TableDefinition> fullTableNameToDefinition) {
    Map<String, byte[]> fullTableNameToMetadata = Maps
            .newHashMapWithExpectedSize(fullTableNameToDefinition.size());
    for (Entry<String, TableDefinition> tableEntry : fullTableNameToDefinition.entrySet()) {
        fullTableNameToMetadata.put(tableEntry.getKey(),
                tableEntry.getValue().toTableMetadata().persistToBytes());
    }//from  w  w  w  .  j av a 2 s.co m
    kvs.createTables(fullTableNameToMetadata);
}

From source file:net.derquinse.bocas.BocasExerciser.java

public static Map<ByteString, MemoryByteSource> dataSet(BocasHashFunction f, int size) {
    Map<ByteString, MemoryByteSource> map = Maps.newHashMapWithExpectedSize(size);
    for (int i = 0; i < size; i++) {
        MemoryByteSource v = data();/* ww w  .jav a  2  s  . com*/
        map.put(f.hash(v), v);
    }
    return map;
}

From source file:tachyon.master.file.journal.PersistFileEntry.java

@Override
public Map<String, Object> getParameters() {
    Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(5);
    parameters.put("fileId", mFileId);
    parameters.put("length", mLength);
    parameters.put("operationTimeMs", mOpTimeMs);
    return parameters;
}

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

@BeforeClass
@Shadower(classBeingShadowed = BaseClientManagedTimeIT.class)
public static void doSetup() throws Exception {
    int targetQueryConcurrency = 3;
    int maxQueryConcurrency = 5;
    Map<String, String> props = Maps.newHashMapWithExpectedSize(3);
    props.put(QueryServices.MAX_QUERY_CONCURRENCY_ATTRIB, Integer.toString(maxQueryConcurrency));
    props.put(QueryServices.TARGET_QUERY_CONCURRENCY_ATTRIB, Integer.toString(targetQueryConcurrency));
    props.put(QueryServices.MAX_INTRA_REGION_PARALLELIZATION_ATTRIB, Integer.toString(Integer.MAX_VALUE));
    // Must update config before starting server
    setUpTestDriver(getUrl(), new ReadOnlyProps(props.entrySet().iterator()));
}

From source file:jp.tricreo.schemagenerator.infrastructure.utils.CloneUtil.java

/**
 * ?? {@link Map} ?({@link Map#values()})?{@link Object#clone() }??
 * ?????? {@link HashMap} ?/*ww  w .j a v a2 s .  com*/
 * 
 * @param <K> ?
 * @param <V> ?
 * @param map ???
 * @return {@link HashMap}
 */
public static <K, V extends Entity<V, ?>> HashMap<K, V> cloneEntityHashMap(Map<K, V> map) {
    HashMap<K, V> cloneMap = Maps.newHashMapWithExpectedSize(map.size());
    for (Entry<K, V> element : map.entrySet()) {
        V cloneValue = element.getValue().clone();
        cloneMap.put(element.getKey(), cloneValue);
    }
    return cloneMap;
}