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:com.google.api.explorer.client.base.ApiResponse.java

/**
 * Inspects the headers object of the given JS object and constructs a
 * {@link Map} of its keys and values./*from   ww  w . j a  va2 s .  c  o m*/
 */
private static Map<String, HeaderValue> createHeadersMap(DynamicJso data) {
    DynamicJso headers = data.get("headers");
    JsArrayString keys = headers.keys();
    Map<String, HeaderValue> headersMap = Maps.newHashMapWithExpectedSize(keys.length());

    for (int i = 0; i < keys.length(); i++) {
        String key = keys.get(i);
        String value = "";
        switch (headers.typeofKey(key)) {
        case STRING:
            value = headers.getString(key);
            break;

        case BOOLEAN:
            value = String.valueOf(headers.getBoolean(key));
            break;

        case NUMBER:
            value = String.valueOf(headers.getInteger(key));
            break;

        case INTEGER:
            value = String.valueOf(headers.getDouble(key));
            break;
        }
        headersMap.put(key.toLowerCase(), new HeaderValue(key, value));

    }
    return headersMap;
}

From source file:com.palantir.atlasdb.transaction.service.SimpleTransactionService.java

@Override
public Map<Long, Long> get(Iterable<Long> startTimestamps) {
    Map<Cell, Long> startTsMap = Maps.newHashMap();
    for (Long startTimestamp : startTimestamps) {
        Cell k = getTransactionCell(startTimestamp);
        startTsMap.put(k, MAX_TIMESTAMP);
    }/*from   w  ww .jav a 2s.c  o  m*/

    Map<Cell, Value> rawResults = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, startTsMap);
    Map<Long, Long> result = Maps.newHashMapWithExpectedSize(rawResults.size());
    for (Map.Entry<Cell, Value> e : rawResults.entrySet()) {
        long startTs = TransactionConstants.getTimestampForValue(e.getKey().getRowName());
        long commitTs = TransactionConstants.getTimestampForValue(e.getValue().getContents());
        result.put(startTs, commitTs);
    }

    return result;
}

From source file:eu.interedition.text.xml.XMLEntity.java

public static ObjectNode attributesToData(XMLStreamReader reader) {
    final int attributeCount = reader.getAttributeCount();
    final Map<Name, String> attributes = Maps.newHashMapWithExpectedSize(attributeCount);
    for (int ac = 0; ac < attributeCount; ac++) {
        attributes.put(new Name(reader.getAttributeName(ac)), reader.getAttributeValue(ac));
    }//  ww  w. j a  va 2s  . c om
    return attributesToData(attributes);
}

From source file:com.netflix.atlas.client.interpreter.ByValueRelOp.java

@Override
public Map<List<String>, LabeledResult> apply(List<Metric> updates) {
    Map<List<String>, LabeledResult> aResults = a.apply(updates);
    double bRes = b.apply(updates);

    Map<List<String>, LabeledResult> results = Maps.newHashMapWithExpectedSize(aResults.size());
    for (Map.Entry<List<String>, LabeledResult> entry : aResults.entrySet()) {
        LabeledResult aRes = entry.getValue();
        String resLabel = String.format("%s %s %s", aRes.getLabel(), op.getSymbol(), b.getLabel());
        results.put(entry.getKey(), new LabeledResult(resLabel, op.apply(aRes.getValue(), bRes)));
    }//w  w  w.j  a v  a  2s  .c o  m
    return results;
}

From source file:org.apache.phoenix.schema.PMetaDataCache.java

private static Map<PTableKey, PSchema> newSchemaMap(int expectedCapacity) {
    // Use regular HashMap, as we cannot use a LinkedHashMap that orders by access time
    // safely across multiple threads (as the underlying collection is not thread safe).
    // Instead, we track access time and prune it based on the copy we've made.
    return Maps.newHashMapWithExpectedSize(expectedCapacity);
}

From source file:com.google.devtools.depan.model.GraphModel.java

/**
 * Returns the collection of Nodes in this graph as a Map from their
 * String name to the underlying node./*from   w  ww. ja  v a  2  s .c o  m*/
 *
 * @return the collection of Nodes in this graph.
 */
public Map<String, GraphNode> getNodesMap() {
    Collection<GraphNode> nodes = getNodes();
    Map<String, GraphNode> result = Maps.newHashMapWithExpectedSize(nodes.size());
    for (GraphNode node : nodes) {
        result.put(node.getId().toString(), node);
    }
    return result;
}

From source file:voldemort.store.StoreUtils.java

/**
 * Returns an empty map with expected size matching the iterable size if
 * it's of type Collection. Otherwise, an empty map with the default size is
 * returned./*from  w  w w.ja va  2s.  c o  m*/
 */
public static <K, V> HashMap<K, V> newEmptyHashMap(Iterable<?> iterable) {
    if (iterable instanceof Collection<?>)
        return Maps.newHashMapWithExpectedSize(((Collection<?>) iterable).size());
    return Maps.newHashMap();
}

From source file:org.gradoop.flink.algorithms.fsm.transactional.tle.functions.SingleEdgeEmbeddings.java

/**
 * Finds all embeddings.//  w  w w.  jav  a 2 s  .  c  o m
 *
 * @param graph graph
 * @return 1-edge embeddings
 */
protected Map<String, List<Embedding>> createEmbeddings(FSMGraph graph) {

    Map<Integer, String> vertices = graph.getVertices();
    Map<String, List<Embedding>> subgraphEmbeddings = Maps.newHashMap();

    for (Map.Entry<Integer, FSMEdge> entry : graph.getEdges().entrySet()) {

        FSMEdge edge = entry.getValue();
        int sourceId = edge.getSourceId();
        int targetId = edge.getTargetId();

        Map<Integer, String> incidentVertices = Maps.newHashMapWithExpectedSize(2);

        incidentVertices.put(sourceId, vertices.get(sourceId));

        if (sourceId != targetId) {
            incidentVertices.put(targetId, vertices.get(targetId));
        }

        Map<Integer, FSMEdge> singleEdge = Maps.newHashMapWithExpectedSize(1);
        singleEdge.put(entry.getKey(), edge);

        Embedding embedding = new Embedding(incidentVertices, singleEdge);

        String subgraph = canonicalLabeler.label(embedding);

        List<Embedding> embeddings = subgraphEmbeddings.get(subgraph);

        if (embeddings == null) {
            subgraphEmbeddings.put(subgraph, Lists.newArrayList(embedding));
        } else {
            embeddings.add(embedding);
        }
    }

    return subgraphEmbeddings;
}

From source file:org.pentaho.caching.api.Constants.java

public static Map<String, String> convertDictionary(Dictionary<String, ?> dictionary) {
    Map<String, String> properties = Maps.newHashMapWithExpectedSize(dictionary.size());
    for (Enumeration<String> keys = dictionary.keys(); keys.hasMoreElements();) {
        String key = keys.nextElement();
        properties.put(key, String.valueOf(dictionary.get(key)));
    }//from  w w w  .  j a v  a  2  s. c om
    return properties;
}

From source file:com.google.devtools.depan.view_doc.layout.hierarchy.HierarchicalTreeLayout.java

/**
 * Does the complete left-to-right planar layout.
 *//*from  w  w  w  .j  av  a 2s.c o m*/
public void initialize() {
    HierarchicalLayoutTool layoutTool = buildLayoutTool();

    positions = Maps.newHashMapWithExpectedSize(graphModel.getNodes().size());
    layoutTool.layoutTree();
    Point2dUtils.translatePos(region, graphModel.getNodes(), positions);
}