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.dishevelled.venn.layout.BinaryVennLayoutImpl.java

/**
 * Create a new binary venn layout with the specified parameters.
 *
 * @param firstShape shape for the first set, must not be null
 * @param secondShape shape for the second set, must not be null
 * @param firstOnlyLuneCenter lune center for the first only area
 * @param secondOnlyLuneCenter lune center for the second only area
 * @param intersectionLuneCenter lune center for the intersection area
 * @param boundingRectangle bounding rectangle, must not be null
 *//*from  w w w .ja va 2 s. c o  m*/
public BinaryVennLayoutImpl(final Shape firstShape, final Shape secondShape, final Point2D firstOnlyLuneCenter,
        final Point2D secondOnlyLuneCenter, final Point2D intersectionLuneCenter,
        final Rectangle2D boundingRectangle) {
    if (firstShape == null) {
        throw new IllegalArgumentException("firstShape must not be null");
    }
    if (secondShape == null) {
        throw new IllegalArgumentException("secondShape must not be null");
    }
    if (boundingRectangle == null) {
        throw new IllegalArgumentException("boundingRectangle must not be null");
    }
    // todo: defensive copy?
    this.firstShape = firstShape;
    this.secondShape = secondShape;
    this.firstOnlyLuneCenter = firstOnlyLuneCenter;
    this.secondOnlyLuneCenter = secondOnlyLuneCenter;
    this.intersectionLuneCenter = intersectionLuneCenter;
    this.boundingRectangle = boundingRectangle;

    luneCenters = Maps.newHashMapWithExpectedSize(3);

    luneCenters.put(toImmutableBitSet(0), this.firstOnlyLuneCenter);
    luneCenters.put(toImmutableBitSet(1), this.secondOnlyLuneCenter);

    luneCenters.put(toImmutableBitSet(0, 1), this.intersectionLuneCenter);
    // copy to immutable map?
}

From source file:com.android.tools.idea.run.CloudProjectIdLabel.java

private void rememberChosenProjectId() {
    if (isProjectSpecified()) {
        myLastChosenProjectIdPerKind.put(myConfigurationKind, getText());
    }/*from w  w  w.  jav a  2 s .c o m*/

    if (myCurrentConfiguration == null || myCurrentModule == null) {
        return;
    }

    Map<Pair<Kind, Module>, String> projectByModuleCache = myProjectByConfigurationAndModuleCache
            .get(myCurrentConfiguration);
    if (projectByModuleCache == null) {
        projectByModuleCache = Maps.newHashMapWithExpectedSize(5);
        myProjectByConfigurationAndModuleCache.put(myCurrentConfiguration, projectByModuleCache);
    }
    projectByModuleCache.put(Pair.create(myConfigurationKind, myCurrentModule), getText());
}

From source file:com.google.gitiles.LogServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    Repository repo = ServletUtils.getRepository(req);
    RevWalk walk = null;//from  w  w w. j  a  v a  2s  .  co  m
    try {
        try {
            walk = newWalk(repo, view);
        } catch (IncorrectObjectTypeException e) {
            res.setStatus(SC_NOT_FOUND);
            return;
        }

        Optional<ObjectId> start = getStart(view.getParameters(), walk.getObjectReader());
        if (start == null) {
            res.setStatus(SC_NOT_FOUND);
            return;
        }

        Map<String, Object> data = Maps.newHashMapWithExpectedSize(5);

        if (!view.getRevision().nameIsId()) {
            List<Map<String, Object>> tags = Lists.newArrayListWithExpectedSize(1);
            for (RevObject o : RevisionServlet.listObjects(walk, view.getRevision().getId())) {
                if (o instanceof RevTag) {
                    tags.add(new TagSoyData(linkifier, req).toSoyData((RevTag) o));
                }
            }
            if (!tags.isEmpty()) {
                data.put("tags", tags);
            }
        }

        Paginator paginator = new Paginator(walk, limit, start.orNull());
        Map<AnyObjectId, Set<Ref>> refsById = repo.getAllRefsByPeeledObjectId();
        List<Map<String, Object>> entries = Lists.newArrayListWithCapacity(limit);
        for (RevCommit c : paginator) {
            entries.add(new CommitSoyData(null, req, repo, walk, view, refsById).toSoyData(c, KeySet.SHORTLOG));
        }

        String title = "Log - ";
        if (view.getOldRevision() != Revision.NULL) {
            title += view.getRevisionRange();
        } else {
            title += view.getRevision().getName();
        }

        data.put("title", title);
        data.put("entries", entries);
        ObjectId next = paginator.getNextStart();
        if (next != null) {
            data.put("nextUrl", copyAndCanonicalize(view).replaceParam(START_PARAM, next.name()).toUrl());
        }
        ObjectId prev = paginator.getPreviousStart();
        if (prev != null) {
            GitilesView.Builder prevView = copyAndCanonicalize(view);
            if (!prevView.getRevision().getId().equals(prev)) {
                prevView.replaceParam(START_PARAM, prev.name());
            }
            data.put("previousUrl", prevView.toUrl());
        }

        render(req, res, "gitiles.logDetail", data);
    } catch (RevWalkException e) {
        log.warn("Error in rev walk", e);
        res.setStatus(SC_INTERNAL_SERVER_ERROR);
        return;
    } finally {
        if (walk != null) {
            walk.release();
        }
    }
}

From source file:com.romeikat.datamessie.core.base.dao.impl.SourceDao.java

public Map<Document, Source> getForDocuments(final SharedSessionContract ssc,
        final Collection<Document> documents) {
    final Set<Long> sourceIds = documents.stream().map(d -> d.getSourceId()).collect(Collectors.toSet());
    final Map<Long, Source> sourcesById = getIdsWithEntities(ssc, sourceIds);

    final Map<Document, Source> result = Maps.newHashMapWithExpectedSize(documents.size());
    for (final Document document : documents) {
        final Source source = sourcesById.get(document.getSourceId());
        result.put(document, source);//  w w w .  ja v a  2 s . c  om
    }
    return result;
}

From source file:org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase.java

@Override
protected <T> void copyProperties(T dictionaryBaseBean) {
    super.copyProperties(dictionaryBaseBean);
    UifDictionaryBeanBase uifDictionaryBeanBaseCopy = (UifDictionaryBeanBase) dictionaryBaseBean;

    if (expressionGraph != null) {
        Map<String, String> expressionGraphCopy = Maps
                .newHashMapWithExpectedSize(this.getExpressionGraph().size());
        for (Map.Entry expressionGraphEntry : getExpressionGraph().entrySet()) {
            expressionGraphCopy.put(expressionGraphEntry.getKey().toString(),
                    expressionGraphEntry.getValue().toString());
        }/*from   w  ww .  j  a  va2  s. com*/

        uifDictionaryBeanBaseCopy.setExpressionGraph(expressionGraphCopy);
    }

    if (refreshExpressionGraph != null) {
        Map<String, String> refreshExpressionGraphCopy = Maps
                .newHashMapWithExpectedSize(this.getRefreshExpressionGraph().size());
        for (Map.Entry refreshExpressionGraphEntry : getRefreshExpressionGraph().entrySet()) {
            refreshExpressionGraphCopy.put(refreshExpressionGraphEntry.getKey().toString(),
                    refreshExpressionGraphEntry.getValue().toString());
        }

        uifDictionaryBeanBaseCopy.setRefreshExpressionGraph(refreshExpressionGraphCopy);
    }

    if (propertyExpressions != null) {
        Map<String, String> propertyExpressionsCopy = Maps
                .newHashMapWithExpectedSize(this.getPropertyExpressions().size());
        for (Map.Entry propertyExpressionsEntry : getPropertyExpressions().entrySet()) {
            propertyExpressionsCopy.put(propertyExpressionsEntry.getKey().toString(),
                    propertyExpressionsEntry.getValue().toString());
        }

        uifDictionaryBeanBaseCopy.setPropertyExpressions(propertyExpressionsCopy);
    }
}

From source file:com.google.devtools.build.lib.skyframe.SkyframeTargetPatternEvaluator.java

@Override
public Map<String, ResolvedTargets<Target>> preloadTargetPatterns(EventHandler eventHandler,
        Collection<String> patterns, boolean keepGoing) throws TargetParsingException, InterruptedException {
    // TODO(bazel-team): This is used only in "blaze query". There are plans to dramatically change
    // how query works on Skyframe, in which case this method is likely to go away.
    // We cannot use an ImmutableMap here because there may be null values.
    Map<String, ResolvedTargets<Target>> result = Maps.newHashMapWithExpectedSize(patterns.size());
    for (String pattern : patterns) {
        // TODO(bazel-team): This could be parallelized to improve performance. [skyframe-loading]
        result.put(pattern, parseTargetPattern(eventHandler, pattern, keepGoing));
    }// w w w.  j a v  a 2 s  .c o m
    return result;
}

From source file:org.sosy_lab.cpachecker.core.algorithm.pdr.transition.Reindexer.java

public static <F extends Formula> F reindex(F pOldFormula, SSAMap pFormulaSSAMap, int pLowIndex,
        BiFunction<String, Integer, Integer> pConvertIndex, FormulaManagerView pFormulaManager) {
    Set<String> allVariables = pFormulaSSAMap.allVariables();
    Set<String> allIndexedVariables = pFormulaManager.extractVariableNames(pOldFormula);
    Map<String, String> substitution = Maps.newHashMapWithExpectedSize(allVariables.size());
    for (String variableName : allVariables) {
        CType type = pFormulaSSAMap.getType(variableName);
        int highIndex = pFormulaSSAMap.getIndex(variableName);
        for (int index = pLowIndex; index <= highIndex; ++index) {
            SSAMap oldSSAMap = SSAMap.emptySSAMap().builder().setIndex(variableName, type, index).build();
            String oldVariableName = pFormulaManager.instantiate(Collections.singleton(variableName), oldSSAMap)
                    .iterator().next();/*from w  w  w  .j av a2s .  c o m*/
            if (allIndexedVariables.contains(oldVariableName)) {
                int newIndex = pConvertIndex.apply(variableName, index);
                SSAMap newSSAMap = SSAMap.emptySSAMap().builder().setIndex(variableName, type, newIndex)
                        .build();
                String newVariableName = pFormulaManager
                        .instantiate(Collections.singleton(variableName), newSSAMap).iterator().next();
                substitution.put(oldVariableName, newVariableName);
            }
        }
    }
    return pFormulaManager.renameFreeVariablesAndUFs(pOldFormula, (oldName) -> {
        String substitute = substitution.get(oldName);
        return substitute != null ? substitute : oldName;
    });
}

From source file:com.google.cloud.dataflow.sdk.coders.MapCoder.java

@Override
public Map<K, V> decode(InputStream inStream, Context context) throws IOException, CoderException {
    DataInputStream dataInStream = new DataInputStream(inStream);
    int size = dataInStream.readInt();
    Map<K, V> retval = Maps.newHashMapWithExpectedSize(size);
    for (int i = 0; i < size; ++i) {
        K key = keyCoder.decode(inStream, context.nested());
        V value = valueCoder.decode(inStream, context.nested());
        retval.put(key, value);/*from   ww w .  j a  va  2s .c  om*/
    }
    return retval;
}

From source file:org.axdt.avm.access.AvmLibrary.java

protected Map<QualifiedName, List<IEObjectDescription>> getNameToObjects() {
    if (nameToObjects == null) {
        synchronized (this) {
            if (nameToObjects == null) {
                Map<QualifiedName, List<IEObjectDescription>> nameToObjects = Maps
                        .newHashMapWithExpectedSize(getExportedObjects().size());
                if (getExportedObjects() instanceof RandomAccess) {
                    for (int i = 0; i < getExportedObjects().size(); i++) {
                        IEObjectDescription description = getExportedObjects().get(i);
                        putIntoMap(nameToObjects, description);
                    }/* ww w .jav  a  2s  . c  om*/
                } else {
                    for (IEObjectDescription description : getExportedObjects()) {
                        putIntoMap(nameToObjects, description);
                    }
                }
                this.nameToObjects = nameToObjects;
            }
        }
    }
    return this.nameToObjects;
}

From source file:org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.java

@Override
public Terms.Bucket getBucketByKey(String term) {
    if (bucketMap == null) {
        bucketMap = Maps.newHashMapWithExpectedSize(buckets.size());
        for (Bucket bucket : buckets) {
            bucketMap.put(bucket.getKey(), bucket);
        }//from w  ww  . j a  v  a  2  s .  c  o m
    }
    return bucketMap.get(term);
}