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.cordovastudio.editors.designer.model.DeletionHandler.java

/**
 * Creates a new {@link DeletionHandler}
 *
 * @param deleted the deleted nodes/*from w w  w .  ja  v  a 2 s . co m*/
 * @param moved   nodes that were moved (e.g. deleted, but also inserted elsewhere)
 * @param layout  the parent layout of the deleted nodes
 */
public DeletionHandler(@NotNull List<RadViewComponent> deleted, @NotNull List<RadViewComponent> moved,
        @NotNull RadViewComponent layout) {
    myDeleted = deleted;
    myChildren = layout.getChildren();
    myNodeMap = Maps.newHashMapWithExpectedSize(myChildren.size());
    for (RadViewComponent view : RadViewComponent.getViewComponents(myChildren)) {
        String id = view.getId();
        if (id != null) {
            myNodeMap.put(id, view);
        }
    }

    myDeletedIds = Sets.newHashSetWithExpectedSize(myDeleted.size());
    for (RadViewComponent node : myDeleted) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.add(id);
        }
    }

    // Any widgets that remain (e.g. typically because they were moved) should
    // keep their incoming dependencies
    for (RadViewComponent node : moved) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.remove(id);
        }
    }
}

From source file:org.apache.shindig.gadgets.config.CoreUtilConfigContributor.java

/** {@inheritDoc} */
public void contribute(Map<String, Object> config, Gadget gadget) {
    // Add gadgets.util support. This is calculated dynamically based on request inputs.
    ModulePrefs prefs = gadget.getSpec().getModulePrefs();
    Collection<Feature> features = prefs.getFeatures().values();
    Map<String, Map<String, Object>> featureMap = Maps.newHashMapWithExpectedSize(features.size());
    Set<String> allFeatureNames = registry.getAllFeatureNames();

    for (Feature feature : features) {
        // Skip unregistered features
        if (!allFeatureNames.contains(feature.getName())) {
            continue;
        }//w  w  w .ja v a  2s.co  m
        // Flatten out the multimap a bit for backwards compatibility:  map keys
        // with just 1 value into the string, treat others as arrays
        Map<String, Object> paramFeaturesInConfig = Maps.newHashMap();
        for (String paramName : feature.getParams().keySet()) {
            Collection<String> paramValues = feature.getParams().get(paramName);
            if (paramValues.size() == 1) {
                paramFeaturesInConfig.put(paramName, paramValues.iterator().next());
            } else {
                paramFeaturesInConfig.put(paramName, paramValues);
            }
        }

        featureMap.put(feature.getName(), paramFeaturesInConfig);
    }
    config.put("core.util", featureMap);
}

From source file:com.android.tools.idea.experimental.codeanalysis.callgraph.CHAUtil.java

public void buildBitSetIndex() {
    PsiCFGClass[] applicationClassArray = mScene.getAllApplicationClasses();
    PsiCFGClass[] libraryClassArray = mScene.getAllLibraryClasses();
    int numofBits = applicationClassArray.length + libraryClassArray.length;
    if (numofBits < 0) {
        throw new RuntimeException("Number of classes in this project is larger than 2G.");
    }/*from   w  w  w . j a  va2 s.c  om*/
    mClassIndexArray = new PsiCFGClass[numofBits];
    mClassIndexMap = Maps.newHashMapWithExpectedSize(numofBits);
    int i = 0;
    for (; i < applicationClassArray.length; i++) {
        mClassIndexArray[i] = applicationClassArray[i];
        mClassIndexMap.put(applicationClassArray[i], i);
    }
    for (; i < numofBits; i++) {
        mClassIndexArray[i] = libraryClassArray[i - applicationClassArray.length];
        mClassIndexMap.put(libraryClassArray[i - applicationClassArray.length], i);
    }
}

From source file:de.learnlib.datastructure.observationtable.reader.SuffixASCIIReader.java

private Map<String, I> generateNameToSymbolMap(Alphabet<I> alphabet) {
    Map<String, I> nameToSymbol = Maps.newHashMapWithExpectedSize(alphabet.size());

    for (I symbol : alphabet) {
        String symbolName = symbol.toString();
        if (nameToSymbol.containsKey(symbolName)) {
            throw new IllegalArgumentException(
                    "Symbol name '" + symbolName + "' is used more than once in alphabet");
        } else {//from  w  w w. jav  a 2 s . c  om
            nameToSymbol.put(symbolName, symbol);
        }
    }

    return nameToSymbol;
}

From source file:org.auraframework.impl.root.component.IterationProvider.java

@Override
public ComponentConfig provide() throws QuickFixException {
    AuraContext context = Aura.getContextService().getCurrentContext();
    BaseComponent<?, ?> component = context.getCurrentComponent();
    ComponentConfig cc = new ComponentConfig();
    List<Component> components = Lists.newArrayList();
    InstanceStack iStack = context.getInstanceStack();
    Map<String, Object> m = Maps.newHashMapWithExpectedSize(1);
    m.put("body", components);
    cc.setAttributes(m);/* w  w  w  . j a va 2s  .co  m*/

    AttributeSet atts = component.getAttributes();
    Iterable<?> value = atts.getValue("items", Iterable.class);
    if (value != null) {
        List<?> items = Lists.newArrayList(value);
        if (!items.isEmpty()) {
            String var = atts.getValue("var", String.class);
            String indexVar = atts.getValue("indexVar", String.class);

            int realstart = 0;
            int realend = items.size();

            ComponentDefRefArrayImpl template = atts.getValue("body", ComponentDefRefArrayImpl.class);
            m.put("template", template);
            Integer start = getIntValue(atts.getValue("start"));
            Integer end = getIntValue(atts.getValue("end"));
            if (start == null && end == null) {
                // int page = (Integer)atts.getValue("page");
                // int pageSize = (Integer)atts.getValue("pageSize");
            } else {
                if (start != null && start > realstart) {
                    realstart = start;
                }

                if (end != null && end < realend) {
                    realend = end;
                }
            }

            // boolean reverse = (Boolean)atts.getValue("reverse");
            iStack.setAttributeName("body");
            for (int i = realstart; i < realend; i++) {
                iStack.setAttributeIndex(i);
                iStack.pushInstance(component, component.getDescriptor());
                iStack.setAttributeName("body");
                Map<String, Object> providers = Maps.newHashMap();
                providers.put(var, items.get(i));
                if (indexVar != null) {
                    providers.put(indexVar, i);
                }
                components.addAll(template.newInstance(atts.getValueProvider(), providers));
                iStack.clearAttributeName("body");
                iStack.popInstance(component);
                iStack.clearAttributeIndex(i);
            }
            iStack.clearAttributeName("body");
        }
    }

    return cc;
}

From source file:com.opengamma.financial.analytics.fudgemsg.YieldCurveBundleBuilder.java

@Override
public YieldCurveBundle buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
    // note name in curve & name in bundle may be different!
    final List<FudgeField> curveFields = message.getAllByName(CURVES_FIELD_NAME);
    final List<FudgeField> curveNameFields = message.getAllByName(CURVES_NAME_FIELD_NAME);
    final List<FudgeField> ccyFields = message.getAllByName(CURRENCY_FIELD_NAME);
    final List<FudgeField> ccyCurveFields = message.getAllByName(CURRENCY_CURVE_FIELD_NAME);
    final Map<String, YieldAndDiscountCurve> curves = new LinkedHashMap<>(curveFields.size());
    final Map<String, Currency> curveCurrencys = Maps.newHashMapWithExpectedSize(ccyFields.size());
    final FXMatrix fxMatrix = deserializer.fieldValueToObject(FXMatrix.class,
            message.getByName(FX_MATRIX_FIELD_NAME));
    for (int i = 0; i < curveFields.size(); i++) {
        final YieldAndDiscountCurve curve = deserializer.fieldValueToObject(YieldAndDiscountCurve.class,
                curveFields.get(i));//from  w w  w  .j ava2s  .co  m
        final String name = deserializer.fieldValueToObject(String.class, curveNameFields.get(i));
        curves.put(name, curve);
    }
    for (int i = 0; i < ccyFields.size(); i++) {
        final String name = deserializer.fieldValueToObject(String.class, ccyCurveFields.get(i));
        final Currency ccy = deserializer.fieldValueToObject(Currency.class, ccyFields.get(i));
        curveCurrencys.put(name, ccy);
    }

    return new YieldCurveBundle(fxMatrix, curveCurrencys, curves);
}

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

@Override
public Map<String, Object> getParameters() {
    Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(2);
    parameters.put("tachyonPath", mTachyonPath);
    parameters.put("ufsPath", mUfsPath);
    return parameters;
}

From source file:org.sonatype.nexus.configuration.ModelloUtils.java

/**
 * {@link List} of {@link CProps} to {@link Map} converter, to ease handling of these thingies.
 *//*ww w  .jav  a  2  s .c o  m*/
public static Map<String, String> getMapFromConfigList(List<CProps> list) {
    final Map<String, String> result = Maps.newHashMapWithExpectedSize(list.size());
    for (CProps props : list) {
        result.put(props.getKey(), props.getValue());
    }
    return result;
}

From source file:shaded.org.openqa.selenium.remote.server.handler.internal.ResultConverter.java

public Object apply(Object result) {
    if (result instanceof WebElement) {
        String elementId = knownElements.add((WebElement) result);
        return ImmutableMap.of("ELEMENT", elementId);
    }/* w w w  .  j  ava 2s  .co  m*/

    if (result instanceof List) {
        @SuppressWarnings("unchecked")
        List<Object> resultAsList = (List<Object>) result;
        return Lists.newArrayList(Iterables.transform(resultAsList, this));
    }

    if (result instanceof Map<?, ?>) {
        Map<?, ?> resultAsMap = (Map<?, ?>) result;
        Map<Object, Object> converted = Maps.newHashMapWithExpectedSize(resultAsMap.size());
        for (Map.Entry<?, ?> entry : resultAsMap.entrySet()) {
            converted.put(entry.getKey(), apply(entry.getValue()));
        }
        return converted;
    }

    if (result instanceof ResultSet) {
        Map<Object, Object> converted = Maps.newHashMap();
        converted.put("insertId", ((ResultSet) result).getLastInsertedRowId());
        converted.put("rowsAffected", ((ResultSet) result).getNumberOfRowsAffected());
        ResultSetRows rsRows = ((ResultSet) result).rows();
        List<Map<String, Object>> rows = Lists.newArrayList();
        for (int i = 0; i < rsRows.size(); i++) {
            rows.add(rsRows.item(i));
        }
        converted.put("rows", Lists.newArrayList(Iterables.transform(rows, this)));
        return converted;
    }

    return result;
}

From source file:com.jivesoftware.os.amza.client.http.Ring.java

public RingMemberAndHost[] orderedRing(List<RingMember> membersInOrder) {
    List<RingMemberAndHost> ordered = Lists.newArrayListWithCapacity(members.length);
    if (membersInOrder == null) {
        if (leaderIndex >= 0) {
            ordered.add(members[leaderIndex]);
        }//from   w w w . j a va  2  s .  c  o m
        for (int i = 0; i < members.length; i++) {
            if (i != leaderIndex) {
                ordered.add(members[i]);
            }
        }
    } else {
        Map<RingMember, RingMemberAndHost> memberHosts = Maps.newHashMapWithExpectedSize(members.length);
        for (RingMemberAndHost member : members) {
            memberHosts.put(member.ringMember, member);
        }
        for (RingMember ringMember : membersInOrder) {
            RingMemberAndHost ringMemberAndHost = memberHosts.remove(ringMember);
            if (ringMemberAndHost != null) {
                ordered.add(ringMemberAndHost);
            }
        }
        for (RingMemberAndHost ringMemberAndHost : memberHosts.values()) {
            ordered.add(ringMemberAndHost);
        }
    }
    return ordered.toArray(new RingMemberAndHost[0]);
}