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:cpw.mods.fml.common.network.ModListResponsePacket.java

@Override
public FMLPacket consumePacket(byte[] data) {
    ByteArrayDataInput dat = ByteStreams.newDataInput(data);
    int versionListSize = dat.readInt();
    modVersions = Maps.newHashMapWithExpectedSize(versionListSize);
    for (int i = 0; i < versionListSize; i++) {
        String modName = dat.readUTF();
        String modVersion = dat.readUTF();
        modVersions.put(modName, modVersion);
    }/*w ww .j ava2 s.c  o m*/

    int missingModSize = dat.readInt();
    missingMods = Lists.newArrayListWithExpectedSize(missingModSize);

    for (int i = 0; i < missingModSize; i++) {
        missingMods.add(dat.readUTF());
    }
    return this;
}

From source file:org.attribyte.api.http.RequestBuilderWithParameters.java

/**
 * Creates a request builder with parameter case-sensitivity specified.
 * @param uri The URI./*w ww.  jav  a2s.  c  o m*/
 * @param caseSensitiveParameters Should case be preserved for URI parameter names?
 */
protected RequestBuilderWithParameters(final URI uri, final boolean caseSensitiveParameters) {
    super(uri);
    this.caseSensitiveParameters = caseSensitiveParameters;
    this.parameters = Maps.newHashMapWithExpectedSize(8);
}

From source file:org.gradoop.flink.algorithms.fsm.functions.SingleEdgeEmbeddings.java

@Override
public void flatMap(FSMGraph graph, Collector<SubgraphEmbeddings> out) throws Exception {

    Map<Integer, String> vertices = graph.getVertices();
    Map<String, Collection<Embedding>> subgraphEmbeddings = Maps.newHashMap();

    for (Map.Entry<Integer, FSMEdge> entry : graph.getEdges().entrySet()) {

        FSMEdge edge = entry.getValue();
        int sourceId = edge.getSourceId();
        int targetId = edge.getTargetId();

        Map<Integer, String> incidentVertices = Maps.newHashMapWithExpectedSize(2);

        incidentVertices.put(sourceId, vertices.get(sourceId));

        if (sourceId != targetId) {
            incidentVertices.put(targetId, vertices.get(targetId));
        }/* w ww  . j a va 2s. c  o  m*/

        Map<Integer, FSMEdge> singleEdge = Maps.newHashMapWithExpectedSize(1);
        singleEdge.put(entry.getKey(), edge);

        Embedding embedding = new Embedding(incidentVertices, singleEdge);

        String subgraph = canonicalLabeler.label(embedding);

        Collection<Embedding> embeddings = subgraphEmbeddings.get(subgraph);

        if (embeddings == null) {
            subgraphEmbeddings.put(subgraph, Lists.newArrayList(embedding));
        } else {
            embeddings.add(embedding);
        }
    }

    reuseTuple.setGraphId(graph.getId());
    reuseTuple.setSize(1);

    for (Map.Entry<String, Collection<Embedding>> entry : subgraphEmbeddings.entrySet()) {

        reuseTuple.setSubgraph(entry.getKey());
        reuseTuple.setEmbeddings(entry.getValue());

        out.collect(reuseTuple);
    }
}

From source file:org.geosdi.geoplatform.connector.api.GeoPlatformServerPool.java

/**
 * // w w  w  .j ava  2s  . c  o  m
 * @param capacity for HashMap
 */
public GeoPlatformServerPool(GPPoolCapacity theCapacity) {
    this.pool = Maps.newHashMapWithExpectedSize(theCapacity.getValue());
    this.capacity = theCapacity;
}

From source file:com.atlassian.jira.rest.client.internal.json.CimFieldsInfoMapJsonParser.java

@Override
public Map<String, CimFieldInfo> parse(JSONObject json) throws JSONException {
    final Map<String, CimFieldInfo> res = Maps.newHashMapWithExpectedSize(json.length());
    final Iterator keysIterator = json.keys();
    while (keysIterator.hasNext()) {
        final String id = (String) keysIterator.next();
        res.put(id, parseIssueFieldInfo(json.getJSONObject(id), id));
    }/*from   www .  j a va  2 s .c o m*/
    return res;
}

From source file:org.openscience.cdk.io.MDLValence.java

/**
 * Apply the MDL valence model to the provided atom container.
 *
 * @param container an atom container loaded from an MDL format
 * @return the container (for convenience)
 *//*ww  w .java  2 s  .  c o m*/
static IAtomContainer apply(IAtomContainer container) {

    int n = container.getAtomCount();

    int[] valences = new int[n];

    Map<IAtom, Integer> atomToIndex = Maps.newHashMapWithExpectedSize(n);
    for (IAtom atom : container.atoms())
        atomToIndex.put(atom, atomToIndex.size());

    // compute the bond order sums
    for (IBond bond : container.bonds()) {
        int u = atomToIndex.get(bond.getAtom(0));
        int v = atomToIndex.get(bond.getAtom(1));

        int bondOrder = bond.getOrder().numeric();

        valences[u] += bondOrder;
        valences[v] += bondOrder;
    }

    for (int i = 0; i < n; i++) {

        IAtom atom = container.getAtom(i);
        Integer charge = atom.getFormalCharge();
        Integer element = atom.getAtomicNumber();

        if (element == null)
            continue;

        // unset = 0 in this case
        charge = charge == null ? 0 : charge;

        int explicit = valences[i];

        // if there was a valence read from the mol file use that otherwise
        // use the default value from the valence model to set the correct
        // number of implied hydrogens
        if (atom.getValency() != null) {
            atom.setImplicitHydrogenCount(atom.getValency() - explicit);
        } else {
            int implicit = implicitValence(element, charge, valences[i]);
            atom.setImplicitHydrogenCount(implicit - explicit);
            atom.setValency(implicit);
        }
    }

    return container;
}

From source file:org.opendaylight.netconf.test.tool.rpc.SimulatedCreateSubscription.java

public SimulatedCreateSubscription(final String id, final Optional<File> notificationsFile) {
    super(id);//from  w w w  .j  a v  a  2 s .c o  m

    Optional<Notifications> notifications;

    if (notificationsFile.isPresent()) {
        notifications = Optional.of(loadNotifications(notificationsFile.get()));
        scheduledExecutorService = Executors.newScheduledThreadPool(1);
    } else {
        notifications = Optional.absent();
    }

    if (notifications.isPresent()) {
        Map<Notification, NetconfMessage> preparedMessages = Maps
                .newHashMapWithExpectedSize(notifications.get().getNotificationList().size());
        for (final Notification notification : notifications.get().getNotificationList()) {
            final NetconfMessage parsedNotification = parseNetconfNotification(notification.getContent());
            preparedMessages.put(notification, parsedNotification);
        }
        this.notifications = preparedMessages;
    } else {
        this.notifications = Collections.emptyMap();
    }

}

From source file:com.android.tools.perflib.vmtrace.VmTraceData.java

private VmTraceData(Builder b) {
    mVersion = b.mVersion;//from w  w w .j  a  v  a  2s .  c om
    mDataFileOverflow = b.mDataFileOverflow;
    mVmClockType = b.mVmClockType;
    mVm = b.mVm;
    mTraceProperties = b.mProperties;
    mMethods = b.mMethods;

    mThreadInfo = Maps.newHashMapWithExpectedSize(b.mThreads.size());
    for (int i = 0; i < b.mThreads.size(); i++) {
        int id = b.mThreads.keyAt(i);
        String name = b.mThreads.valueAt(i);

        ThreadInfo info = mThreadInfo.get(name);
        if (info != null) {
            // there is alread a thread with the same name
            name = String.format("%1$s-%2$d", name, id);
        }

        info = new ThreadInfo(id, name, b.mTopLevelCalls.get(id));
        mThreadInfo.put(name, info);
    }
}

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

@Override
public Map<List<String>, LabeledResult> apply(List<Metric> updates) {
    Map<List<String>, LabeledResult> aResults = a.apply(updates);
    Map<List<String>, LabeledResult> bResults = b.apply(updates);

    Map<List<String>, LabeledResult> results = Maps.newHashMapWithExpectedSize(aResults.size());
    for (Map.Entry<List<String>, LabeledResult> entry : aResults.entrySet()) {
        LabeledResult aRes = entry.getValue();
        LabeledResult bRes = bResults.get(entry.getKey());
        // current behavior is to omit the result if either key is not present
        if (bRes != null) {
            String resLabel = String.format("%s %s %s", aRes.getLabel(), op.getSymbol(), bRes.getLabel());
            double value = op.apply(aRes.getValue(), bRes.getValue());
            results.put(entry.getKey(), new LabeledResult(resLabel, value));
        }//from w w w .j ava  2  s. c  o  m
    }
    return results;
}

From source file:org.summer.dsl.builder.clustering.CopiedResourceDescription.java

public CopiedResourceDescription(IResourceDescription original) {
    this.uri = original.getURI();
    this.exported = ImmutableList.copyOf(Iterables.transform(original.getExportedObjects(),
            new Function<IEObjectDescription, IEObjectDescription>() {
                public IEObjectDescription apply(IEObjectDescription from) {
                    if (from.getEObjectOrProxy().eIsProxy()) {
                        return from;
                    }/*from   w  w w. j  ava2 s.  c om*/
                    InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass());
                    result.eSetProxyURI(from.getEObjectURI());
                    Map<String, String> userData = null;
                    for (final String key : from.getUserDataKeys()) {
                        if (userData == null) {
                            userData = Maps.newHashMapWithExpectedSize(2);
                        }
                        userData.put(key, from.getUserData(key));
                    }
                    return EObjectDescription.create(from.getName(), result, userData);
                }
            }));
}