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:edu.umn.msi.tropix.webgui.server.xml.GridUserFunctionImpl.java

public Map<String, String> apply(final GridUser gridUser) {
    final Map<String, String> map = Maps.newHashMapWithExpectedSize(4);
    // Using short field names to reduce data transferred, this is not a
    // premature optimization.
    map.put("f", gridUser.getFirstName());
    map.put("l", gridUser.getLastName());
    map.put("g", gridUser.getGridId());
    map.put("u", getUsername(gridUser));
    map.put("i", gridUser.getInstitution());
    return map;/*ww  w  .  j a v  a 2s. c o  m*/
}

From source file:org.auraframework.component.ui.ListProvider.java

@Override
public ComponentConfig provide() throws QuickFixException {
    BaseComponent<?, ?> component = Aura.getContextService().getCurrentContext().getCurrentComponent();
    ComponentConfig cc = new ComponentConfig();
    Map<String, Object> m = Maps.newHashMapWithExpectedSize(1);
    // so now we're relying on the fact that the data provider's model has items on it, thats fantastic.
    m.put("items",
            component.getAttributes().getValue(new PropertyReferenceImpl("dataProvider.0.m.items", null)));
    cc.setAttributes(m);//www  . j  a v a  2s.  c o m
    return cc;
}

From source file:com.google.gerrit.server.git.ReceiveCommitsAdvertiseRefsHook.java

@Override
public void advertiseRefs(BaseReceivePack rp) {
    Map<String, Ref> oldRefs = rp.getAdvertisedRefs();
    if (oldRefs == null) {
        oldRefs = rp.getRepository().getAllRefs();
    }//from   w w  w.  j av  a  2  s . com
    Map<String, Ref> r = Maps.newHashMapWithExpectedSize(oldRefs.size());
    for (Map.Entry<String, Ref> e : oldRefs.entrySet()) {
        String name = e.getKey();
        if (!skip(name)) {
            r.put(name, e.getValue());
        }
    }
    rp.setAdvertisedRefs(r, rp.getAdvertisedObjects());
}

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

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

From source file:com.textocat.textokit.commons.wfstore.DefaultWordformStoreBuilder.java

@Override
public DefaultWordformStore<TagType> build() {
    DefaultWordformStore<TagType> result = new DefaultWordformStore<TagType>();
    result.strKeyMap = Maps.newHashMapWithExpectedSize(strKeyMap.size());
    for (String wf : strKeyMap.keySet()) {
        Multiset<TagType> tagBag = strKeyMap.get(wf);
        int max = 0;
        TagType maxTag = null;//from   w w w .  j a v  a 2s  .c om
        for (Multiset.Entry<TagType> tagEntry : tagBag.entrySet()) {
            if (tagEntry.getCount() > max) {
                max = tagEntry.getCount();
                maxTag = tagEntry.getElement();
            }
        }
        if (maxTag == null) {
            throw new IllegalStateException();
        }
        result.strKeyMap.put(wf, maxTag);
    }
    return result;
}

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

@Override
public Map<List<String>, LabeledResult> apply(List<Metric> updates) {
    Map<List<String>, LabeledResult> aResults = a.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(op.getFormat(), aRes.getLabel());
        results.put(entry.getKey(), new LabeledResult(resLabel, op.apply(aRes.getValue())));
    }//from  ww  w  .j  ava  2  s. co  m

    return results;
}

From source file:org.auraframework.throwable.InvalidSessionException.java

@Override
public Event getEvent() {
    try {/*from  w ww  . j  av  a2 s.  c  om*/
        Map<String, Object> args = Maps.newHashMapWithExpectedSize(1);
        args.put("newToken", this.newToken);
        return Aura.getInstanceService().getInstance("aura:invalidSession", EventDef.class, args);
    } catch (QuickFixException x) {
        throw new AuraRuntimeException(x);
    }
}

From source file:abstractions.piece.PieceManager.java

private Map<Integer, PieceInterface> initializeData(final Map<SideInterface, Set<PieceInterface>> map) {
    final Map<Integer, PieceInterface> data = Maps.newHashMapWithExpectedSize(map.size());
    for (final Entry<SideInterface, Set<PieceInterface>> mapEntry : map.entrySet()) {
        for (final PieceInterface sidedPiece : mapEntry.getValue()) {
            data.put(this.hash(sidedPiece.getSide(), sidedPiece.getType()), sidedPiece);
        }/*from  ww  w.j av a  2s  .co m*/
    }
    return ImmutableMap.copyOf(data);
}

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

private static Map<PTableKey, PTableRef> newMap(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:org.apache.shindig.gadgets.config.XhrwrapperConfigContributor.java

/** {@inheritDoc} */
public void contribute(Map<String, Object> config, Gadget gadget) {
    Map<String, String> xhrWrapperConfig = Maps.newHashMapWithExpectedSize(2);
    View view = gadget.getCurrentView();
    Uri contentsUri = view.getHref();/*  w  ww . j a  va  2s .c o m*/
    xhrWrapperConfig.put("contentUrl", contentsUri == null ? "" : contentsUri.toString());
    if (AuthType.OAUTH.equals(view.getAuthType())) {
        addOAuthConfig(xhrWrapperConfig, view);
    } else if (AuthType.SIGNED.equals(view.getAuthType())) {
        xhrWrapperConfig.put("authorization", "signed");
    }
    config.put("shindig.xhrwrapper", xhrWrapperConfig);
}