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.elasticsearch.indices.recovery.StartRecoveryRequest.java

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    recoveryId = in.readLong();//from   ww  w  .jav  a  2 s.c  om
    shardId = ShardId.readShardId(in);
    sourceNode = DiscoveryNode.readNode(in);
    targetNode = DiscoveryNode.readNode(in);
    markAsRelocated = in.readBoolean();
    int size = in.readVInt();
    existingFiles = Maps.newHashMapWithExpectedSize(size);
    for (int i = 0; i < size; i++) {
        StoreFileMetaData md = StoreFileMetaData.readStoreFileMetaData(in);
        existingFiles.put(md.name(), md);
    }
}

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

/**
 * Creates tables/indexes for this schema.
 *
 * This operation is idempotent, so it can be called multiple times without
 * effect. Behavior is undefined if the schema has changed between calls
 * (e.g., it is not the responsibility of this method to perform schema
 * upgrades).//ww  w  .j a v  a  2s .  c  om
 */
public static void createTablesAndIndexes(Schema schema, KeyValueService kvs) {
    schema.validate();

    Map<String, TableDefinition> fullTableNamesToDefinitions = Maps
            .newHashMapWithExpectedSize(schema.getTableDefinitions().size());
    for (Entry<String, TableDefinition> e : schema.getTableDefinitions().entrySet()) {
        fullTableNamesToDefinitions.put(getFullTableName(e.getKey(), schema.getNamespace()), e.getValue());
    }
    Map<String, IndexDefinition> fullIndexNamesToDefinitions = Maps
            .newHashMapWithExpectedSize(schema.getIndexDefinitions().size());
    for (Entry<String, IndexDefinition> e : schema.getIndexDefinitions().entrySet()) {
        fullIndexNamesToDefinitions.put(getFullTableName(e.getKey(), schema.getNamespace()), e.getValue());
    }
    createTables(kvs, fullTableNamesToDefinitions);
    createIndices(kvs, fullIndexNamesToDefinitions);
}

From source file:voldemort.restclient.RESTClient.java

@Override
public Map<K, Versioned<V>> getAll(Iterable<K> keys, Map<K, Object> transforms) {
    Map<K, List<Versioned<V>>> items = null;
    items = this.clientStore.getAll(keys, null);
    Map<K, Versioned<V>> result = Maps.newHashMapWithExpectedSize(items.size());

    for (Entry<K, List<Versioned<V>>> mapEntry : items.entrySet()) {
        Versioned<V> value = getItemOrThrow(mapEntry.getKey(), null, mapEntry.getValue());
        result.put(mapEntry.getKey(), value);
    }/*www  .  ja v a 2  s.c  om*/
    return result;
}

From source file:com.google.cloud.bigquery.InsertAllResponse.java

static InsertAllResponse fromPb(TableDataInsertAllResponse responsePb) {
    Map<Long, List<BigQueryError>> insertErrors = null;
    if (responsePb.getInsertErrors() != null) {
        List<InsertErrors> errorsPb = responsePb.getInsertErrors();
        insertErrors = Maps.newHashMapWithExpectedSize(errorsPb.size());
        for (InsertErrors errorPb : errorsPb) {
            insertErrors.put(errorPb.getIndex(),
                    Lists.transform(// w w  w  . ja  va2  s.  co  m
                            errorPb.getErrors() != null ? errorPb.getErrors() : ImmutableList.<ErrorProto>of(),
                            BigQueryError.FROM_PB_FUNCTION));
        }
    }
    return new InsertAllResponse(insertErrors);
}

From source file:org.eclipse.xtext.xbase.typesystem.override.ResolvedOperationInHierarchy.java

@Override
protected TypeParameterSubstitutor<?> getSubstitutor() {
    if (isRawTypeInheritance()) {
        return new RawTypeSubstitutor(getContextType().getOwner());
    }/* w ww  . j a va 2  s.  c  o m*/
    TypeParameterSubstitutor<?> result = super.getSubstitutor();
    List<JvmTypeParameter> typeParameters = getTypeParameters();
    if (!typeParameters.isEmpty()) {
        List<JvmTypeParameter> resolvedTypeParameters = getResolvedTypeParameters();
        int max = Math.min(typeParameters.size(), resolvedTypeParameters.size());
        ITypeReferenceOwner owner = getContextType().getOwner();
        Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> additionalMapping = Maps
                .newHashMapWithExpectedSize(max);
        for (int i = 0; i < max; i++) {
            LightweightTypeReference localReference = owner
                    .newParameterizedTypeReference(resolvedTypeParameters.get(i));
            additionalMapping.put(typeParameters.get(i),
                    new LightweightMergedBoundTypeArgument(localReference, VarianceInfo.INVARIANT));
        }
        result.enhanceMapping(additionalMapping);
    }
    return result;
}

From source file:edu.harvard.med.screensaver.db.datafetcher.TupleDataFetcher.java

/**
 * @param keys if null, fetches all entities for the root entity type (subject
 *          to normal column criteria)/*  ww w  . ja v  a  2  s.c o m*/
 */
protected Map<K, Tuple<K>> doFetchData(Set<K> keys) {
    // collate properties into groups of PropertyPaths having same RelationshipPath; 
    // this will allow us to execute one query for each group of properties that are from the same entity type 
    Multimap<RelationshipPath<E>, PropertyPath<E>> pathGroups = Multimaps.index(getProperties(),
            new Function<PropertyPath<E>, RelationshipPath<E>>() {
                public RelationshipPath<E> apply(PropertyPath<E> p) {
                    return p.getAncestryPath();
                }
            });

    Map<K, Tuple<K>> tuples = Maps.newHashMapWithExpectedSize(keys.size());
    for (Collection<PropertyPath<E>> propertyPaths : pathGroups.asMap().values()) {
        List<PropertyPath<E>> orderedPropertyPaths = Lists.newArrayList(propertyPaths);
        if (log.isDebugEnabled()) {
            log.debug("fetching " + keys.size() + " values for properties " + orderedPropertyPaths);
        }
        List<Object[]> result = _dao.runQuery(buildQueryForProperty(orderedPropertyPaths, keys));
        packageResultIntoTuples(tuples, orderedPropertyPaths, result);
    }
    return tuples;
}

From source file:com.flaptor.indextank.rpc.StoringClient.java

@Override
public void enqueueUpdateBoosts(String indexId, String sourceDocId, Map<Integer, Float> boosts) {
    TSocket transport = new TSocket(host, port);
    TProtocol protocol = new TBinaryProtocol(transport);
    Storage.Client client = new Storage.Client(protocol);

    try {/* w  w w. jav  a2s .co  m*/
        transport.open();
        Map<Integer, Double> doubleBoosts = Maps.newHashMapWithExpectedSize(boosts.size());
        for (Entry<Integer, Float> entry : boosts.entrySet()) {
            doubleBoosts.put(entry.getKey(), entry.getValue().doubleValue());
        }

        client.enqueueUpdateBoosts(indexId, sourceDocId, doubleBoosts);
        transport.close();
    } catch (IndextankException e) {
        throw new RuntimeException(e);
    } catch (TTransportException e) {
        throw new RuntimeException(e);
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.xtext.common.types.access.binary.asm.JvmAnnotationTargetBuilder.java

protected Map<String, JvmTypeParameter> createTypeParameters(AbstractBinarySignature signature,
        JvmTypeParameterDeclarator container, Map<String, JvmTypeParameter> knownTypeParameters) {

    List<BinaryTypeParameter> typeParameters = signature.getTypeParameters();
    if (typeParameters.size() != 0) {
        Map<String, JvmTypeParameter> result = Maps.newHashMapWithExpectedSize(
                (knownTypeParameters != null ? knownTypeParameters.size() : 0) + typeParameters.size());
        if (knownTypeParameters != null)
            result.putAll(knownTypeParameters);
        InternalEList<JvmTypeParameter> jvmTypeParameters = (InternalEList<JvmTypeParameter>) container
                .getTypeParameters();/*from   ww w . ja  va2  s.c  om*/
        for (int i = 0; i < typeParameters.size(); i++) {
            JvmTypeParameter typeParameter = TypesFactory.eINSTANCE.createJvmTypeParameter();
            String name = typeParameters.get(i).getName();
            typeParameter.setName(name);
            jvmTypeParameters.addUnique(typeParameter);
            result.put(name, typeParameter);
        }

        for (int i = 0; i < typeParameters.size(); i++) {
            List<BinaryGenericTypeSignature> bounds = typeParameters.get(i).getBounds();
            JvmTypeParameter typeParameter = jvmTypeParameters.get(i);
            InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) typeParameter
                    .getConstraints();
            for (int j = 0; j < bounds.size(); j++) {
                JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
                ((JvmTypeConstraintImplCustom) upperBound)
                        .internalSetTypeReference(proxies.createTypeReference(bounds.get(j), result));
                constraints.addUnique(upperBound);
            }
        }
        return result;
    }
    return knownTypeParameters;
}

From source file:org.apache.shindig.gadgets.spec.UserPref.java

/**
 * Performs substitutions on the pref. See field comments for details on what
 * is substituted./*  w  w  w.  ja v  a 2 s.co m*/
 *
 * @param substituter
 * @return The substituted pref.
 */
public UserPref substitute(Substitutions substituter) {
    UserPref pref = new UserPref(this);
    pref.displayName = substituter.substituteString(displayName);
    pref.defaultValue = substituter.substituteString(defaultValue);
    if (enumValues.isEmpty()) {
        pref.enumValues = Collections.emptyMap();
    } else {
        Map<String, String> values = Maps.newHashMapWithExpectedSize(enumValues.size());
        for (Map.Entry<String, String> entry : enumValues.entrySet()) {
            values.put(entry.getKey(), substituter.substituteString(entry.getValue()));
        }
        pref.enumValues = ImmutableMap.copyOf(values);
    }
    if (orderedEnumValues.isEmpty()) {
        pref.orderedEnumValues = Collections.emptyList();
    } else {
        List<EnumValuePair> orderedValues = Lists.newLinkedList();
        for (EnumValuePair evp : orderedEnumValues) {
            orderedValues.add(
                    new EnumValuePair(evp.getValue(), substituter.substituteString(evp.getDisplayValue())));
        }
        pref.orderedEnumValues = Collections.unmodifiableList(orderedValues);
    }
    return pref;
}

From source file:org.gradoop.flink.algorithms.fsm.functions.SubgraphDecoder.java

@Override
public GraphTransaction map(Subgraph value) throws Exception {

    // GRAPH HEAD

    PropertyList properties = new PropertyList();

    properties.set(FREQUENCY_KEY, value.getCount());
    properties.set(CANONICAL_LABEL_KEY, value.getSubgraph());

    GraphHead epgmGraphHead = graphHeadFactory.createGraphHead(SUBGRAPH_LABEL, properties);

    GradoopIdSet graphIds = GradoopIdSet.fromExisting(epgmGraphHead.getId());

    // VERTICES/*from   w  w w  .  j  a  v  a  2  s .  c om*/

    Map<Integer, String> vertices = value.getEmbedding().getVertices();
    Set<Vertex> epgmVertices = Sets.newHashSetWithExpectedSize(vertices.size());
    Map<Integer, GradoopId> vertexIdMap = Maps.newHashMapWithExpectedSize(vertices.size());

    for (Map.Entry<Integer, String> vertex : vertices.entrySet()) {
        Vertex epgmVertex = vertexFactory.createVertex(vertex.getValue(), graphIds);

        vertexIdMap.put(vertex.getKey(), epgmVertex.getId());
        epgmVertices.add(epgmVertex);

    }

    // EDGES

    Collection<FSMEdge> edges = value.getEmbedding().getEdges().values();
    Set<Edge> epgmEdges = Sets.newHashSetWithExpectedSize(edges.size());

    for (FSMEdge edge : edges) {
        epgmEdges.add(edgeFactory.createEdge(edge.getLabel(), vertexIdMap.get(edge.getSourceId()),
                vertexIdMap.get(edge.getTargetId()), graphIds));
    }

    return new GraphTransaction(epgmGraphHead, epgmVertices, epgmEdges);
}