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.spongepowered.common.data.processor.data.tileentity.JukeboxDataProcessor.java
@Override protected Map<Key<?>, ?> getValues(BlockJukebox.TileEntityJukebox entity) { HashMap<Key<?>, ItemStackSnapshot> values = Maps.newHashMapWithExpectedSize(1); if (entity.getRecord() != null) { values.put(Keys.REPRESENTED_ITEM, ((org.spongepowered.api.item.inventory.ItemStack) entity.getRecord()).createSnapshot()); }// w ww .j a v a 2 s .c o m return values; }
From source file:org.jalphanode.jmx.MBeanAnnotationScanner.java
protected void buildAttributeMetadata(final Class<?> klass, final BeanInfo beanInfo, final MBeanMetadata.Builder builder) { final List<Field> fields = ReflectionUtils.getAnnotatedFields(klass, ManagedAttribute.class); final Map<String, Field> indexFields = Maps.newHashMapWithExpectedSize(fields.size()); for (Field field : fields) { indexFields.put(field.getName(), field); }//from w ww. ja v a 2 s . c o m PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); final Set<String> attributes = Sets.newHashSetWithExpectedSize(propertyDescriptors.length); for (PropertyDescriptor property : propertyDescriptors) { final Field annotatedField = indexFields.remove(property.getName()); final Method readMethod = property.getReadMethod(); final Method writeMethod = property.getWriteMethod(); ManagedAttribute annotation = getManagedAttribute(property.getName(), annotatedField, readMethod, writeMethod); if (annotation != null) { final String name = annotation.name().isEmpty() ? property.getName() : annotation.name(); if (!attributes.add(name)) { throw new MalformedMBeanException( MessageFormat.format("Attribute with name {0} already registered", name)); } ManagedAttributeMetadata.Builder attributeBuilder = new ManagedAttributeMetadata.Builder(name); if (!annotation.description().isEmpty()) { attributeBuilder.withDescription(annotation.description()); } if (readMethod != null) { attributeBuilder.withReadMethod(readMethod); } if (writeMethod != null) { attributeBuilder.withWriteMethod(writeMethod); } builder.putAttribute(attributeBuilder.build()); } } if (!indexFields.isEmpty()) { throw new MalformedMBeanException( MessageFormat.format("Found attribute(s) without getters/setters: {0}", indexFields.keySet())); } }
From source file:org.spongepowered.server.launch.transformer.deobf.NotchDeobfuscationTransformer.java
public NotchDeobfuscationTransformer() throws IOException { URL mappings = (URL) Launch.blackboard.get("vanilla.srg_mappings"); SrgReader reader = new SrgReader(); reader.read(mappings);/*from ww w .ja v a 2 s . co m*/ this.classes = reader.getClasses(); this.rawFields = reader.getFields(); this.rawMethods = reader.getMethods(); this.fields = Maps.newHashMapWithExpectedSize(this.rawFields.size()); this.methods = Maps.newHashMapWithExpectedSize(this.rawMethods.size()); }
From source file:org.eclipse.xtext.resource.SaveOptions.java
public Map<Object, Object> toOptionsMap() { Map<Object, Object> result = Maps.newHashMapWithExpectedSize(2); addTo(result); return result; }
From source file:com.android.tools.klint.checks.ControlFlowGraph.java
/** * Creates a new {@link ControlFlowGraph} and populates it with the flow * control for the given method. If the optional {@code initial} parameter is * provided with an existing graph, then the graph is simply populated, not * created. This allows subclassing of the graph instance, if necessary. * * @param initial usually null, but can point to an existing instance of a * {@link ControlFlowGraph} in which that graph is reused (but * populated with new edges)// w w w. j a v a 2 s. com * @param classNode the class containing the method to be analyzed * @param method the method to be analyzed * @return a {@link ControlFlowGraph} with nodes for the control flow in the * given method * @throws AnalyzerException if the underlying bytecode library is unable to * analyze the method bytecode */ @NonNull public static ControlFlowGraph create(@Nullable ControlFlowGraph initial, @NonNull ClassNode classNode, @NonNull MethodNode method) throws AnalyzerException { final ControlFlowGraph graph = initial != null ? initial : new ControlFlowGraph(); final InsnList instructions = method.instructions; graph.mNodeMap = Maps.newHashMapWithExpectedSize(instructions.size()); graph.mMethod = method; // Create a flow control graph using ASM5's analyzer. According to the ASM 4 guide // (download.forge.objectweb.org/asm/asm4-guide.pdf) there are faster ways to construct // it, but those require a lot more code. Analyzer analyzer = new Analyzer(new BasicInterpreter()) { @Override protected void newControlFlowEdge(int insn, int successor) { // Update the information as of whether the this object has been // initialized at the given instruction. AbstractInsnNode from = instructions.get(insn); AbstractInsnNode to = instructions.get(successor); graph.add(from, to); } @Override protected boolean newControlFlowExceptionEdge(int insn, TryCatchBlockNode tcb) { AbstractInsnNode from = instructions.get(insn); graph.exception(from, tcb); return super.newControlFlowExceptionEdge(insn, tcb); } @Override protected boolean newControlFlowExceptionEdge(int insn, int successor) { AbstractInsnNode from = instructions.get(insn); AbstractInsnNode to = instructions.get(successor); graph.exception(from, to); return super.newControlFlowExceptionEdge(insn, successor); } }; analyzer.analyze(classNode.name, method); return graph; }
From source file:com.twitter.elephanttwin.lucene.indexing.HadoopSplitDocument.java
@Override public void readFields(DataInput in) throws IOException { clear();//from w w w . j av a 2s . c o m cnt = in.readInt(); offset = in.readLong(); int numKeyVals = in.readInt(); keyValueListMap = Maps.newHashMapWithExpectedSize(numKeyVals); for (int i = 0; i < numKeyVals; i++) { String key = in.readUTF(); int numEntries = in.readInt(); Set<String> valueSet = Sets.newHashSetWithExpectedSize(numEntries); for (int j = 0; j < numEntries; j++) { valueSet.add(in.readUTF()); } keyValueListMap.put(key, valueSet); } if (split == null) { // Initializing to nonsense split = new FileSplit(null, 0, 0, null); } split.readFields(in); }
From source file:com.palantir.atlasdb.keyvalue.impl.TableRemappingKeyValueService.java
@Override public void createTables(Map<TableReference, byte[]> tableReferencesToTableMetadata) { Map<String, byte[]> tableNameToTableMetadata = Maps .newHashMapWithExpectedSize(tableReferencesToTableMetadata.size()); for (Entry<TableReference, byte[]> tableEntry : tableReferencesToTableMetadata.entrySet()) { tableNameToTableMetadata.put(tableMapper.addTable(tableEntry.getKey()), tableEntry.getValue()); }/*from www .j a v a2s .co m*/ delegate().createTables(tableNameToTableMetadata); }
From source file:com.amd.gerrit.plugins.manifestsubscription.Utilities.java
static ObjectId updateManifest(GitRepositoryManager gitRepoManager, MetaDataUpdate.Server metaDataUpdateFactory, ChangeHooks changeHooks, String projectName, String refName, Manifest manifest, String manifestSrc, String extraCommitMsg, String defaultBranchBase) throws JAXBException, IOException { Project.NameKey p = new Project.NameKey(projectName); Repository repo = gitRepoManager.openRepository(p); MetaDataUpdate update = metaDataUpdateFactory.create(p); ObjectId commitId = repo.resolve(refName); VersionedManifests vManifests = new VersionedManifests(refName); //TODO find a better way to detect no branch boolean refExists = true; try {//from w w w. j a va2 s.c o m vManifests.load(update, commitId); } catch (Exception e) { refExists = false; } RevCommit commit = null; if (refExists) { Map<String, Manifest> entry = Maps.newHashMapWithExpectedSize(1); entry.put("default.xml", manifest); vManifests.setManifests(entry); vManifests.setSrcManifestRepo(manifestSrc); vManifests.setExtraCommitMsg(extraCommitMsg); commit = vManifests.commit(update); } else { if (defaultBranchBase == null) defaultBranchBase = "refs/heads/master"; vManifests = new VersionedManifests(defaultBranchBase); ObjectId cid = repo.resolve(defaultBranchBase); try { vManifests.load(update, cid); } catch (ConfigInvalidException e) { e.printStackTrace(); } Map<String, Manifest> entry = Maps.newHashMapWithExpectedSize(1); entry.put("default.xml", manifest); vManifests.setManifests(entry); commit = vManifests.commitToNewRef(update, refName); } // TODO this may be bug in the MetaDataUpdate or VersionedMetaData // May be related: // https://code.google.com/p/gerrit/issues/detail?id=2564 // https://gerrit-review.googlesource.com/55540 if (commit != null) { ObjectId parent = ObjectId.zeroId(); if (commit.getParents().length > 0) { parent = commit.getParent(0).getId(); } changeHooks.doRefUpdatedHook(new Branch.NameKey(p, refName), parent, commit.getId(), null); return commit.getId(); } else { log.warn("Failing to commit manifest subscription update:" + "\n\tProject: " + projectName + "\n\tRef: " + refName); } return null; }
From source file:com.vmware.appfactory.taskqueue.tasks.TaskRecorder.java
TaskRecorder(int expectedSize, int maxFinishedSize, int expectedTasksPerId) { mapTaskIdToTask = Maps.newHashMapWithExpectedSize(expectedSize); mapTaskHandleToTasks = LinkedHashMultimap.create(expectedSize + maxFinishedSize, expectedTasksPerId); }
From source file:co.cask.cdap.data2.queue.QueueEntry.java
public static Map<String, Integer> deserializeHashKeys(byte[] bytes, int off, int len) throws IOException { if (bytes == null || (len == 1 && bytes[off] == 0)) { // No hash keys. return ImmutableMap.of(); }//from w ww. j a va 2 s. c o m ByteArrayInputStream bis = new ByteArrayInputStream(bytes, off, len); BinaryDecoder decoder = new BinaryDecoder(bis); int size = decoder.readInt(); Map<String, Integer> hashKeys = Maps.newHashMapWithExpectedSize(size); while (size > 0) { // per avro spec, ther ecan be multiple blocks while (size-- > 0) { String key = decoder.readString(); int value = decoder.readInt(); hashKeys.put(key, value); } size = decoder.readInt(); // next block length, will be always zero in this case } return hashKeys; }