List of usage examples for com.google.common.collect Maps newHashMapWithExpectedSize
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize)
From source file:com.threerings.tools.gxlate.spreadsheet.Index.java
/** * Creates a new index for the given table and columns. Index creation stops and an exception * is thrown after a fixed number of problems occur. * @throws IndexError if there were any problems creating the index. *//*from w ww .ja va 2s.c om*/ public Index(Table table, String... headers) throws IndexError { _rows = Maps.newHashMapWithExpectedSize(table.getRows().size()); _headers = headers; List<Error> errors = Lists.newArrayList(); for (Row row : table.getRows()) { if (row == null) { continue; } Key key = key(row, errors); Row old = _rows.put(key, row); if (old != null) { errors.add(new DuplicateKeyError(old, row)); } if (errors.size() > 10) { throw new IndexError(errors); } } if (!errors.isEmpty()) { throw new IndexError(errors); } }
From source file:org.eclipse.hawkbit.ui.management.actionhistory.ActionStatusMsgGrid.java
protected void configureQueryFactory() { // ADD all the filters to the query config final Map<String, Object> queryConfig = Maps.newHashMapWithExpectedSize(2); queryConfig.put(SPUIDefinitions.MESSAGES_BY_ACTIONSTATUS, getDetailsSupport().getMasterDataId()); queryConfig.put(SPUIDefinitions.NO_MSG_PROXY, noMsgText); // Create ActionBeanQuery factory with the query config. targetQF.setQueryConfiguration(queryConfig); }
From source file:com.netflix.atlas.client.interpreter.GroupBy.java
@Override public Map<List<String>, LabeledResult> apply(List<Metric> updates) { // group metrics by keys Map<List<String>, List<Metric>> grouped = Maps.newHashMap(); for (Metric metric : updates) { boolean shouldKeep = true; List<String> groupByValues = Lists.newArrayListWithCapacity(keys.size()); for (String key : keys) { String value = getValue(metric, key); if (value != null) { groupByValues.add(value); } else { // ignore this metric shouldKeep = false;/*from w w w . j a va 2 s.com*/ break; } } if (shouldKeep) { List<Metric> valuesForKeys = grouped.get(groupByValues); if (valuesForKeys == null) { valuesForKeys = Lists.newArrayList(); grouped.put(groupByValues, valuesForKeys); } valuesForKeys.add(metric); } } Map<List<String>, LabeledResult> results = Maps.newHashMapWithExpectedSize(grouped.size()); for (Map.Entry<List<String>, List<Metric>> entry : grouped.entrySet()) { List<String> k = entry.getKey(); List<Metric> v = entry.getValue(); String label = String.format("GroupBy([%s], %s)", JOINER.join(k), expression.getLabel()); results.put(k, new LabeledResult(label, expression.apply(v))); } return results; }
From source file:org.apache.flink.runtime.io.network.partition.consumer.UnionInputGate.java
public UnionInputGate(InputGate... inputGates) { this.inputGates = checkNotNull(inputGates); checkArgument(inputGates.length > 1, "Union input gate should union at least two input gates."); this.inputGateToIndexOffsetMap = Maps.newHashMapWithExpectedSize(inputGates.length); this.inputGatesWithRemainingData = Sets.newHashSetWithExpectedSize(inputGates.length); int currentNumberOfInputChannels = 0; for (InputGate inputGate : inputGates) { // The offset to use for buffer or event instances received from this input gate. inputGateToIndexOffsetMap.put(checkNotNull(inputGate), currentNumberOfInputChannels); inputGatesWithRemainingData.add(inputGate); currentNumberOfInputChannels += inputGate.getNumberOfInputChannels(); // Register the union gate as a listener for all input gates inputGate.registerListener(this); }// ww w. j a v a 2 s. co m this.totalNumberOfInputChannels = currentNumberOfInputChannels; }
From source file:com.voxelplugineering.voxelsniper.brush.effect.morphological.LinearBlendMaterialOperation.java
@Override public void reset() { Map<Material, Integer> mats = Maps.newHashMapWithExpectedSize(10); count = 0; maxDistance = 0; }
From source file:org.ambraproject.wombat.service.CommentValidationServiceImpl.java
@Override public Map<String, Object> validateFlag(String flagComment) { Map<String, Object> errors = Maps.newHashMapWithExpectedSize(1); if (Strings.isNullOrEmpty(flagComment)) { errors.put("missingComment", true); }/*from w w w .ja va 2s . co m*/ checkLength(errors, "commentLength", flagComment, COMMENT_BODY_MAX); return errors; }
From source file:com.opengamma.engine.target.resolver.SecuritySourceResolver.java
@Override public Map<ExternalIdBundle, UniqueId> resolveExternalIds(final Collection<ExternalIdBundle> identifiers, final VersionCorrection versionCorrection) { final Map<ExternalIdBundle, ? extends Security> securities = getUnderlying().getSingle(identifiers, versionCorrection);/*from w w w . j a v a 2 s.c om*/ final Map<ExternalIdBundle, UniqueId> result = Maps.newHashMapWithExpectedSize(securities.size()); for (Map.Entry<ExternalIdBundle, ? extends Security> security : securities.entrySet()) { result.put(security.getKey(), security.getValue().getUniqueId()); } return result; }
From source file:ru.org.linux.spring.dao.MsgbaseDao.java
public Map<Integer, MessageText> getMessageText(Collection<Integer> msgids) { if (msgids.isEmpty()) { return ImmutableMap.of(); }/*w w w . java 2s . c o m*/ final Map<Integer, MessageText> out = Maps.newHashMapWithExpectedSize(msgids.size()); namedJdbcTemplate.query("SELECT message, markup, id FROM msgbase WHERE id IN (:list)", ImmutableMap.of("list", msgids), new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { String text = resultSet.getString("message"); String markup = resultSet.getString("markup"); boolean lorcode = !"PLAIN".equals(markup); out.put(resultSet.getInt("id"), new MessageText(text, lorcode)); } }); return out; }
From source file:org.elasticsearch.transport.TransportInfo.java
@Override public void readFrom(StreamInput in) throws IOException { address = BoundTransportAddress.readBoundTransportAddress(in); int size = in.readVInt(); if (size > 0) { profileAddresses = Maps.newHashMapWithExpectedSize(size); for (int i = 0; i < size; i++) { String key = in.readString(); BoundTransportAddress value = BoundTransportAddress.readBoundTransportAddress(in); profileAddresses.put(key, value); }/*from www . j a va 2 s.c o m*/ } }
From source file:com.romeikat.datamessie.core.base.ui.component.SourceTypeChoiceProvider.java
private Map<Long, SourceTypeDto> getSourceTypes() { final HibernateSessionProvider sessionProvider = new HibernateSessionProvider(sessionFactory); final List<SourceTypeDto> sourceTypes = sourceTypeDao.getAsDtos(sessionProvider.getStatelessSession()); sessionProvider.closeStatelessSession(); final Map<Long, SourceTypeDto> sourceTypesMap = Maps.newHashMapWithExpectedSize(sourceTypes.size()); for (final SourceTypeDto sourceType : sourceTypes) { sourceTypesMap.put(sourceType.getId(), sourceType); }//from w ww .j a v a 2 s. c o m return sourceTypesMap; }