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.android.tools.idea.run.CloudConfigurationComboBox.java

public CloudConfigurationComboBox(@NotNull Kind configurationKind) {
    myConfigurationKind = configurationKind;
    myConfigurationProvider = CloudConfigurationProvider.getCloudConfigurationProvider();
    setMinimumSize(new Dimension(100, getMinimumSize().height));

    getComboBox().setRenderer(new TestConfigurationRenderer());
    getComboBox().addActionListener(new ActionListener() {
        @Override/*  ww  w .  j  a  va 2 s . co  m*/
        public void actionPerformed(ActionEvent e) {
            Object item = getComboBox().getSelectedItem();
            if (item instanceof CloudConfiguration) {
                CloudConfiguration cloudConfiguration = (CloudConfiguration) item;
                myLastChosenCloudConfigurationPerKind.put(myConfigurationKind, cloudConfiguration);
                if (myCurrentAndroidConfiguration != null && myCurrentModule != null) {
                    Map<Pair<Kind, Module>, CloudConfiguration> matrixConfigurationByModuleCache = myMatrixConfigurationByAndroidConfigurationAndModuleCache
                            .get(myCurrentAndroidConfiguration);
                    if (matrixConfigurationByModuleCache == null) {
                        matrixConfigurationByModuleCache = Maps.newHashMapWithExpectedSize(5);
                        myMatrixConfigurationByAndroidConfigurationAndModuleCache
                                .put(myCurrentAndroidConfiguration, matrixConfigurationByModuleCache);
                    }
                    matrixConfigurationByModuleCache.put(Pair.create(myConfigurationKind, myCurrentModule),
                            cloudConfiguration);
                }
            }
        }
    });

    CloudConfigurationCoordinator.getInstance(myConfigurationKind).addComboBox(this);
}

From source file:org.apache.kylin.storage.translate.HBaseKeyRange.java

private void init(Collection<ColumnValueRange> andDimensionRanges) {
    int size = andDimensionRanges.size();
    Map<TblColRef, String> startValues = Maps.newHashMapWithExpectedSize(size);
    Map<TblColRef, String> stopValues = Maps.newHashMapWithExpectedSize(size);
    Map<TblColRef, Set<String>> fuzzyValues = Maps.newHashMapWithExpectedSize(size);
    for (ColumnValueRange dimRange : andDimensionRanges) {
        TblColRef column = dimRange.getColumn();
        startValues.put(column, dimRange.getBeginValue());
        stopValues.put(column, dimRange.getEndValue());
        fuzzyValues.put(column, dimRange.getEqualValues());

        TblColRef partitionDateColumnRef = cubeSeg.getCubeDesc().getModel().getPartitionDesc()
                .getPartitionDateColumnRef();
        if (column.equals(partitionDateColumnRef)) {
            initPartitionRange(dimRange);
        }/*from w  ww.  ja  v  a2 s.  c  o m*/
    }

    AbstractRowKeyEncoder encoder = new LazyRowKeyEncoder(cubeSeg, cuboid);
    encoder.setBlankByte(RowConstants.ROWKEY_LOWER_BYTE);
    this.startKey = encoder.encode(startValues);
    encoder.setBlankByte(RowConstants.ROWKEY_UPPER_BYTE);
    // In order to make stopRow inclusive add a trailing 0 byte. #See Scan.setStopRow(byte [] stopRow)
    this.stopKey = Bytes.add(encoder.encode(stopValues), ZERO_TAIL_BYTES);

    // always fuzzy match cuboid ID to lock on the selected cuboid
    this.fuzzyKeys = buildFuzzyKeys(fuzzyValues);
}

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

public Map<String, Object> toSoyData(ObjectId treeId, TreeWalk tw) throws MissingObjectException, IOException {
    List<Object> entries = Lists.newArrayList();
    GitilesView.Builder urlBuilder = GitilesView.path().copyFrom(view);
    while (tw.next()) {
        FileType type = FileType.forEntry(tw);
        String name = tw.getNameString();

        switch (view.getType()) {
        case PATH:
            urlBuilder.setTreePath(view.getTreePath() + "/" + name);
            break;
        case REVISION:
            // Got here from a tag pointing at a tree.
            urlBuilder.setTreePath(name);
            break;
        default://from   www.j a  va 2  s .co m
            throw new IllegalStateException(
                    String.format("Cannot render TreeSoyData from %s view", view.getType()));
        }

        String url = urlBuilder.toUrl();
        if (type == FileType.TREE) {
            name += "/";
            url += "/";
        }
        Map<String, String> entry = Maps.newHashMapWithExpectedSize(4);
        entry.put("type", type.toString());
        entry.put("name", name);
        entry.put("url", url);
        if (type == FileType.SYMLINK) {
            String target = new String(rw.getObjectReader().open(tw.getObjectId(0)).getCachedBytes(),
                    Charsets.UTF_8);
            // TODO(dborowitz): Merge Shawn's changes before copying these methods
            // in.
            entry.put("targetName", getTargetDisplayName(target));
            String targetUrl = resolveTargetUrl(view, target);
            if (targetUrl != null) {
                entry.put("targetUrl", targetUrl);
            }
        }
        entries.add(entry);
    }

    Map<String, Object> data = Maps.newHashMapWithExpectedSize(3);
    data.put("sha", treeId.name());
    data.put("entries", entries);

    if (view.getType() == GitilesView.Type.PATH && view.getRevision().getPeeledType() == OBJ_COMMIT) {
        data.put("logUrl", GitilesView.log().copyFrom(view).toUrl());
    }

    return data;
}

From source file:org.spongepowered.common.data.processor.multi.tileentity.FurnaceDataProcessor.java

@Override
protected Map<Key<?>, ?> getValues(TileEntityFurnace tileEntity) {
    HashMap<Key<?>, Integer> values = Maps.newHashMapWithExpectedSize(3);

    final int passedBurnTime = tileEntity.getField(1) - tileEntity.getField(0);
    final int maxBurnTime = tileEntity.getField(1);
    final int passedCookTime = tileEntity.getField(2);
    final int maxCookTime = tileEntity.getField(3);

    values.put(Keys.PASSED_BURN_TIME, passedBurnTime);
    values.put(Keys.MAX_BURN_TIME, maxBurnTime);
    values.put(Keys.PASSED_COOK_TIME, passedCookTime);
    values.put(Keys.MAX_COOK_TIME, maxCookTime);

    return values;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.ContextPullParser.java

@Override
public Object getViewCookie() {
    String name = super.getName();
    if (name == null) {
        return null;
    }/*from  w w  w.j  a v  a 2s  .c om*/

    // Store tools attributes if this looks like a layout we'll need adapter view
    // bindings for in the ProjectCallback.
    if (LIST_VIEW.equals(name) || EXPANDABLE_LIST_VIEW.equals(name) || GRID_VIEW.equals(name)
            || SPINNER.equals(name)) {
        Map<String, String> map = null;
        int count = getAttributeCount();
        for (int i = 0; i < count; i++) {
            String namespace = getAttributeNamespace(i);
            if (namespace != null && namespace.equals(TOOLS_URI)) {
                String attribute = getAttributeName(i);
                if (attribute.equals(ATTR_IGNORE)) {
                    continue;
                }
                if (map == null) {
                    map = Maps.newHashMapWithExpectedSize(4);
                }
                map.put(attribute, getAttributeValue(i));
            }
        }

        return map;
    }

    return null;
}

From source file:org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleTable.java

private Map<String, Object> prepareQueryConfigFilters() {
    final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(2);
    artifactUploadState.getSoftwareModuleFilters().getSearchText()
            .ifPresent(value -> queryConfig.put(SPUIDefinitions.FILTER_BY_TEXT, value));
    artifactUploadState.getSoftwareModuleFilters().getSoftwareModuleType()
            .ifPresent(type -> queryConfig.put(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE, type));
    return queryConfig;
}

From source file:org.eclipse.xtext.resource.impl.EObjectDescriptionLookUp.java

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

From source file:org.spongepowered.common.data.processor.multi.entity.EntityCommandDataProcessor.java

@Override
protected Map<Key<?>, ?> getValues(EntityMinecartCommandBlock entity) {
    CommandBlockLogic logic = entity.getCommandBlockLogic();
    Map<Key<?>, Object> values = Maps.newHashMapWithExpectedSize(4);
    Optional<Text> lastCommandOutput = logic.getLastOutput() != null
            ? Optional.of(SpongeTexts.toText(logic.getLastOutput()))
            : Optional.empty();/*from w  w  w  .  j a v  a2  s .c o m*/
    values.put(Keys.LAST_COMMAND_OUTPUT, lastCommandOutput);
    values.put(Keys.COMMAND, logic.commandStored);
    values.put(Keys.SUCCESS_COUNT, logic.successCount);
    values.put(Keys.TRACKS_OUTPUT, logic.shouldTrackOutput());
    return values;
}

From source file:org.dishevelled.venn.model.VennModelImpl.java

/**
 * Create and return the map of exclusive set views keyed by bit set.
 *
 * @return the map of exclusive set views keyed by bit set
 *//*from  w ww  .  j  a  va2s .  c o  m*/
private Map<ImmutableBitSet, Set<E>> createExclusives() {
    Map<ImmutableBitSet, Set<E>> map = Maps.newHashMapWithExpectedSize((int) Math.pow(2, this.sets.size()) - 1);

    // construct a set containing 0...n integers
    Set<Integer> input = Sets.newHashSet();
    for (int i = 0, size = size(); i < size; i++) {
        input.add(Integer.valueOf(i));
    }

    // calculate the power set (note n > 30 will overflow int)
    Set<Set<Integer>> powerSet = Sets.powerSet(ImmutableSet.copyOf(input));
    for (Set<Integer> set : powerSet) {
        if (!set.isEmpty()) {
            // intersect all in set
            Iterator<Integer> indices = set.iterator();
            Set<E> view = sets.get(indices.next());
            while (indices.hasNext()) {
                view = Sets.intersection(view, sets.get(indices.next()));
            }

            // subtract all in input not in set
            for (Integer index : input) {
                if (!set.contains(index)) {
                    view = Sets.difference(view, sets.get(index));
                }
            }

            // add to exclusives map
            map.put(toImmutableBitSet(set), view);
        }
    }

    // make an immutable copy?
    return map;
}

From source file:com.opengamma.engine.target.resolver.SecuritySourceResolver.java

@Override
public Map<ObjectId, UniqueId> resolveObjectIds(final Collection<ObjectId> identifiers,
        final VersionCorrection versionCorrection) {
    final Map<ObjectId, Security> securities = getUnderlying().get(identifiers, versionCorrection);
    final Map<ObjectId, UniqueId> result = Maps.newHashMapWithExpectedSize(securities.size());
    for (Map.Entry<ObjectId, Security> security : securities.entrySet()) {
        result.put(security.getKey(), security.getValue().getUniqueId());
    }//from w  ww  .  j  a va 2 s.c o m
    return result;
}