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.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria.java

private static Map<String, Object> createDropHintConfigurations() {
    final Map<String, Object> config = Maps.newHashMapWithExpectedSize(4);
    config.put(SPUIDefinitions.DISTRIBUTION_TYPE_ID_PREFIXS, DragEvent.DISTRIBUTION_TYPE_DRAG);
    config.put(UIComponentIdProvider.DIST_TABLE_ID, DragEvent.DISTRIBUTION_DRAG);
    config.put(UIComponentIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE, DragEvent.SOFTWAREMODULE_DRAG);
    config.put(SPUIDefinitions.SOFTWARE_MODULE_TAG_ID_PREFIXS, DragEvent.SOFTWAREMODULE_TYPE_DRAG);
    return config;
}

From source file:org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper.java

public static List<Row> createExpectedRows(String[] columnNames, Object[]... values) {
    int timeIndex = Arrays.asList(columnNames).indexOf(ColumnHolder.TIME_COLUMN_NAME);
    Preconditions.checkArgument(timeIndex >= 0);

    List<Row> expected = Lists.newArrayList();
    for (Object[] value : values) {
        Preconditions.checkArgument(value.length == columnNames.length);
        Map<String, Object> theVals = Maps.newHashMapWithExpectedSize(value.length);
        for (int i = 0; i < columnNames.length; i++) {
            if (i != timeIndex) {
                theVals.put(columnNames[i], value[i]);
            }/*from   w  w w.j av a 2 s .  c o  m*/
        }
        expected.add(new MapBasedRow(new DateTime(value[timeIndex], ISOChronology.getInstanceUTC()), theVals));
    }
    return expected;
}

From source file:org.gradoop.flink.algorithms.fsm.pojos.Embedding.java

/**
 * Combines this embedding with another one.
 *
 * @param that other embedding/*from w w w. j  av  a  2 s.co  m*/
 *
 * @return combined embedding
 */
public Embedding combine(Embedding that) {

    Map<Integer, String> commonVertices = Maps.newHashMap(vertices);
    commonVertices.putAll(that.vertices);

    Map<Integer, FSMEdge> commonEdges = Maps.newHashMapWithExpectedSize(this.edges.size() + that.edges.size());

    commonEdges.putAll(this.edges);
    commonEdges.putAll(that.edges);

    return new Embedding(commonVertices, commonEdges);
}

From source file:ml.grafos.okapi.common.graph.SortedOutEdges.java

@Override
public void initialize(int capacity) {
    edgeMap = Maps.newHashMapWithExpectedSize(capacity);
}

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

public StatisticsData mergeState(StatisticsData state2) {
    assert data.size() == state2.data.size() : "sized and properties have to match";
    Map<StatisticsProvider, StatisticsDataProvider> merged = Maps.newHashMapWithExpectedSize(data.size());
    for (Entry<StatisticsProvider, StatisticsDataProvider> providerEntry : data.entrySet()) {
        merged.put(providerEntry.getKey(),
                providerEntry.getValue().mergePath(state2.data.get(providerEntry.getKey())));
    }/* www .  ja v  a 2  s .  co  m*/
    return new StatisticsData(merged);
}

From source file:com.twitter.nodes.utils.Futures.java

/**
 * Wait for a map of futures and return a future of map, with the keys mapping to the value
 * returned from corresponding futures.//from www. j a  va  2  s  .  co m
 */
public static <K, V> Future<Map<K, V>> collect(final Map<K, Future<V>> futures) {
    try {
        List<Future<Tuple2<K, V>>> entries = Lists.newArrayListWithCapacity(futures.size());
        for (final Map.Entry<K, Future<V>> entry : futures.entrySet()) {
            entries.add(map(entry.getValue(), new Function0<Tuple2<K, V>>() {
                public Tuple2<K, V> apply() {
                    try {
                        return scala.Tuple2$.MODULE$.apply(entry.getKey(), Await.result(entry.getValue()));
                    } catch (Exception e) {
                        return Throwables.unchecked(e);
                    }
                }
            }));
        }

        final Future<List<Tuple2<K, V>>> listFuture = Future.collect(entries);

        return map(listFuture, new Function0<Map<K, V>>() {
            public Map<K, V> apply() {
                Map<K, V> result = Maps.newHashMapWithExpectedSize(futures.size());
                try {
                    for (Tuple2<K, V> pair : Await.result(listFuture)) {
                        result.put(pair._1(), pair._2());
                    }
                    return result;
                } catch (Exception e) {
                    return Throwables.unchecked(e);
                }
            }
        });
    } catch (Exception e) {
        return Throwables.unchecked(e);
    }
}

From source file:edu.umn.msi.tropix.proteomics.itraqquantitation.impl.TrainingWeightFunctionImpl.java

TrainingWeightFunctionImpl(final QuantificationWeights weights) {
    final Map<Double, Double> weightMap = Maps.newHashMapWithExpectedSize(weights.getWeight().length);
    for (QuantificationWeight weight : weights.getWeight()) {
        weightMap.put(weight.getIntensity(), weight.getWeight());
    }//from   w  w w . j a  v a  2s .co  m
    final List<Double> sortedIntensities = Lists.newArrayList(weightMap.keySet());
    Collections.sort(sortedIntensities);
    this.trainingMatrix = new double[sortedIntensities.size()][2];
    int i = 0;
    for (final Double intensity : sortedIntensities) {
        trainingMatrix[i][0] = intensity;
        trainingMatrix[i][1] = weightMap.get(intensity);
        i++;
    }
}

From source file:org.gradoop.flink.io.impl.json.functions.JSONToEntity.java

/**
 * Reads the key-value properties from the json object.
 *
 * @param object json object//  w w w.j  a v a  2s.co m
 * @return key-value properties
 * @throws JSONException
 */
protected Map<String, Object> getProperties(JSONObject object) throws JSONException {
    Map<String, Object> props = Maps.newHashMapWithExpectedSize(object.length() * 2);
    object = object.getJSONObject(JSONConstants.DATA);
    Iterator<?> keys = object.keys();
    while (keys.hasNext()) {
        String key = keys.next().toString();
        Object o = object.get(key);
        props.put(key, o);
    }
    return props;
}

From source file:com.sahlbach.maven.delivery.Delivery.java

/**
 * creates a merged version of two deliveries.
 * jobs are deeply merged/*from  w w  w  .java  2  s  .co m*/
 * @param toMerge delivers the overwritten values of the delivery
 * @throws org.apache.maven.plugin.MojoExecutionException in case of merge conflicts
 * @return the merged instance (this) for call chaining
 */
public Delivery mergeWith(Delivery toMerge) throws MojoExecutionException {
    setId(toMerge.getId());
    if (toMerge.getDescription() != null)
        setDescription(toMerge.getDescription());
    Map<String, Job> mappedJobs = Maps.newHashMapWithExpectedSize(getJobs().size() + toMerge.getJobs().size());
    List<Job> resultJobs = Lists.newArrayListWithCapacity(getJobs().size() + toMerge.getJobs().size());
    for (Job job : getJobs()) {
        Job newJob = new Job();
        newJob.mergeWith(job);
        if (newJob.getId() != null)
            mappedJobs.put(newJob.getId(), newJob);
        resultJobs.add(newJob);
    }
    for (Job job : toMerge.getJobs()) {
        if ((job.getId() != null) && mappedJobs.get(job.getId()) != null) {
            Job existingJob = mappedJobs.get(job.getId());
            existingJob.mergeWith(job);
        } else {
            resultJobs.add(new Job().mergeWith(job));
        }
    }
    setJobs(resultJobs);
    return this;
}

From source file:org.eclipse.xtext.ecore.EcoreResourceDescriptionStrategy.java

protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedNameProvider, boolean isNsURI,
        EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
    try {/*from  w w  w. j  av  a  2  s. c  o  m*/
        QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject);
        if (qualifiedName != null) {
            Map<String, String> userData = Maps.newHashMapWithExpectedSize(1);
            userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI));
            IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData);
            acceptor.accept(description);
            return true;
        }
    } catch (Exception exc) {
        LOG.error(exc.getMessage(), exc);
    }
    return false;
}