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.onos.yangtools.yang.data.api.schema.tree.spi.LazyContainerNode.java

private static <K, V> Map<K, V> allocateMap(final int hint) {
    switch (hint) {
    case 0:/* www  .  j av a2s  .co  m*/
    case 1:
        // Zero does not matter, but will be kept small if it is touched in the future
        return new HashMap<>(1);
    case 2:
        // Two entries, may end up being grown to 4
        return new HashMap<>(2);
    case 3:
        // 4 * 0.75 = 3
        return new HashMap<>(4);
    case 4:
    case 5:
    case 6:
        // 8 * 0.75 = 6
        return new HashMap<>(8);
    default:
        // No savings, defer to Guava
        return Maps.newHashMapWithExpectedSize(hint);
    }
}

From source file:org.apache.phoenix.end2end.index.BaseLocalIndexIT.java

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(7);
    serverProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, "true");
    Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(1);
    clientProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, "true");
    setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
            new ReadOnlyProps(clientProps.entrySet().iterator()));
}

From source file:com.opengamma.engine.marketdata.AbstractMarketDataSnapshot.java

/**
 * Implementation based on the {@link #query(ValueSpecification)} method. {@inheritDoc}
 *//*from  w  ww . ja va  2  s . c  o m*/
@Override
public Map<ValueSpecification, Object> query(final Set<ValueSpecification> specifications) {
    final Map<ValueSpecification, Object> results = Maps.newHashMapWithExpectedSize(specifications.size());
    for (final ValueSpecification specification : specifications) {
        final Object value = query(specification);
        if (value != null) {
            results.put(specification, value);
        }
    }
    return results;
}

From source file:org.eclipse.xtend.core.scoping.CachingTypeScope.java

public CachingTypeScope(AbstractScope parent) {
    this.parent = parent;
    this.cache = Maps.newHashMapWithExpectedSize(50);
}

From source file:org.graylog2.restclient.models.ConfigurableEntity.java

public Map<String, Object> getConfiguration(List<RequestedConfigurationField> configurationFields) {
    final Map<String, Object> result = Maps.newHashMapWithExpectedSize(getConfiguration().size());

    for (final RequestedConfigurationField configurationField : configurationFields) {
        if (getConfiguration().get(configurationField.getTitle()) != null) {
            if (configurationField.getAttributes().contains("is_password")) {
                result.put(configurationField.getTitle(), "*******");
            } else {
                result.put(configurationField.getTitle(),
                        getConfiguration().get(configurationField.getTitle()));
            }/*from  ww w. j av a2 s .  co  m*/
        }
    }
    return result;
}

From source file:org.apache.phoenix.pig.BasePigIT.java

@BeforeClass
@Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
public static void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(3);
    props.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    // Must update config before starting server
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}

From source file:org.eclipse.che.infrastructure.docker.client.json.Filters.java

public Map<String, List<String>> getFilters() {
    final HashMap<String, List<String>> filtersCopy = Maps.newHashMapWithExpectedSize(filters.size());
    filters.forEach((s, strings) -> filtersCopy.put(s, Collections.unmodifiableList(strings)));

    return Collections.unmodifiableMap(filtersCopy);
}

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

public LenientExplicitOrdering(List<T> order) {
    this.idxMap = Maps.newHashMapWithExpectedSize(order.size());
    int idx = 0;/*w  w w  . jav  a 2 s . c  o m*/
    for (T s : order) {
        idxMap.put(s, idx);
        idx++;
    }
}

From source file:com.google.template.soy.data.internal.BasicParamStore.java

public BasicParamStore(int size) {
    this.localStore = Maps.newHashMapWithExpectedSize(size);
}

From source file:org.lunifera.dsl.xtext.lazyresolver.scoping.CachingTypeScope.java

public CachingTypeScope(String cacheId, IScope parent) {
    super(parent, false);
    this.cacheId = cacheId;
    this.cache = Maps.newHashMapWithExpectedSize(50);
}