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:net.automatalib.graphs.helpers.SimpleNodeIDs.java

public SimpleNodeIDs(SimpleGraph<N> graph) {
    this.nodes = new ArrayList<>(graph.getNodes());
    int numNodes = this.nodes.size();
    this.nodeIds = Maps.newHashMapWithExpectedSize(numNodes);

    for (int i = 0; i < numNodes; i++) {
        N node = this.nodes.get(i);
        nodeIds.put(node, i);//  w  w w. j  a  v  a  2 s .c om
    }
}

From source file:com.opengamma.engine.target.resolver.AbstractIdentifierResolver.java

public static Map<ExternalIdBundle, UniqueId> resolveExternalIdsSingleThread(final IdentifierResolver resolver,
        final Collection<ExternalIdBundle> identifiers, final VersionCorrection versionCorrection) {
    final Map<ExternalIdBundle, UniqueId> result = Maps.newHashMapWithExpectedSize(identifiers.size());
    for (final ExternalIdBundle identifier : identifiers) {
        final UniqueId uid = resolver.resolveExternalId(identifier, versionCorrection);
        if (uid != null) {
            result.put(identifier, uid);
        }/*from w  w w.j  a v a  2  s.  c  o  m*/
    }
    return result;
}

From source file:org.carrot2.core.ProcessingComponentConfiguration.java

static Map<String, ProcessingComponentConfiguration> indexByComponentId(
        ProcessingComponentConfiguration... configurations) {
    final HashMap<String, ProcessingComponentConfiguration> componentIdToConfiguration = Maps
            .newHashMapWithExpectedSize(configurations.length);
    for (ProcessingComponentConfiguration configuration : configurations) {
        if (componentIdToConfiguration.put(configuration.componentId, configuration) != null) {
            throw new IllegalArgumentException(
                    "Duplicate processing component id: " + configuration.componentId);
        }//w ww  .  j  av a  2s.  co  m
    }
    return Collections.unmodifiableMap(componentIdToConfiguration);
}

From source file:org.sonatype.nexus.orient.entity.FieldCopier.java

@SuppressWarnings("unchecked")
public static Map copy(final Map<?, ?> source) {
    Map target = Maps.newHashMapWithExpectedSize(source.size());
    for (Map.Entry<?, ?> entry : source.entrySet()) {
        Object value = maybeCopy(entry.getValue());
        target.put(entry.getKey(), value);
    }//w  w w. j  a  v  a2s .  c  om
    return target;
}

From source file:com.google.template.soy.basicfunctions.BasicFunctionsRuntime.java

/**
 * Combine the two maps -- for the JavaSource variant while the function signature is still ?
 * instead of map./*from w w  w.j  a  va  2 s .c  o m*/
 */
public static SoyDict augmentMap(SoyValue sv1, SoyValue sv2) {
    SoyDict first = (SoyDict) sv1;
    SoyDict second = (SoyDict) sv2;
    Map<String, SoyValueProvider> map = Maps
            .newHashMapWithExpectedSize(first.getItemCnt() + second.getItemCnt());
    map.putAll(first.asJavaStringMap());
    map.putAll(second.asJavaStringMap());
    return DictImpl.forProviderMap(map, RuntimeMapTypeTracker.Type.LEGACY_OBJECT_MAP_OR_RECORD);
}

From source file:org.apache.mahout.fpm.pfpgrowth.fpgrowth.LeastKCache.java

public LeastKCache(int capacity) {
    this.capacity = capacity;
    cache = Maps.newHashMapWithExpectedSize(capacity);
    queue = new PriorityQueue<K>(capacity + 1, Collections.reverseOrder());
}

From source file:net.automatalib.automata.helpers.SimpleStateIDs.java

public SimpleStateIDs(SimpleAutomaton<S, ?> automaton) {
    this.states = new ArrayList<>(automaton.getStates());
    int numStates = this.states.size();
    this.stateIds = Maps.newHashMapWithExpectedSize(numStates);

    for (int i = 0; i < numStates; i++) {
        S state = this.states.get(i);
        stateIds.put(state, i);/*from  w  w  w .  j av a  2s  .  co m*/
    }
}

From source file:com.ngdata.hbaseindexer.indexer.SolrUpdateCollector.java

/**
 * Instantiate with an expected initial capacity of added and deleted documents.
 *//*from  ww w . j  av  a 2 s  .co m*/
public SolrUpdateCollector(int initialSize) {
    documentsToAdd = Maps.newHashMapWithExpectedSize(initialSize);
    idsToDelete = Lists.newArrayListWithCapacity(initialSize);
    deleteQueries = Lists.newArrayList();
}

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

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

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

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> serverProps = getServerProps();
    serverProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.TRUE.toString());
    Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(2);
    clientProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.TRUE.toString());
    clientProps.put(HConstants.HBASE_CLIENT_RETRIES_NUMBER, "2");
    NUM_SLAVES_BASE = 4;//from   w  w  w. j a  v  a 2  s  .  co  m
    setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
            new ReadOnlyProps(clientProps.entrySet().iterator()));
    TableName systemTable = SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES,
            true);
    indexRebuildTaskRegionEnvironment = getUtility().getRSForFirstRegionInTable(systemTable)
            .getRegions(systemTable).get(0).getCoprocessorHost()
            .findCoprocessorEnvironment(MetaDataRegionObserver.class.getName());
    MetaDataRegionObserver
            .initRebuildIndexConnectionProps(indexRebuildTaskRegionEnvironment.getConfiguration());
}