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.google.devtools.build.skyframe.DelegatingWalkableGraph.java
@Override public Map<SkyKey, SkyValue> getSuccessfulValues(Iterable<SkyKey> keys) throws InterruptedException { Map<SkyKey, ? extends NodeEntry> batchGet = graph.getBatch(null, Reason.WALKABLE_GRAPH_VALUE, keys); Map<SkyKey, SkyValue> result = Maps.newHashMapWithExpectedSize(batchGet.size()); for (Entry<SkyKey, ? extends NodeEntry> entryPair : batchGet.entrySet()) { SkyValue value = getValue(entryPair.getValue()); if (value != null) { result.put(entryPair.getKey(), value); }/*from w w w.j a v a 2 s . c o m*/ } return result; }
From source file:org.jage.platform.component.pico.injector.Parameters.java
public static <K> Map<K, Parameter> fromMapping(final Map<K, IArgumentDefinition> mapping) { Map<K, Parameter> parameters = Maps.newHashMapWithExpectedSize(mapping.size()); for (Entry<K, IArgumentDefinition> e : mapping.entrySet()) { parameters.put(e.getKey(), from(e.getValue())); }/*from w ww. j a v a 2s . co m*/ return parameters; }
From source file:org.apache.isis.core.runtime.system.persistence.adaptermanager.PojoAdapterHashMap.java
public PojoAdapterHashMap(final int capacity) { adapterByPojoMap = Maps.newHashMapWithExpectedSize(capacity); }
From source file:org.apache.phoenix.parse.PrimaryKeyConstraint.java
PrimaryKeyConstraint(String name, List<ColumnDefInPkConstraint> columnDefs) { super(name);/* w w w.j a v a 2s . c om*/ if (columnDefs == null) { this.columns = Collections.<Pair<ColumnName, SortOrder>>emptyList(); this.columnNameToSortOrder = Collections.<ColumnName, Pair<ColumnName, SortOrder>>emptyMap(); this.columnNameToRowTimestamp = Collections.<ColumnName, Pair<ColumnName, Boolean>>emptyMap(); numColumnsWithRowTimestamp = 0; } else { int numRowTimestampCols = 0; List<Pair<ColumnName, SortOrder>> l = new ArrayList<>(columnDefs.size()); this.columnNameToSortOrder = Maps.newHashMapWithExpectedSize(columnDefs.size()); this.columnNameToRowTimestamp = Maps.newHashMapWithExpectedSize(columnDefs.size()); for (ColumnDefInPkConstraint colDef : columnDefs) { Pair<ColumnName, SortOrder> p = Pair.newPair(colDef.getColumnName(), colDef.getSortOrder()); l.add(p); this.columnNameToSortOrder.put(colDef.getColumnName(), p); this.columnNameToRowTimestamp.put(colDef.getColumnName(), Pair.newPair(colDef.getColumnName(), colDef.isRowTimestamp())); if (colDef.isRowTimestamp()) { numRowTimestampCols++; } } this.numColumnsWithRowTimestamp = numRowTimestampCols; this.columns = ImmutableList.copyOf(l); } }
From source file:com.kingen.web.AssetsController.java
/** * ?grid//from w w w.j ava 2s .com */ //?jsonstring ?jsonObject @RequestMapping(value = "/type/treeData") public @ResponseBody Object data(Page<AssetsType> page, HttpServletResponse response) { List<AssetsType> all = service.list("AssetsType"); 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:com.romeikat.datamessie.core.base.ui.component.AbstractIdBasedChoiceProvider.java
public AbstractIdBasedChoiceProvider() { super();//from w w w . jav a2s . c o m choicesModel = new LoadableDetachableModel<Map<Long, T>>() { private static final long serialVersionUID = 1L; @Override protected Map<Long, T> load() { final List<T> choices = provideChoices(); final Map<Long, T> choicesMap = Maps.newHashMapWithExpectedSize(choices.size()); for (final T choice : choices) { final long id = provideId(choice); choicesMap.put(id, choice); } return choicesMap; } }; }
From source file:org.apache.mahout.clustering.kmeans.EigenSeedGenerator.java
public static Path buildFromEigens(Configuration conf, Path input, Path output, int k, DistanceMeasure measure) throws IOException { // delete the output directory FileSystem fs = FileSystem.get(output.toUri(), conf); HadoopUtil.delete(conf, output);// w w w . j a va2 s . co m Path outFile = new Path(output, "part-eigenSeed"); boolean newFile = fs.createNewFile(outFile); if (newFile) { Path inputPathPattern; if (fs.getFileStatus(input).isDir()) { inputPathPattern = new Path(input, "*"); } else { inputPathPattern = input; } FileStatus[] inputFiles = fs.globStatus(inputPathPattern, PathFilters.logsCRCFilter()); SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, outFile, Text.class, ClusterWritable.class); Map<Integer, Double> maxEigens = Maps.newHashMapWithExpectedSize(k); // store // max // value // of // each // column Map<Integer, Text> chosenTexts = Maps.newHashMapWithExpectedSize(k); Map<Integer, ClusterWritable> chosenClusters = Maps.newHashMapWithExpectedSize(k); for (FileStatus fileStatus : inputFiles) { if (!fileStatus.isDir()) { for (Pair<Writable, VectorWritable> record : new SequenceFileIterable<Writable, VectorWritable>( fileStatus.getPath(), true, conf)) { Writable key = record.getFirst(); VectorWritable value = record.getSecond(); for (Vector.Element e : value.get().nonZeroes()) { int index = e.index(); double v = Math.abs(e.get()); if (!maxEigens.containsKey(index) || v > maxEigens.get(index)) { maxEigens.put(index, v); Text newText = new Text(key.toString()); chosenTexts.put(index, newText); Kluster newCluster = new Kluster(value.get(), index, measure); newCluster.observe(value.get(), 1); ClusterWritable clusterWritable = new ClusterWritable(); clusterWritable.setValue(newCluster); chosenClusters.put(index, clusterWritable); } } } } } try { for (Integer key : maxEigens.keySet()) { writer.append(chosenTexts.get(key), chosenClusters.get(key)); } log.info("EigenSeedGenerator:: Wrote {} Klusters to {}", chosenTexts.size(), outFile); } finally { Closeables.close(writer, false); } } return outFile; }
From source file:com.radeonsys.data.querystore.support.AbstractHashMapQueryStore.java
/** * Creates a new instance of {@code AbstractHashMapQueryStore} */ public AbstractHashMapQueryStore() { queryMap = Maps.newHashMapWithExpectedSize(INITIAL_MAP_SIZE); }
From source file:com.palantir.atlasdb.keyvalue.jdbc.impl.SingleTimestampPutBatch.java
@Override @Nullable//from ww w . j av a 2 s . c o m public PutBatch getNextBatch(Result<? extends Record> existingRecords) { Map<Cell, byte[]> existing = Maps.newHashMapWithExpectedSize(existingRecords.size()); for (Record record : existingRecords) { existing.put(Cell.create(record.getValue(JdbcConstants.A_ROW_NAME), record.getValue(JdbcConstants.A_COL_NAME)), record.getValue(JdbcConstants.A_VALUE)); } Map<Cell, byte[]> nextBatch = Maps.newHashMap(); for (Entry<Cell, byte[]> entry : data.entrySet()) { Cell cell = entry.getKey(); byte[] newValue = entry.getValue(); byte[] oldValue = existing.get(cell); if (oldValue == null) { nextBatch.put(cell, newValue); } else if (!Arrays.equals(oldValue, newValue)) { return null; } } return new SingleTimestampPutBatch(nextBatch, timestamp); }
From source file:com.attribyte.essem.BasicAuth.java
/** * Create from properties of the form username:password=index0,index1,... * @param props The properties./*from w w w. j a v a2 s . c o m*/ */ public BasicAuth(final Properties props) { Map<HashCode, Set<String>> authMap = Maps.newHashMapWithExpectedSize(16); Set<String> indexSet = Sets.newLinkedHashSetWithExpectedSize(16); Splitter indexSplitter = Splitter.on(CharMatcher.anyOf(", \t")).trimResults().omitEmptyStrings(); Enumeration names = props.propertyNames(); while (names.hasMoreElements()) { String key = ((String) names.nextElement()).trim(); String up = key.replace('|', ':'); String expectedValue = "Basic " + EncodingUtil.encodeBase64(up.getBytes(Charsets.UTF_8)); HashCode expectedValueCode = hashFunction.hashString(expectedValue, Charsets.UTF_8); Set<String> allowSet = authMap.get(expectedValueCode); if (allowSet == null) { allowSet = Sets.newLinkedHashSetWithExpectedSize(16); authMap.put(expectedValueCode, allowSet); } String indexStr = props.getProperty(key).trim(); for (String index : indexSplitter.split(indexStr)) { if (!index.equals("*")) { indexSet.add(index); } allowSet.add(index); } } this.authorizedIndexes = ImmutableSet.copyOf(indexSet); ImmutableMap.Builder<HashCode, ImmutableSet<String>> builder = ImmutableMap.builder(); for (Map.Entry<HashCode, Set<String>> entry : authMap.entrySet()) { builder.put(entry.getKey(), ImmutableSet.copyOf(entry.getValue())); } this.authMap = builder.build(); }