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.openqa.selenium.remote.server.handler.internal.ArgumentConverter.java

public Object apply(Object arg) {
    if (arg instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> paramAsMap = (Map<String, Object>) arg;
        if (paramAsMap.containsKey("ELEMENT")) {
            KnownElements.ProxiedElement element = (KnownElements.ProxiedElement) knownElements
                    .get((String) paramAsMap.get("ELEMENT"));
            return element.getWrappedElement();
        }/*from  w ww.  ja  va2 s . c o m*/

        Map<String, Object> converted = Maps.newHashMapWithExpectedSize(paramAsMap.size());
        for (Map.Entry<String, Object> entry : paramAsMap.entrySet()) {
            converted.put(entry.getKey(), apply(entry.getValue()));
        }
        return converted;
    }

    if (arg instanceof List<?>) {
        return Lists.newArrayList(Iterables.transform((List<?>) arg, this));
    }

    return arg;
}

From source file:org.opennms.newts.aggregate.Rate.java

Rate(Iterator<Row<Sample>> input, Set<String> metrics) {
    m_input = checkNotNull(input, "input argument");
    m_metrics = checkNotNull(metrics, "metrics argument");
    m_prevSamples = Maps.newHashMapWithExpectedSize(m_metrics.size());
}

From source file:com.doctusoft.bean.binding.observable.ObservableMap.java

public ObservableMap(int size) {
    delegate = Maps.newHashMapWithExpectedSize(size);
    initReflectingSets();
}

From source file:org.impressivecode.depress.mg.po.ChangeDataTransformer.java

public Map<String, ChangeData> transformChangeData(final BufferedDataTable changeHistory,
        final ExecutionContext exec) throws CanceledExecutionException {
    Map<String, ChangeData> changeData = Maps.newHashMapWithExpectedSize(1000);
    CloseableRowIterator iterator = changeHistory.iterator();
    while (iterator.hasNext()) {
        progress(exec);/*from   ww  w  .ja  va 2  s  .c o  m*/
        ChangeData curr = transform(iterator.next());
        String key = curr.getClassName();
        changeData.put(key, mergeChangeData(changeData.get(key), curr));
    }
    iterator.close();
    return changeData;
}

From source file:com.webbfontaine.valuewebb.irms.core.IrmsCriterionRepository.java

private static Object getGroovyCompileOptimisationOptions() {
    Map<String, Boolean> options = Maps.newHashMapWithExpectedSize(1);
    options.put("indy", false);

    return options;
}

From source file:net.automatalib.words.impl.SimpleAlphabet.java

public SimpleAlphabet(Collection<? extends I> symbols) {
    this.symbols = new ArrayList<>(symbols);
    this.indexMap = Maps.newHashMapWithExpectedSize(symbols.size()); // TODO: replace by primitive specialization
    int i = 0;//w w  w .  ja  v  a  2s.  c o  m
    for (I sym : this.symbols) {
        indexMap.put(sym, i++);
    }
}

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

@Override
public Map<String, Object> getParameters() {
    Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(6);
    parameters.put("id", mId);
    parameters.put("parentId", mParentId);
    parameters.put("name", mName);
    parameters.put("persisted", mPersisted);
    parameters.put("pinned", mPinned);
    parameters.put("creationTimeMs", mCreationTimeMs);
    parameters.put("lastModificationTimeMs", mLastModificationTimeMs);
    return parameters;
}

From source file:org.apache.kylin.engine.mr.common.CuboidStatsReaderUtil.java

public static Map<Long, Long> readCuboidStatsFromSegments(Set<Long> cuboidIds, List<CubeSegment> segmentList)
        throws IOException {
    Map<Long, Long> statisticsMerged = Maps.newHashMapWithExpectedSize(cuboidIds.size());
    readCuboidStatsFromSegments(cuboidIds, segmentList, statisticsMerged,
            Maps.<Long, Double>newHashMapWithExpectedSize(cuboidIds.size()));
    return statisticsMerged.isEmpty() ? null : statisticsMerged;
}

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

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

From source file:voldemort.store.slop.strategy.ConsistentHandoffStrategy.java

/**
 * Creates a consistent handoff strategy instance
 * /*from  ww w .jav a 2 s.co  m*/
 * @param cluster The cluster
 * @param prefListSize The number of nodes adjacent to the failed node in
 *        the that could be selected to receive given hint
 * @param enableZoneRouting is zone routing enabled?
 * @param clientZoneId client zone id if zone routing is enabled
 */
public ConsistentHandoffStrategy(Cluster cluster, int prefListSize, boolean enableZoneRouting,
        int clientZoneId) {
    int nodesInCluster = cluster.getNumberOfNodes();
    if (prefListSize > nodesInCluster - 1)
        throw new IllegalArgumentException(
                "Preference list size must be less than " + "number of nodes in the cluster - 1");

    routeToMap = Maps.newHashMapWithExpectedSize(cluster.getNumberOfNodes());
    for (Node node : cluster.getNodes()) {
        List<Node> prefList = Lists.newArrayListWithCapacity(prefListSize);
        int i = node.getId();
        int n = 0;
        while (n < prefListSize) {
            i = (i + 1) % cluster.getNumberOfNodes();
            Node peer = cluster.getNodeById(i);
            if (peer.getId() != node.getId()) {
                if (enableZoneRouting && cluster.getZones().size() > 1) {
                    // don't handoff hints to the same zone
                    int zoneId = node.getZoneId();
                    if (clientZoneId == zoneId) {
                        if (peer.getZoneId() != zoneId)
                            continue;
                    } else {
                        if (peer.getZoneId() == zoneId)
                            continue;
                    }
                }
                prefList.add(peer);
                n++;
            }
            routeToMap.put(node.getId(), prefList);
        }
    }
}