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.textocat.textokit.postagger.opennlp.DictionaryBasedContextGenerator.java

public DictionaryBasedContextGenerator(Iterable<String> targetGramCategories, MorphDictionary morphDict) {
    this.morphDict = morphDict;
    this.gramModel = morphDict.getGramModel();
    this.tagMapper = new GramModelBasedTagMapper(gramModel);
    // re-pack into a set to avoid duplicates and maintain ID-based ordering
    TreeSet<Grammeme> tagCatGrams = Sets.newTreeSet(Grammeme.numIdComparator());
    for (String tc : targetGramCategories) {
        Grammeme tcGram = gramModel.getGrammem(tc);
        if (tcGram == null) {
            throw new IllegalArgumentException(String.format("Tag category %s does not exist", tc));
        }/*from   w ww .j a  va 2 s.c  o  m*/
        tagCatGrams.add(tcGram);
    }
    this.targetTagCategoriesMap = Maps.newHashMapWithExpectedSize(tagCatGrams.size());
    this.targetCategoriesMask = new BitSet();
    for (Grammeme tcg : tagCatGrams) {
        BitSet tcBits = gramModel.getGrammemWithChildrenBits(tcg.getId(), true);
        targetTagCategoriesMap.put(tcg, tcBits);
        targetCategoriesMask.or(tcBits);
    }
    //
    namedPredicates = AgreementPredicates.numberGenderCaseCombinations(gramModel);
}

From source file:ru.runa.wf.logic.bot.MsWordReportTaskHandler.java

@Override
protected Map<String, Object> executeAction(VariableProvider variableProvider) throws Exception {
    File reportTemporaryFile = null;
    FileInputStream reportFileInputStream = null;
    try {//from   w  w  w .ja v  a2  s  .co  m
        reportTemporaryFile = File.createTempFile("prefix", ".doc");
        MsWordReportBuilder wordReportBuilder = MsWordReportBuilderFactory.createBuilder(settings,
                variableProvider);
        log.debug("Using template " + settings.getTemplateFileLocation());
        wordReportBuilder.build(reportTemporaryFile.getAbsolutePath());
        reportFileInputStream = new FileInputStream(reportTemporaryFile);
        byte[] fileContent = ByteStreams.toByteArray(reportFileInputStream);
        FileVariableImpl fileVariable = new FileVariableImpl(settings.getReportFileName(), fileContent,
                CONTENT_TYPE);
        Map<String, Object> result = Maps.newHashMapWithExpectedSize(1);
        result.put(settings.getReportVariableName(), fileVariable);
        return result;
    } finally {
        if (reportFileInputStream != null) {
            reportFileInputStream.close();
        }
        if (reportTemporaryFile != null) {
            if (!reportTemporaryFile.delete()) {
                log.warn("Unable to delete " + reportTemporaryFile.getAbsolutePath());
            }
        }
    }
}

From source file:org.apache.kylin.metrics.MetricsManager.java

private static void setSourceReporterBindProps(
        Map<ActiveReservoir, List<Pair<String, Properties>>> sourceReporterBindProperties) {
    sourceReporterBindProps = Maps.newHashMapWithExpectedSize(sourceReporterBindProperties.size());
    for (ActiveReservoir activeReservoir : sourceReporterBindProperties.keySet()) {
        List<Pair<Class<? extends ActiveReservoirReporter>, Properties>> values = Lists
                .newArrayListWithExpectedSize(sourceReporterBindProperties.get(activeReservoir).size());
        sourceReporterBindProps.put(activeReservoir, values);
        for (Pair<String, Properties> entry : sourceReporterBindProperties.get(activeReservoir)) {
            try {
                Class clz = Class.forName(entry.getKey());
                if (ActiveReservoirReporter.class.isAssignableFrom(clz)) {
                    values.add(new Pair(clz, entry.getValue()));
                } else {
                    logger.warn("The class " + clz + " is not a sub class of " + ActiveReservoir.class);
                }//from   w  ww  .j  a va 2s  . co m
            } catch (ClassNotFoundException e) {
                logger.warn("Cannot find class " + entry.getKey());
            }
        }
    }
}

From source file:org.eclipse.hawkbit.ui.management.event.ManagementViewAcceptCriteria.java

private static Map<String, Object> createDropHintConfigurations() {
    final Map<String, Object> config = Maps.newHashMapWithExpectedSize(4);
    config.put(SPUIDefinitions.TARGET_TAG_ID_PREFIXS, DragEvent.TARGET_TAG_DRAG);
    config.put(UIComponentIdProvider.TARGET_TABLE_ID, DragEvent.TARGET_DRAG);
    config.put(UIComponentIdProvider.DIST_TABLE_ID, DragEvent.DISTRIBUTION_DRAG);
    config.put(SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS, DragEvent.DISTRIBUTION_TAG_DRAG);
    return config;
}

From source file:org.apache.shindig.gadgets.config.ShindigAuthConfigContributor.java

/** {@inheritDoc} */
public void contribute(Map<String, Object> config, String container, String host) {
    // Inject an anonymous security token TODO set TTL based on cachability of this JS?
    SecurityToken containerToken = new AnonymousSecurityToken(container, 0, "*", 1000L * 60 * 60 * 24);
    Map<String, String> authConfig = Maps.newHashMapWithExpectedSize(2);

    try {//ww  w.  j a  v  a2s.  c  o  m
        config.put("shindig.auth", authConfig);
        authConfig.put("authToken", securityTokenCodec.encodeToken(containerToken));

    } catch (SecurityTokenException e) {
        // ignore
    }
}

From source file:com.preferanser.shared.domain.Editor.java

public Editor reset() {
    name = null;/*from w  w  w  . java 2s .  com*/
    description = null;
    firstTurn = null;
    players = null;
    widow = new Widow();
    handContracts = Maps.newHashMapWithExpectedSize(Hand.PLAYING_HANDS.size());
    centerCardHandMap = Maps.newLinkedHashMap(); // order is important
    handCardMultimap = LinkedHashMultimap.create(TableLocation.values().length, Card.values().length);
    return this;
}

From source file:voldemort.store.stats.ClusterWideCounter.java

public Map<Integer, Long> asMap() {
    Map<Integer, Long> map = Maps.newHashMapWithExpectedSize(values.size());
    for (Map.Entry<Integer, AtomicLong> entry : values.entrySet())
        map.put(entry.getKey(), entry.getValue().get());
    return Collections.unmodifiableMap(map);
}

From source file:com.qcadoo.model.integration.VerifyHooks.java

public void clear() {
    interactions = Maps.newHashMapWithExpectedSize(HookType.values().length);
    for (HookType type : HookType.values()) {
        interactions.put(type, 0);
    }
}

From source file:org.apache.shindig.auth.BasicSecurityToken.java

public BasicSecurityToken(String owner, String viewer, String app, String domain, String appUrl,
        String moduleId, String container, String activeUrl, Long expiresAt) throws BlobCrypterException {
    tokenData = Maps.newHashMapWithExpectedSize(7);
    putNullSafe(OWNER_KEY, owner);//from   www .  j  a  va2  s  . com
    putNullSafe(VIEWER_KEY, viewer);
    putNullSafe(APP_KEY, app);
    putNullSafe(DOMAIN_KEY, domain);
    putNullSafe(APPURL_KEY, appUrl);
    putNullSafe(MODULE_KEY, moduleId);
    putNullSafe(CONTAINER_KEY, container);
    if (expiresAt != null)
        putNullSafe(EXPIRES_KEY, expiresAt.toString());

    token = crypter.wrap(tokenData);
    this.activeUrl = activeUrl;
}

From source file:org.envirocar.server.rest.decoding.json.SensorDecoder.java

private Object parseObjectNode(JsonNode value) {
    Iterator<String> names = value.fieldNames();
    Map<String, Object> map = Maps.newHashMapWithExpectedSize(value.size());
    while (names.hasNext()) {
        String name = names.next();
        map.put(name, parseNode(value.path(name)));
    }//from w  ww .  ja  v  a 2 s.  c o  m
    return map;
}