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.opengamma.engine.marketdata.live.LiveMarketDataPermissionProvider.java

private Map<LiveDataSpecification, Collection<ValueSpecification>> getRequiredLiveDataSpecifications(
        final Set<ValueSpecification> specifications) {
    final Map<LiveDataSpecification, Collection<ValueSpecification>> returnValue = Maps
            .newHashMapWithExpectedSize(specifications.size());
    for (final ValueSpecification specification : specifications) {
        final LiveDataSpecification liveDataSpec = LiveMarketDataAvailabilityProvider
                .getLiveDataSpecification(specification);
        Collection<ValueSpecification> specs = returnValue.get(liveDataSpec);
        if (specs == null) {
            specs = new ArrayList<ValueSpecification>();
            returnValue.put(liveDataSpec, specs);
        }//w w  w. j a  v  a 2 s. c  om
        specs.add(specification);
    }
    return returnValue;
}

From source file:org.eclipse.hawkbit.ui.artifacts.footer.UploadViewConfirmationWindowLayout.java

@Override
protected Map<String, ConfirmationTab> getConfirmationTabs() {
    final Map<String, ConfirmationTab> tabs = Maps.newHashMapWithExpectedSize(2);
    if (!artifactUploadState.getDeleteSofwareModules().isEmpty()) {
        tabs.put(i18n.getMessage("caption.delete.swmodule.accordion.tab"), createSMDeleteConfirmationTab());
    }/* w  ww .  jav  a 2s.  c o m*/
    if (!artifactUploadState.getSelectedDeleteSWModuleTypes().isEmpty()) {
        tabs.put(i18n.getMessage("caption.delete.sw.module.type.accordion.tab"),
                createSMtypeDeleteConfirmationTab());
    }
    return tabs;
}

From source file:com.attribyte.essem.model.Application.java

private ImmutableMap<Metric.Type, ImmutableSet<Metric>> buildTypeMap(final Collection<Metric> metrics) {
    if (metrics != null && metrics.size() > 0) {
        Map<Metric.Type, ImmutableSet.Builder<Metric>> builderMap = Maps
                .newHashMapWithExpectedSize(metrics.size());

        for (Metric metric : metrics) {
            ImmutableSet.Builder<Metric> setBuilder = builderMap.get(metric.type);
            if (setBuilder == null) {
                setBuilder = ImmutableSet.builder();
                builderMap.put(metric.type, setBuilder);
            }/*w ww.  java2 s .  c om*/
            setBuilder.add(metric);
        }

        ImmutableMap.Builder<Metric.Type, ImmutableSet<Metric>> builder = ImmutableMap.builder();
        for (Map.Entry<Metric.Type, ImmutableSet.Builder<Metric>> entry : builderMap.entrySet()) {
            builder.put(entry.getKey(), entry.getValue().build());
        }

        return builder.build();

    } else {
        return ImmutableMap.of();
    }
}

From source file:org.caleydo.core.data.collection.table.CategoricalTable.java

@Override
protected void normalize() {
    if (categoricalClassDescription == null) {
        Set<CategoryType> uniqueCategories = new HashSet<>();
        for (AColumn<?, ?> column : columns) {
            @SuppressWarnings("unchecked")
            CategoricalColumn<CategoryType> catCol = (CategoricalColumn<CategoryType>) column;
            uniqueCategories.addAll(catCol.getCategories());
        }//  www. j  av  a2s  .  co  m
        categoricalClassDescription = new CategoricalClassDescription<>();
        categoricalClassDescription.autoInitialize(uniqueCategories);
        for (AColumn<?, ?> column : columns) {
            @SuppressWarnings("unchecked")
            CategoricalColumn<CategoryType> catCol = (CategoricalColumn<CategoryType>) column;
            catCol.setCategoryDescriptions(categoricalClassDescription);
        }

    }
    super.normalize();

    //no build the opposite num matches
    //first one use to initialize

    {
        @SuppressWarnings("unchecked")
        CategoricalColumn<CategoryType> firstColumn = (CategoricalColumn<CategoryType>) columns.get(0);
        int numCategories = getCategoryDescriptions().getCategoryProperties().size();
        oppositeNumMatches = new ArrayList<>(firstColumn.size());
        for (int i = 0; i < firstColumn.size(); ++i) {
            CategoryType v = firstColumn.getRaw(i);
            HashMap<CategoryType, Integer> hist = Maps.newHashMapWithExpectedSize(numCategories);
            hist.put(v, 1);
            oppositeNumMatches.add(hist);
        }
    }
    for (AColumn<?, ?> col : columns.subList(1, columns.size())) {
        @SuppressWarnings("unchecked")
        CategoricalColumn<CategoryType> column = (CategoricalColumn<CategoryType>) col;
        for (int i = 0; i < col.size(); ++i) {
            CategoryType v = column.getRaw(i);
            Map<CategoryType, Integer> hist = oppositeNumMatches.get(i);
            Integer h = hist.get(v);
            if (h == null)
                hist.put(v, 1);
            else
                hist.put(v, h + 1);
        }
    }
}

From source file:com.google.gerrit.lucene.LuceneVersionManager.java

@Inject
LuceneVersionManager(@GerritServerConfig Config cfg, SitePaths sitePaths,
        Collection<IndexDefinition<?, ?, ?>> defs) {
    this.sitePaths = sitePaths;
    this.defs = Maps.newHashMapWithExpectedSize(defs.size());
    for (IndexDefinition<?, ?, ?> def : defs) {
        this.defs.put(def.getName(), def);
    }/*from  ww  w. j a  v  a2 s . co m*/

    reindexers = Maps.newHashMapWithExpectedSize(defs.size());
    onlineUpgrade = cfg.getBoolean("index", null, "onlineUpgrade", true);
    runReindexMsg = "No index versions ready; run java -jar " + sitePaths.gerrit_war.toAbsolutePath()
            + " reindex";
}

From source file:org.opennms.web.rest.measurements.fetch.JrobinFetchStrategy.java

/**
 * {@inheritDoc}//from   w ww .ja  v  a2 s.  c  om
 */
@Override
protected FetchResults fetchMeasurements(long start, long end, long step, int maxrows,
        Map<Source, String> rrdsBySource, Map<String, Object> constants) throws RrdException {

    final long startInSeconds = (long) Math.floor(start / 1000);
    final long endInSeconds = (long) Math.floor(end / 1000);

    long stepInSeconds = (long) Math.floor(step / 1000);
    // The step must be strictly positive
    if (stepInSeconds <= 0) {
        stepInSeconds = 1;
    }

    final DataProcessor dproc = new DataProcessor(startInSeconds, endInSeconds);
    if (maxrows > 0) {
        dproc.setPixelCount(maxrows);
    }
    dproc.setFetchRequestResolution(stepInSeconds);

    for (final Map.Entry<Source, String> entry : rrdsBySource.entrySet()) {
        final Source source = entry.getKey();
        final String rrdFile = entry.getValue();

        dproc.addDatasource(source.getLabel(), rrdFile, source.getAttribute(), source.getAggregation());
    }

    try {
        dproc.processData();
    } catch (IOException e) {
        throw new RrdException("JRB processing failed.", e);
    }

    final long[] timestamps = dproc.getTimestamps();

    // Convert the timestamps to milliseconds
    for (int i = 0; i < timestamps.length; i++) {
        timestamps[i] *= 1000;
    }

    final Map<String, double[]> columns = Maps.newHashMapWithExpectedSize(rrdsBySource.keySet().size());
    for (Source source : rrdsBySource.keySet()) {
        columns.put(source.getLabel(), dproc.getValues(source.getLabel()));
    }

    return new FetchResults(timestamps, columns, dproc.getStep() * 1000, constants);
}

From source file:org.sonatype.nexus.proxy.maven.packaging.DefaultArtifactPackagingMapper.java

public Map<String, String> getPackaging2extensionMapping() {
    if (packaging2extensionMapping == null) {
        synchronized (this) {
            if (packaging2extensionMapping == null) {
                packaging2extensionMapping = Maps.newHashMapWithExpectedSize(defaults.size());

                // merge defaults
                packaging2extensionMapping.putAll(defaults);

                if (propertiesFile != null && propertiesFile.exists()) {
                    log.info("Found artifact packaging mapping file {}", propertiesFile);

                    final Properties userMappings = new Properties();

                    try (final FileInputStream fis = new FileInputStream(propertiesFile)) {
                        userMappings.load(fis);

                        if (userMappings.keySet().size() > 0) {
                            for (Object key : userMappings.keySet()) {
                                packaging2extensionMapping.put(key.toString(),
                                        userMappings.getProperty(key.toString()));
                            }/*from  ww  w .  ja  va2  s . c o m*/

                            log.info("User artifact packaging mapping file contained {} mappings",
                                    userMappings.keySet().size());
                        }
                    } catch (IOException e) {
                        log.warn("Got IO exception during read of file: {}", propertiesFile.getAbsolutePath(),
                                e);
                    }
                } else {
                    // make it silent if using defaults
                    log.debug("User artifact packaging mappings file not found, will work with defaults...");
                }
            }
        }
    }

    return packaging2extensionMapping;
}

From source file:com.pinterest.terrapin.thrift.TerrapinServiceImpl.java

/**
 * @param configuration Config settings containing settings such
 * @throws Exception//from   w w w .j av a  2 s  . co  m
 */
public TerrapinServiceImpl(PropertiesConfiguration configuration, List<String> clusterList) throws Exception {
    String zkQuorum = TerrapinUtil.getZKQuorumFromConf(configuration);
    Preconditions.checkNotNull(zkQuorum, "Zookeeper quorum should not be empty/null.");
    ZooKeeperClient zkClient = TerrapinUtil.getZooKeeperClient(zkQuorum, 30);
    this.clusterClientMap = Maps.newHashMapWithExpectedSize(clusterList.size());
    for (String clusterName : clusterList) {
        try {
            FileSetViewManager fsViewManager = new FileSetViewManager(zkClient, clusterName);
            LOG.info("Connecting to cluster " + clusterName + " on " + zkQuorum);
            TerrapinClient terrapinClient = new TerrapinClient(fsViewManager, clusterName,
                    configuration.getInt(Constants.TERRAPIN_SERVER_TARGET_PORT, Constants.DEFAULT_THRIFT_PORT),
                    configuration.getInt(Constants.CLIENT_CONNECT_TIMEOUT_MILLIS, 300),
                    configuration.getInt(Constants.CLIENT_RPC_TIMEOUT_MILLIS, 500));
            clusterClientMap.put(clusterName, terrapinClient);
            LOG.info("Done.");
        } catch (Exception e) {
            LOG.warn("Could not connect to cluster " + clusterName, e);
            throw e;
        }
    }
}

From source file:voldemort.store.compress.CompressingStore.java

@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys,
        Map<ByteArray, byte[]> transforms) throws VoldemortException {
    StoreUtils.assertValidKeys(keys);//ww  w .ja v a  2s .c o  m
    Iterable<ByteArray> processedKeys = keys;
    List<ByteArray> deflatedKeys = Lists.newArrayList();
    for (ByteArray key : keys)
        deflatedKeys.add(deflateKey(key));
    processedKeys = deflatedKeys;
    Map<ByteArray, byte[]> newTransforms = Maps.newHashMap();
    if (transforms != null) {
        for (Map.Entry<ByteArray, byte[]> transform : transforms.entrySet()) {
            newTransforms.put(deflateKey(transform.getKey()), transform.getValue());
        }
    } else {
        for (ByteArray deflatedKey : processedKeys) {
            newTransforms.put(deflatedKey, null);
        }
    }
    Map<ByteArray, List<Versioned<byte[]>>> deflatedResult = innerStore.getAll(processedKeys, newTransforms);
    Map<ByteArray, List<Versioned<byte[]>>> result = Maps.newHashMapWithExpectedSize(deflatedResult.size());
    for (Map.Entry<ByteArray, List<Versioned<byte[]>>> mapEntry : deflatedResult.entrySet())
        result.put(inflateKey(mapEntry.getKey()), inflateValues(mapEntry.getValue()));
    return result;
}

From source file:org.gradle.internal.locking.DependencyLockingArtifactVisitor.java

@Override
public void startArtifacts(RootGraphNode root) {
    RootConfigurationMetadata metadata = root.getMetadata();
    dependencyLockingState = metadata.getDependencyLockingState();
    if (dependencyLockingState.mustValidateLockState()) {
        Set<ModuleComponentIdentifier> lockedModules = dependencyLockingState.getLockedDependencies();
        modulesToBeLocked = Maps.newHashMapWithExpectedSize(lockedModules.size());
        for (ModuleComponentIdentifier lockedModule : lockedModules) {
            modulesToBeLocked.put(lockedModule.getModuleIdentifier(), lockedModule);
        }//from w w  w . j a v  a  2  s. c o  m
        allResolvedModules = Sets.newHashSetWithExpectedSize(this.modulesToBeLocked.size());
        extraModules = Sets.newHashSet();
    } else {
        modulesToBeLocked = Collections.emptyMap();
        allResolvedModules = Sets.newHashSet();
    }
}