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.apache.druid.query.topn.TopNLexicographicResultBuilder.java
@Override public TopNResultBuilder addEntry(Comparable dimValueObj, Object dimValIndex, Object[] metricVals) { final String dimValue = Objects.toString(dimValueObj, null); final Map<String, Object> metricValues = Maps.newHashMapWithExpectedSize(metricVals.length + 1); if (shouldAdd(dimValue)) { metricValues.put(dimSpec.getOutputName(), dimValueObj); final int extra = metricVals.length % LOOP_UNROLL_COUNT; switch (extra) { case 7:/*from w ww . ja v a2 s .c o 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]); } pQueue.add(new DimValHolder.Builder().withDimValue(dimValue).withMetricValues(metricValues).build()); if (pQueue.size() > threshold) { pQueue.poll(); } } return this; }
From source file:org.sonar.db.metric.MetricDao.java
public List<MetricDto> selectEnabled(DbSession session, @Nullable Boolean isCustom, int offset, int limit) { Map<String, Object> properties = Maps.newHashMapWithExpectedSize(1); if (isCustom != null) { properties.put("isCustom", isCustom); }//from w w w. ja v a2 s. c o m return mapper(session).selectAllEnabled(properties, new RowBounds(offset, limit)); }
From source file:org.matsim.contrib.taxi.optimizer.rules.IdleTaxiZonalRegistry.java
public IdleTaxiZonalRegistry(ZonalSystem zonalSystem, ScheduleInquiry scheduleInquiry) { this.scheduleInquiry = scheduleInquiry; this.zonalSystem = zonalSystem; zonesSortedByDistance = ZonalSystems.initZonesByDistance(zonalSystem.getZones()); vehiclesInZones = Maps.newHashMapWithExpectedSize(zonalSystem.getZones().size()); for (Id<Zone> id : zonalSystem.getZones().keySet()) { vehiclesInZones.put(id, new HashMap<Id<Vehicle>, Vehicle>()); }/*from w ww.j a v a 2 s . c o m*/ }
From source file:org.apache.phoenix.util.ReadOnlyProps.java
private ReadOnlyProps(ReadOnlyProps defaultProps, Properties overrides) { Map<String, String> combinedProps = Maps .newHashMapWithExpectedSize(defaultProps.props.size() + overrides.size()); combinedProps.putAll(defaultProps.props); for (Entry<Object, Object> entry : overrides.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue().toString(); combinedProps.put(key, value);// ww w . ja v a 2 s . c om } this.props = ImmutableMap.copyOf(combinedProps); }
From source file:com.viadeo.kasper.core.id.AbstractSimpleConverter.java
@Override public Map<ID, ID> convert(final Collection<ID> ids) { final Map<ID, ID> transformedIdToIds = Maps.newHashMapWithExpectedSize(ids.size()); for (final ID id : ids) { transformedIdToIds.put(id, convert(id)); }/*from w w w . ja v a 2 s. c om*/ return transformedIdToIds; }
From source file:org.apache.kylin.cube.util.CubingUtils.java
public static Map<Long, HLLCounter> sampling(CubeDesc cubeDesc, IJoinedFlatTableDesc flatDescIn, Iterable<List<String>> streams) { final CubeJoinedFlatTableEnrich flatDesc = new CubeJoinedFlatTableEnrich(flatDescIn, cubeDesc); final int rowkeyLength = cubeDesc.getRowkey().getRowKeyColumns().length; final List<Long> allCuboidIds = new CuboidScheduler(cubeDesc).getAllCuboidIds(); final long baseCuboidId = Cuboid.getBaseCuboidId(cubeDesc); final Map<Long, Integer[]> allCuboidsBitSet = Maps.newHashMap(); Lists.transform(allCuboidIds, new Function<Long, Integer[]>() { @Nullable/* ww w. j av a2 s . c o m*/ @Override public Integer[] apply(@Nullable Long cuboidId) { Integer[] result = new Integer[Long.bitCount(cuboidId)]; long mask = Long.highestOneBit(baseCuboidId); int position = 0; for (int i = 0; i < rowkeyLength; i++) { if ((mask & cuboidId) > 0) { result[position] = i; position++; } mask = mask >> 1; } return result; } }); final Map<Long, HLLCounter> result = Maps.newHashMapWithExpectedSize(allCuboidIds.size()); for (Long cuboidId : allCuboidIds) { result.put(cuboidId, new HLLCounter(cubeDesc.getConfig().getCubeStatsHLLPrecision())); Integer[] cuboidBitSet = new Integer[Long.bitCount(cuboidId)]; long mask = Long.highestOneBit(baseCuboidId); int position = 0; for (int i = 0; i < rowkeyLength; i++) { if ((mask & cuboidId) > 0) { cuboidBitSet[position] = i; position++; } mask = mask >> 1; } allCuboidsBitSet.put(cuboidId, cuboidBitSet); } HashFunction hf = Hashing.murmur3_32(); ByteArray[] row_hashcodes = new ByteArray[rowkeyLength]; for (int i = 0; i < rowkeyLength; i++) { row_hashcodes[i] = new ByteArray(); } for (List<String> row : streams) { //generate hash for each row key column for (int i = 0; i < rowkeyLength; i++) { Hasher hc = hf.newHasher(); final String cell = row.get(flatDesc.getRowKeyColumnIndexes()[i]); if (cell != null) { row_hashcodes[i].set(hc.putString(cell).hash().asBytes()); } else { row_hashcodes[i].set(hc.putInt(0).hash().asBytes()); } } for (Map.Entry<Long, HLLCounter> longHyperLogLogPlusCounterNewEntry : result.entrySet()) { Long cuboidId = longHyperLogLogPlusCounterNewEntry.getKey(); HLLCounter counter = longHyperLogLogPlusCounterNewEntry.getValue(); Hasher hc = hf.newHasher(); final Integer[] cuboidBitSet = allCuboidsBitSet.get(cuboidId); for (int position = 0; position < cuboidBitSet.length; position++) { hc.putBytes(row_hashcodes[cuboidBitSet[position]].array()); } counter.add(hc.hash().asBytes()); } } return result; }
From source file:com.opengamma.analytics.financial.forex.calculator.PV01ForexCalculator.java
private Map<String, Double> visit(final Map<String, List<DoublesPair>> curveSensitivities) { ArgumentChecker.notNull(curveSensitivities, "curve sensitivities"); final Map<String, Double> result = Maps.newHashMapWithExpectedSize(curveSensitivities.size()); for (final Map.Entry<String, List<DoublesPair>> entry : curveSensitivities.entrySet()) { final String name = entry.getKey(); final double sum = sumListPair(entry.getValue()) * ONE_BASIS_POINT; result.put(name, sum);//w ww . java 2 s .c o m } return result; }
From source file:com.arpnetworking.tsdaggregator.sources.MappingSource.java
private MappingSource(final Builder builder) { super(builder); _source = builder._source;/*w ww. j av a 2 s . c o m*/ _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.<String>copyOf(entry.getValue())); } _source.attach(new MappingObserver(this, _findAndReplace)); }
From source file:com.kingen.web.SkillController.java
/** * ?grid//from ww w. j ava 2 s . co m */ //?jsonstring ?jsonObject @RequestMapping(value = "/treeData") public @ResponseBody Object data(Page<SkillCat> page, HttpServletResponse response) { List<SkillCat> all = service.list(); List<TreeNode> allConverted = BeanMapper.mapList(all, TreeNode.class); Map<String, Object> json = Maps.newHashMapWithExpectedSize(1); //?chidlren,return toComplexJsonString(offices);?.jsonString??????? json.put("children", TreeConverter.toComplexTree(allConverted)); return json; }
From source file:org.novelang.build.unicode.UnicodeNamesTextReader.java
Map<Character, String> extractNames(final String names) throws IOException { final Map<Character, String> characterToNameMap = Maps.newHashMapWithExpectedSize(256 * 256); final Matcher matcher = PROPERTY_LINE_PATTERN.matcher(names); int limiter = 0; while (matcher.find() /*&& limiter < 150*/ ) { final String code = matcher.group(1); if (code.length() == 4) { final String name; final String casualName = matcher.group(2); if ("<control>".equals(casualName)) { final String controlName = matcher.group(3); name = controlName;/* ww w. j av a2 s .co m*/ } else { name = casualName; } final int codeAsInt = Integer.parseInt(code, 16); // Be confident! final Character character = (char) codeAsInt; final String existing = characterToNameMap.get(character); if (existing == null && !"".equals(name)) { // Retain first definition, seems that most interesting appear first. characterToNameMap.put(character, name); // LOG.info( "Added " + ( ( int ) character ) + " as '" + name + "'" + // ( character != limiter ? " OOOPS!" : "" ) // ) ; } } limiter++; } return ImmutableMap.copyOf(characterToNameMap); }