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.sosy_lab.cpachecker.cpa.statistics.StatisticsData.java

public StatisticsData getNextState(CFAEdge node) {
    Map<StatisticsProvider, StatisticsDataProvider> dataProvider = Maps.newHashMapWithExpectedSize(data.size());
    for (Entry<StatisticsProvider, StatisticsDataProvider> providerEntry : data.entrySet()) {
        StatisticsProvider key = providerEntry.getKey();
        StatisticsDataProvider value = providerEntry.getValue();
        value = value.calculateNext(node);
        dataProvider.put(key, value);/*from  w  w  w .  j  a  va  2  s .c o m*/
    }
    return new StatisticsData(dataProvider);
}

From source file:com.android.tools.idea.uibuilder.handlers.relative.DeletionHandler.java

/**
 * Creates a new {@link DeletionHandler}
 *
 * @param deleted the deleted nodes/*from www .  ja  va2 s  .  c o  m*/
 * @param moved   nodes that were moved (e.g. deleted, but also inserted elsewhere)
 * @param layout  the parent layout of the deleted nodes
 */
public DeletionHandler(@NotNull List<NlComponent> deleted, @NotNull List<NlComponent> moved,
        @NotNull NlComponent layout) {
    myDeleted = deleted;
    myChildren = Lists.newArrayList(layout.getChildren());
    myNodeMap = Maps.newHashMapWithExpectedSize(myChildren.size());
    for (NlComponent view : myChildren) {
        String id = view.getId();
        if (id != null) {
            myNodeMap.put(LintUtils.stripIdPrefix(id), view);
        }
    }

    myDeletedIds = Sets.newHashSetWithExpectedSize(myDeleted.size());
    for (NlComponent node : myDeleted) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.add(LintUtils.stripIdPrefix(id));
        }
    }

    // Any widgets that remain (e.g. typically because they were moved) should
    // keep their incoming dependencies
    for (NlComponent node : moved) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.remove(LintUtils.stripIdPrefix(id));
        }
    }
}

From source file:org.openqa.selenium.remote.internal.WebElementToJsonConverter.java

public Object apply(Object arg) {
    if (arg == null || arg instanceof String || arg instanceof Boolean || arg instanceof Number) {
        return arg;
    }//from   w  w  w.j a va 2 s  . c  om

    while (arg instanceof WrapsElement) {
        arg = ((WrapsElement) arg).getWrappedElement();
    }

    if (arg instanceof RemoteWebElement) {
        return ImmutableMap.of("ELEMENT", ((RemoteWebElement) arg).getId(),
                "element-6066-11e4-a52e-4f735466cecf", ((RemoteWebElement) arg).getId());
    }

    if (arg.getClass().isArray()) {
        arg = Lists.newArrayList((Object[]) arg);
    }

    if (arg instanceof Collection<?>) {
        Collection<?> args = (Collection<?>) arg;
        return Collections2.transform(args, this);
    }

    if (arg instanceof Map<?, ?>) {
        Map<?, ?> args = (Map<?, ?>) arg;
        Map<String, Object> converted = Maps.newHashMapWithExpectedSize(args.size());
        for (Map.Entry<?, ?> entry : args.entrySet()) {
            Object key = entry.getKey();
            if (!(key instanceof String)) {
                throw new IllegalArgumentException(
                        "All keys in Map script arguments must be strings: " + key.getClass().getName());
            }
            converted.put((String) key, apply(entry.getValue()));
        }
        return converted;
    }

    throw new IllegalArgumentException("Argument is of an illegal type: " + arg.getClass().getName());
}

From source file:org.apache.jackrabbit.oak.security.user.MembershipWriter.java

/**
 * Adds a new member to the given {@code groupTree}.
 *
 * @param groupTree the group to add the member to
 * @param memberContentId the id of the new member
 * @return {@code true} if the member was added
 * @throws RepositoryException if an error occurs
 *//*from   ww w .jav  a2 s. co  m*/
boolean addMember(Tree groupTree, String memberContentId) throws RepositoryException {
    Map<String, String> m = Maps.newHashMapWithExpectedSize(1);
    m.put(memberContentId, "-");
    return addMembers(groupTree, m).isEmpty();
}

From source file:org.apache.kylin.engine.mr.common.CuboidStatsReaderUtil.java

private static void readCuboidStatsFromSegments(Set<Long> cuboidSet, List<CubeSegment> segmentList,
        final Map<Long, Long> statisticsMerged, final Map<Long, Double> sizeMerged) throws IOException {
    if (segmentList == null || segmentList.isEmpty()) {
        return;//from   ww  w.  j  a v a 2  s .com
    }
    int nSegment = segmentList.size();

    Map<Long, HLLCounter> cuboidHLLMapMerged = Maps.newHashMapWithExpectedSize(cuboidSet.size());
    Map<Long, Double> sizeMapMerged = Maps.newHashMapWithExpectedSize(cuboidSet.size());
    for (CubeSegment pSegment : segmentList) {
        CubeStatsReader pReader = new CubeStatsReader(pSegment, null, pSegment.getConfig());
        Map<Long, HLLCounter> pHLLMap = pReader.getCuboidRowHLLCounters();
        if (pHLLMap == null || pHLLMap.isEmpty()) {
            logger.info("Cuboid Statistics for segment " + pSegment.getName() + " is not enabled.");
            nSegment--;
            continue;
        }
        Map<Long, Double> pSizeMap = pReader.getCuboidSizeMap();
        for (Long pCuboid : cuboidSet) {
            HLLCounter pInnerHLL = pHLLMap.get(pCuboid);
            Preconditions.checkNotNull(pInnerHLL, "statistics should exist for cuboid " + pCuboid
                    + " of segment " + pSegment.getCubeDesc().getName() + "[" + pSegment.getName() + "]");
            if (cuboidHLLMapMerged.get(pCuboid) != null) {
                cuboidHLLMapMerged.get(pCuboid).merge(pInnerHLL);
            } else {
                cuboidHLLMapMerged.put(pCuboid, pInnerHLL);
            }

            Double pSize = sizeMapMerged.get(pCuboid);
            sizeMapMerged.put(pCuboid, pSize == null ? pSizeMap.get(pCuboid) : pSizeMap.get(pCuboid) + pSize);
        }
    }

    if (nSegment < 1) {
        return;
    }
    for (Long pCuboid : cuboidSet) {
        statisticsMerged.put(pCuboid, cuboidHLLMapMerged.get(pCuboid).getCountEstimate());
        sizeMerged.put(pCuboid, sizeMapMerged.get(pCuboid));
    }
}

From source file:com.google.gerrit.server.notedb.RevisionNoteBuilder.java

RevisionNoteBuilder(RevisionNote<? extends Comment> base) {
    if (base != null) {
        baseRaw = base.getRaw();/*from  w  w w.  j a  va  2  s .  c  o m*/
        baseComments = base.getComments();
        put = Maps.newHashMapWithExpectedSize(baseComments.size());
        if (base instanceof ChangeRevisionNote) {
            pushCert = ((ChangeRevisionNote) base).getPushCert();
        }
    } else {
        baseRaw = new byte[0];
        baseComments = Collections.emptyList();
        put = new HashMap<>();
        pushCert = null;
    }
    delete = new HashSet<>();
}

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

/**
 * Creates an application./*from  w  ww .j  a  v  a 2s  . co  m*/
 * @param name The name.
 * @param index The associated index, if any.
 * @param hosts The collection of hosts.
 * @param metrics The collection of metrics.
 */
public Application(final String name, final String index, final Collection<Host> hosts,
        final Collection<Metric> metrics) {
    this.name = name;
    this.index = index;
    this.hosts = hosts != null ? ImmutableSet.copyOf(hosts) : ImmutableSet.<Host>of();
    this.metrics = metrics != null ? ImmutableSet.copyOf(metrics) : ImmutableSet.<Metric>of();
    this.metricTypeMap = buildTypeMap(metrics);

    ImmutableMap.Builder<String, Metric> mapBuilder = ImmutableMap.builder();
    Map<String, List<Metric>> prefixMapBuilder = Maps.newHashMapWithExpectedSize(1024);

    for (Metric metric : this.metrics) {
        mapBuilder.put(metric.name, metric);
        addPrefix(prefixMapBuilder, metric);
    }

    for (List<Metric> sorted : prefixMapBuilder.values()) {
        Collections.sort(sorted, Metric.alphaComparator);
    }

    this.metricNameMap = mapBuilder.build();
    this.metricNamePrefixMap = ImmutableMap.copyOf(prefixMapBuilder);
}

From source file:com.intellij.android.designer.model.layout.relative.DeletionHandler.java

/**
 * Creates a new {@link DeletionHandler}
 *
 * @param deleted the deleted nodes/*from  www  .j  a  v  a2 s. com*/
 * @param moved   nodes that were moved (e.g. deleted, but also inserted elsewhere)
 * @param layout  the parent layout of the deleted nodes
 */
public DeletionHandler(@NotNull List<RadViewComponent> deleted, @NotNull List<RadViewComponent> moved,
        @NotNull RadViewComponent layout) {
    myDeleted = deleted;
    myChildren = layout.getChildren();
    myNodeMap = Maps.newHashMapWithExpectedSize(myChildren.size());
    for (RadViewComponent view : RadViewComponent.getViewComponents(myChildren)) {
        String id = view.getId();
        if (id != null) {
            myNodeMap.put(LintUtils.stripIdPrefix(id), view);
        }
    }

    myDeletedIds = Sets.newHashSetWithExpectedSize(myDeleted.size());
    for (RadViewComponent node : myDeleted) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.add(LintUtils.stripIdPrefix(id));
        }
    }

    // Any widgets that remain (e.g. typically because they were moved) should
    // keep their incoming dependencies
    for (RadViewComponent node : moved) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.remove(LintUtils.stripIdPrefix(id));
        }
    }
}

From source file:org.eclipse.xtext.builder.clustering.CopiedResourceDescription.java

public CopiedResourceDescription(IResourceDescription original) {
    this.uri = original.getURI();
    this.exported = ImmutableList.copyOf(Iterables.transform(original.getExportedObjects(),
            new Function<IEObjectDescription, IEObjectDescription>() {
                @Override/*from w  w  w.  ja v  a  2 s  .  c  o  m*/
                public IEObjectDescription apply(IEObjectDescription from) {
                    if (from.getEObjectOrProxy().eIsProxy()) {
                        return from;
                    }
                    InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass());
                    result.eSetProxyURI(from.getEObjectURI());
                    Map<String, String> userData = null;
                    for (final String key : from.getUserDataKeys()) {
                        if (userData == null) {
                            userData = Maps.newHashMapWithExpectedSize(2);
                        }
                        userData.put(key, from.getUserData(key));
                    }
                    return EObjectDescription.create(from.getName(), result, userData);
                }
            }));
}

From source file:org.graylog2.rest.resources.system.MessagesResource.java

@GET
@Timed//from   ww w.  ja va  2s . c  o m
@ApiOperation(value = "Get internal Graylog system messages")
@RequiresPermissions(RestPermissions.SYSTEMMESSAGES_READ)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> all(
        @ApiParam(name = "page", value = "Page", required = false) @QueryParam("page") int page) {
    final List<Map<String, Object>> messages = Lists.newArrayList();
    for (SystemMessage sm : systemMessageService.all(page(page))) {
        Map<String, Object> message = Maps.newHashMapWithExpectedSize(4);
        message.put("caller", sm.getCaller());
        message.put("content", sm.getContent());
        message.put("timestamp", Tools.getISO8601String(sm.getTimestamp()));
        message.put("node_id", sm.getNodeId());

        messages.add(message);
    }

    return ImmutableMap.of("messages", messages, "total", systemMessageService.totalCount());
}