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.arpnetworking.metrics.mad.sources.MappingSource.java

private MappingSource(final Builder builder) {
    super(builder);
    _source = builder._source;/*ww  w  .  j  a  va 2  s.com*/

    _findAndReplace = Maps.newHashMapWithExpectedSize(builder._findAndReplace.size());
    for (final Map.Entry<String, ? extends List<String>> entry : builder._findAndReplace.entrySet()) {
        _findAndReplace.put(Pattern.compile(entry.getKey()), ImmutableList.copyOf(entry.getValue()));
    }

    _source.attach(new MappingObserver(this, _findAndReplace));
}

From source file:com.viadeo.kasper.core.id.AbstractByTypeConverter.java

@Override
public Map<ID, ID> convert(final Collection<ID> ids) {

    final ListMultimap<String, ID> idsByType = Multimaps.index(ids, new Function<ID, String>() {
        @Override//from  w  w  w . j  a v  a 2  s .c om
        public java.lang.String apply(ID input) {
            return checkNotNull(input).getType();
        }
    });

    final Map<ID, ID> convertResults = Maps.newHashMapWithExpectedSize(ids.size());

    for (final String type : idsByType.keySet()) {
        convertResults.putAll(doConvert(type, idsByType.get(type)));
    }

    return convertResults;
}

From source file:eu.interedition.text.xml.XMLEntity.java

public static Map<Name, String> dataToAttributes(JsonNode data) {
    final Map<Name, String> attributes = Maps.newHashMapWithExpectedSize(data.size());
    for (Iterator<String> attrNameIt = data.getFieldNames(); attrNameIt.hasNext();) {
        try {//from   www  . j ava 2 s  .c  o  m
            final String attrName = attrNameIt.next();
            final JsonNode value = data.get(attrName);
            attributes.put(Name.fromString(attrName),
                    value.isTextual() ? value.getTextValue() : value.toString());
        } catch (IllegalArgumentException e) {
        }
    }
    return attributes;
}

From source file:org.eclipse.hawkbit.ui.management.actionhistory.ActionStatusGrid.java

protected void configureQueryFactory() {
    // ADD all the filters to the query config
    final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(1);
    queryConfig.put(SPUIDefinitions.ACTIONSTATES_BY_ACTION, getDetailsSupport().getMasterDataId());
    // Create ActionBeanQuery factory with the query config.
    targetQF.setQueryConfiguration(queryConfig);
}

From source file:com.voxelplugineering.voxelsniper.brush.effect.morphological.BlendMaterialOperation.java

@Override
public void reset() {
    Map<Material, Integer> mats = Maps.newHashMapWithExpectedSize(10);
}

From source file:org.opennms.netmgt.measurements.impl.JrobinFetchStrategy.java

/**
 * {@inheritDoc}// w  w  w.j  av a2s  .  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.getEffectiveDataSource(),
                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.attribyte.api.http.impl.servlet.Bridge.java

@SuppressWarnings("unchecked")
/**/*w w  w. j ava2s .  c o m*/
 * Creates a request from a servlet HTTP request.
 * <p>
 *   Sets an attribute, <code>remoteAddr</code> with the address reported
 *   by the servlet API.
 * </p>
 * @param request The servlet request.
 * @param maxBodyBytes The maximum number of bytes read. If < 1, the body is not read.
 */
public static final Request fromServletRequest(final HttpServletRequest request, final int maxBodyBytes)
        throws IOException {

    Map<String, Header> headers = Maps.newHashMapWithExpectedSize(8);
    List<String> valueList = Lists.newArrayListWithExpectedSize(2);
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = (String) headerNames.nextElement();
        Enumeration headerValues = request.getHeaders(name);
        valueList.clear();
        while (headerValues.hasMoreElements()) {
            valueList.add((String) headerValues.nextElement());
        }

        if (valueList.size() == 1) {
            headers.put(name, new Header(name, valueList.get(0)));
        } else {
            headers.put(name, new Header(name, valueList.toArray(new String[valueList.size()])));
        }
    }

    final String queryString = request.getQueryString();

    final String requestURL = Strings.isNullOrEmpty(queryString) ? request.getRequestURL().toString()
            : request.getRequestURL().append('?').append(queryString).toString();

    final Map parameterMap = request.getParameterMap();

    Method method = Method.fromString(request.getMethod());
    switch (method) {
    case GET: {
        GetRequestBuilder grb = new GetRequestBuilder(requestURL, parameterMap);
        grb.addHeaders(headers);
        grb.addAttribute("remoteAddr", request.getRemoteAddr());
        return grb.create();
    }
    case HEAD: {
        HeadRequestBuilder hrb = new HeadRequestBuilder(requestURL, parameterMap);
        hrb.addHeaders(headers);
        hrb.addAttribute("remoteAddr", request.getRemoteAddr());
        return hrb.create();
    }
    case DELETE: {
        DeleteRequestBuilder drb = new DeleteRequestBuilder(requestURL, request.getParameterMap());
        drb.addHeaders(headers);
        drb.addAttribute("remoteAddr", request.getRemoteAddr());
        return drb.create();
    }
    }

    if (parameterMap != null && parameterMap.size() > 0) {
        FormPostRequestBuilder prb = new FormPostRequestBuilder(requestURL);
        prb.addHeaders(headers);
        prb.addParameters(request.getParameterMap());
        prb.addAttribute("remoteAddr", request.getRemoteAddr());
        return prb.create();
    } else {
        byte[] body = null;
        if (maxBodyBytes > 0) {
            InputStream is = request.getInputStream();
            try {
                body = Request.bodyFromInputStream(is, maxBodyBytes);
            } finally {
                is.close();
            }
        } else {
            ByteStreams.toByteArray(request.getInputStream()); //Read, but ignore the body...
        }

        if (method == Method.POST) {
            PostRequestBuilder prb = new PostRequestBuilder(requestURL, body);
            prb.addHeaders(headers);
            prb.addAttribute("remoteAddr", request.getRemoteAddr());
            return prb.create();
        } else {
            PutRequestBuilder prb = new PutRequestBuilder(requestURL, body);
            prb.addHeaders(headers);
            prb.addAttribute("remoteAddr", request.getRemoteAddr());
            return prb.create();
        }
    }
}

From source file:gg.uhc.uhc.modules.death.DeathStandsModule.java

@SuppressWarnings("Duplicates")
protected Map<EquipmentSlot, ItemStack> getItems(ArmorStand stand) {
    Map<EquipmentSlot, ItemStack> slots = Maps.newHashMapWithExpectedSize(5);

    slots.put(EquipmentSlot.HAND, stand.getItemInHand());
    slots.put(EquipmentSlot.HEAD, stand.getHelmet());
    slots.put(EquipmentSlot.CHEST, stand.getChestplate());
    slots.put(EquipmentSlot.LEGS, stand.getLeggings());
    slots.put(EquipmentSlot.FEET, stand.getBoots());

    return slots;
}

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

private Map<String, Object> toHeaderSoyData(Paginator paginator, @Nullable String revision) {
    Map<String, Object> data = Maps.newHashMapWithExpectedSize(5);
    data.put("logEntryPretty", pretty);
    ObjectId prev = paginator.getPreviousStart();
    if (prev != null) {
        GitilesView.Builder prevView = copyAndCanonicalizeView(revision);
        if (!prevView.getRevision().getId().equals(prev)) {
            prevView.replaceParam(LogServlet.START_PARAM, prev.name());
        }//  w w w.  j a  v a  2  s.  c om
        data.put("previousUrl", prevView.toUrl());
    }
    return data;
}

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

private void precomputePackages(WalkableGraph walkableGraph) throws InterruptedException {
    Set<PackageIdentifier> packagesToRequest = getPackagesIdentifiers();
    packages = Maps.newHashMapWithExpectedSize(packagesToRequest.size());
    for (PackageIdentifier pkgIdentifier : packagesToRequest) {
        packages.put(pkgIdentifier, findPackageInGraph(pkgIdentifier, walkableGraph));
    }//from w  w  w  . ja v a2 s  . c  om
}