List of usage examples for com.google.common.collect Maps newHashMapWithExpectedSize
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize)
From source file:org.sonar.server.user.index.UserResultSetIterator.java
@Override protected UserDoc read(ResultSet rs) throws SQLException { UserDoc doc = new UserDoc(Maps.newHashMapWithExpectedSize(8)); String login = rs.getString(1); // all the keys must be present, even if value is null doc.setLogin(login);/* w w w. j a v a2s.com*/ doc.setName(rs.getString(2)); doc.setEmail(rs.getString(3)); doc.setActive(rs.getBoolean(4)); doc.setScmAccounts(UserDto.decodeScmAccounts(rs.getString(5))); doc.setCreatedAt(rs.getLong(6)); doc.setUpdatedAt(rs.getLong(7)); doc.setOrganizationUuids(organizationUuidsByLogins.get(login)); return doc; }
From source file:io.druid.query.topn.TopNNumericResultBuilder.java
@Override public TopNNumericResultBuilder addEntry(String dimName, Object dimValIndex, Object[] metricVals) { Preconditions.checkArgument(metricVals.length == aggFactoryNames.length, "metricVals must be the same length as aggFactories"); final Map<String, Object> metricValues = Maps .newHashMapWithExpectedSize(metricVals.length + postAggs.size() + 1); metricValues.put(dimSpec.getOutputName(), dimName); final int extra = metricVals.length % LOOP_UNROLL_COUNT; switch (extra) { case 7://from w w w . j a va2s . c o m metricValues.put(aggFactoryNames[6], metricVals[6]); case 6: metricValues.put(aggFactoryNames[5], metricVals[5]); case 5: metricValues.put(aggFactoryNames[4], metricVals[4]); case 4: metricValues.put(aggFactoryNames[3], metricVals[3]); case 3: metricValues.put(aggFactoryNames[2], metricVals[2]); case 2: metricValues.put(aggFactoryNames[1], metricVals[1]); case 1: metricValues.put(aggFactoryNames[0], metricVals[0]); } for (int i = extra; i < metricVals.length; i += LOOP_UNROLL_COUNT) { metricValues.put(aggFactoryNames[i + 0], metricVals[i + 0]); metricValues.put(aggFactoryNames[i + 1], metricVals[i + 1]); metricValues.put(aggFactoryNames[i + 2], metricVals[i + 2]); metricValues.put(aggFactoryNames[i + 3], metricVals[i + 3]); metricValues.put(aggFactoryNames[i + 4], metricVals[i + 4]); metricValues.put(aggFactoryNames[i + 5], metricVals[i + 5]); metricValues.put(aggFactoryNames[i + 6], metricVals[i + 6]); metricValues.put(aggFactoryNames[i + 7], metricVals[i + 7]); } // Order matters here, do not unroll for (PostAggregator postAgg : postAggs) { metricValues.put(postAgg.getName(), postAgg.compute(metricValues)); } Object topNMetricVal = metricValues.get(metricName); if (shouldAdd(topNMetricVal)) { DimValHolder dimValHolder = new DimValHolder.Builder().withTopNMetricVal(topNMetricVal) .withDimName(dimName).withDimValIndex(dimValIndex).withMetricValues(metricValues).build(); pQueue.add(dimValHolder); } if (this.pQueue.size() > this.threshold) { pQueue.poll(); } return this; }
From source file:org.apache.beam.sdk.coders.MapCoder.java
@Override public Map<K, V> decode(InputStream inStream, Context context) throws IOException, CoderException { DataInputStream dataInStream = new DataInputStream(inStream); int size = dataInStream.readInt(); if (size == 0) { return Collections.emptyMap(); }//from w w w . j av a 2 s .c o m Map<K, V> retval = Maps.newHashMapWithExpectedSize(size); for (int i = 0; i < size - 1; ++i) { K key = keyCoder.decode(inStream); V value = valueCoder.decode(inStream); retval.put(key, value); } K key = keyCoder.decode(inStream); V value = valueCoder.decode(inStream, context); retval.put(key, value); return retval; }
From source file:com.twitter.common.net.loadbalancing.LeastConnectedStrategy.java
@Override protected Collection<S> onBackendsOffered(Set<S> backends) { Map<S, ConnectionStats> newConnections = Maps.newHashMapWithExpectedSize(backends.size()); Collection<ConnectionStats> newConnectionStats = Lists.newArrayListWithCapacity(backends.size()); // Recreate all connection stats since their ordering may have changed and this is used for // comparison tie breaks. int backendId = 0; for (S backend : backends) { ConnectionStats stats = new ConnectionStats(backend, backendId++); // Retain the activeCount for existing backends to prevent dogpiling existing active servers ConnectionStats existing = connections.get(backend); if (existing != null) { stats.activeCount = existing.activeCount; }/*from w w w . jav a 2 s.c om*/ newConnections.put(backend, stats); newConnectionStats.add(stats); } connections.clear(); connections.putAll(newConnections); connectionStats.clear(); connectionStats.addAll(newConnectionStats); return connections.keySet(); }
From source file:org.gradle.plugins.ide.idea.model.ModuleLibrary.java
@Override public void addToNode(Node parentNode) { Map<String, Object> orderEntryAttributes = Maps.newHashMap(ImmutableMap.<String, Object>builder() .put("type", "module-library").putAll(getAttributeMapForScopeAndExported()).build()); Node libraryNode = parentNode.appendNode("orderEntry", orderEntryAttributes).appendNode("library"); Node classesNode = libraryNode.appendNode("CLASSES"); Node javadocNode = libraryNode.appendNode("JAVADOC"); Node sourcesNode = libraryNode.appendNode("SOURCES"); for (Path path : classes) { Map<String, Object> attributes = Maps.newHashMapWithExpectedSize(1); attributes.put("url", path.getUrl()); classesNode.appendNode("root", attributes); }//from w w w . j a v a 2 s . c om for (Path path : javadoc) { Map<String, Object> attributes = Maps.newHashMapWithExpectedSize(1); attributes.put("url", path.getUrl()); javadocNode.appendNode("root", attributes); } for (Path path : sources) { Map<String, Object> attributes = Maps.newHashMapWithExpectedSize(1); attributes.put("url", path.getUrl()); sourcesNode.appendNode("root", attributes); } for (JarDirectory jarDirectory : jarDirectories) { Map<String, Object> attributes = Maps.newHashMapWithExpectedSize(2); attributes.put("url", jarDirectory.getPath().getUrl()); attributes.put("recursive", String.valueOf(jarDirectory.isRecursive())); libraryNode.appendNode("jarDirectory", attributes); } }
From source file:com.cinchapi.concourse.server.storage.db.BlockIndex.java
/** * Construct a new instance.//from w ww . ja v a 2s . c om * * @param expectedInsertions */ private BlockIndex(String file, int expectedInsertions) { this.file = file; this.entries = Maps.newHashMapWithExpectedSize(expectedInsertions); this.softEntries = null; this.mutable = true; }
From source file:org.gradoop.flink.model.impl.operators.matching.common.functions.ElementsFromEmbedding.java
/** * Constructor/*from ww w.j ava 2s. co m*/ * * @param traversalCode traversal code to retrieve sourceId/targetId * @param epgmGraphHeadFactory EPGM graph head factory * @param epgmVertexFactory EPGM vertex factory * @param epgmEdgeFactory EPGM edge factory * @param query query handler */ public ElementsFromEmbedding(TraversalCode traversalCode, EPGMGraphHeadFactory<GraphHead> epgmGraphHeadFactory, EPGMVertexFactory<Vertex> epgmVertexFactory, EPGMEdgeFactory<Edge> epgmEdgeFactory, QueryHandler query) { this.graphHeadFactory = epgmGraphHeadFactory; this.vertexFactory = epgmVertexFactory; this.edgeFactory = epgmEdgeFactory; this.queryVertexMapping = query.getVertices().stream() .collect(Collectors.toMap(v -> v.getId(), v -> v.getVariable())); this.queryEdgeMapping = query.getEdges().stream() .collect(Collectors.toMap(e -> e.getId(), e -> e.getVariable())); List<Step> steps = traversalCode.getSteps(); edgeToStep = Maps.newHashMapWithExpectedSize(steps.size()); for (Step step : steps) { edgeToStep.put((int) step.getVia(), step); } }
From source file:org.onos.yangtools.util.MapAdaptor.java
/** * Creates an initial snapshot. The backing map is selected according to * the expected size./*www .j a v a 2 s.c om*/ * * @param expectedSize Expected map size * @return An empty mutable map. */ public <K, V> Map<K, V> initialSnapshot(final int expectedSize) { Preconditions.checkArgument(expectedSize >= 0); if (expectedSize > persistMinItems) { return new ReadWriteTrieMap<>(); } return Maps.newHashMapWithExpectedSize(expectedSize); }
From source file:edu.cmu.cs.lti.ark.util.ds.map.IntCounter.java
public Map<T, Integer> asMap() { final Map<T, Integer> copy = Maps.newHashMapWithExpectedSize(size()); final TObjectIntIterator<T> iter = getIterator(); while (iter.hasNext()) { iter.advance();//from w ww. j a va2 s . co m copy.put(iter.key(), iter.value()); } return copy; }
From source file:org.apache.druid.query.topn.TopNNumericResultBuilder.java
@Override public TopNNumericResultBuilder addEntry(Comparable dimValueObj, Object dimValIndex, Object[] metricVals) { Preconditions.checkArgument(metricVals.length == aggFactoryNames.length, "metricVals must be the same length as aggFactories"); final Map<String, Object> metricValues = Maps .newHashMapWithExpectedSize(metricVals.length + postAggs.size() + 1); metricValues.put(dimSpec.getOutputName(), dimValueObj); final int extra = metricVals.length % LOOP_UNROLL_COUNT; switch (extra) { case 7://from ww w .jav a 2s. co m metricValues.put(aggFactoryNames[6], metricVals[6]); // fall through case 6: metricValues.put(aggFactoryNames[5], metricVals[5]); // fall through case 5: metricValues.put(aggFactoryNames[4], metricVals[4]); // fall through case 4: metricValues.put(aggFactoryNames[3], metricVals[3]); // fall through case 3: metricValues.put(aggFactoryNames[2], metricVals[2]); // fall through case 2: metricValues.put(aggFactoryNames[1], metricVals[1]); // fall through case 1: metricValues.put(aggFactoryNames[0], metricVals[0]); } for (int i = extra; i < metricVals.length; i += LOOP_UNROLL_COUNT) { metricValues.put(aggFactoryNames[i + 0], metricVals[i + 0]); metricValues.put(aggFactoryNames[i + 1], metricVals[i + 1]); metricValues.put(aggFactoryNames[i + 2], metricVals[i + 2]); metricValues.put(aggFactoryNames[i + 3], metricVals[i + 3]); metricValues.put(aggFactoryNames[i + 4], metricVals[i + 4]); metricValues.put(aggFactoryNames[i + 5], metricVals[i + 5]); metricValues.put(aggFactoryNames[i + 6], metricVals[i + 6]); metricValues.put(aggFactoryNames[i + 7], metricVals[i + 7]); } // Order matters here, do not unroll for (PostAggregator postAgg : postAggs) { metricValues.put(postAgg.getName(), postAgg.compute(metricValues)); } Object topNMetricVal = metricValues.get(metricName); if (shouldAdd(topNMetricVal)) { DimValHolder dimValHolder = new DimValHolder.Builder().withTopNMetricVal(topNMetricVal) .withDimValue(dimValueObj).withDimValIndex(dimValIndex).withMetricValues(metricValues).build(); pQueue.add(dimValHolder); } if (this.pQueue.size() > this.threshold) { pQueue.poll(); } return this; }