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.eharmony.matching.seeking.mapper.ProjectedResultMapper.java

protected Map<String, Object> propertyMap(Object[] properties, String[] propertyNames) {
    if (properties.length != propertyNames.length) {
        throw new IllegalArgumentException("The number of properties (" + properties.length
                + ") must match the number of property names (" + propertyNames.length + ")");
    }// www.  j av a 2 s.c o m
    int n = properties.length;
    Map<String, Object> map = Maps.newHashMapWithExpectedSize(n);
    for (int i = 0; i < n; i++) {
        map.put(propertyNames[i], properties[i]);
    }
    return map;
}

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

@Override
public Map<String, Object> getParameters() {
    Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(2);
    parameters.put("id", mId);
    parameters.put("persisted", mPersisted);
    return parameters;
}

From source file:tachyon.master.lineage.journal.RequestFilePersistenceEntry.java

@Override
public Map<String, Object> getParameters() {
    Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(1);
    parameters.put("fileIds", mFileIds);
    return parameters;
}

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

@Override
public FloatingPaymentMatrix buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
    final List<FudgeField> dateFields = message.getAllByName(DATES_FIELD);
    final List<FudgeField> pairsField = message.getAllByName(PAIRS_FIELD);
    final Map<LocalDate, List<Pair<CurrencyAmount, String>>> values = Maps
            .newHashMapWithExpectedSize(dateFields.size());
    for (int i = 0; i < dateFields.size(); i++) {
        final LocalDate date = deserializer.fieldValueToObject(LocalDate.class, dateFields.get(i));
        final FudgeMsg perDateMessage = (FudgeMsg) pairsField.get(i).getValue();
        final List<FudgeField> caMessage = perDateMessage.getAllByName(CA_FIELD);
        final List<FudgeField> resetIndexMessage = perDateMessage.getAllByName(RESET_INDEX_FIELD);
        final List<Pair<CurrencyAmount, String>> list = Lists.newArrayListWithCapacity(caMessage.size());
        for (int j = 0; j < caMessage.size(); j++) {
            final CurrencyAmount ca = deserializer.fieldValueToObject(CurrencyAmount.class, caMessage.get(j));
            final String resetIndex = (String) deserializer.fieldValueToObject(String.class,
                    resetIndexMessage.get(j));
            list.add(Pair.of(ca, resetIndex));
        }/* w  ww  .j ava  2 s .c  om*/
        values.put(date, list);
    }
    final int maxAmounts = message.getInt(MAX_AMOUNTS_FIELD);
    return new FloatingPaymentMatrix(values, maxAmounts);
}

From source file:org.apache.beam.sdk.extensions.euphoria.core.testkit.accumulators.NanosecondTimer.java

@Override
public Map<Duration, Long> getSnapshot() {
    Map<Duration, Long> m = Maps.newHashMapWithExpectedSize(hist.buckets.size());
    hist.buckets.forEach((key, count) -> m.put(Duration.ofNanos(key), count));
    return m;//from  w w w  .java2  s  .c  o  m
}

From source file:tachyon.master.lineage.journal.DeleteLineageEntry.java

@Override
public Map<String, Object> getParameters() {
    Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(2);
    parameters.put("lineageId", mLineageId);
    parameters.put("cascade", mCascade);
    return parameters;
}

From source file:org.sonar.server.rule.index.RuleDoc.java

public RuleDoc() {
    super(Maps.newHashMapWithExpectedSize(15));
}

From source file:org.datacleaner.components.machinelearning.impl.VectorOneHotEncodingFeatureModifier.java

public VectorOneHotEncodingFeatureModifier(Collection<String> values) {
    this.values = Maps.newHashMapWithExpectedSize(values.size());
    int index = 0;
    for (String value : values) {
        this.values.put(value, index);
        index++;/*from   w ww  . j  a  v  a  2 s.c  o  m*/
    }
}

From source file:com.google.wave.splash.data.ProfileStore.java

/**
 * Retrieves participant profiles from a collection of participant ids.
 *
 * @param participantIds the participants to retrieve.
 * @return map of participant profiles./*  w  ww . j  a  va  2s .  co  m*/
 */
public Map<String, ParticipantProfile> getProfiles(Collection<String> participantIds) {
    Map<String, ParticipantProfile> profiles = Maps.newHashMapWithExpectedSize(participantIds.size());
    for (String id : participantIds) {
        profiles.put(id, getProfile(id));
    }
    return profiles;
}

From source file:org.sosy_lab.cpachecker.cpa.statistics.StatisticsData.java

public StatisticsData(Set<StatisticsProvider> propertyProviders) {
    Map<StatisticsProvider, StatisticsDataProvider> dataProvider = Maps
            .newHashMapWithExpectedSize(propertyProviders.size());
    for (StatisticsProvider providerEntry : propertyProviders) {
        dataProvider.put(providerEntry, providerEntry.createDataProvider());
    }//ww  w. j  ava2  s  . c o m
    data = dataProvider;
}