List of usage examples for com.google.common.collect Lists newArrayListWithExpectedSize
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize)
From source file:org.eclipse.xtext.xbase.scoping.batch.NestedTypeLiteralScope.java
@Override protected List<IEObjectDescription> getAllLocalElements() { List<IEObjectDescription> result = Lists.newArrayListWithExpectedSize(2); if (rawEnclosingType instanceof JvmDeclaredType) { for (JvmMember member : ((JvmDeclaredType) rawEnclosingType).getMembers()) { if (member instanceof JvmDeclaredType) { IEObjectDescription description = EObjectDescription.create(member.getSimpleName(), member); addToList(new TypeLiteralDescription(description, enclosingType, isVisible((JvmType) member)), result);/*from ww w .ja va 2 s . co m*/ } } } return result; }
From source file:org.nmdp.ngs.align.ParallelBiojavaPairwiseAlignment.java
@Override public Iterable<AlignmentPair> global(final List<Sequence> queries, final List<Sequence> subjects, final GapPenalties gapPenalties) { checkNotNull(queries);/*from www. j ava2s . co m*/ checkNotNull(subjects); checkNotNull(gapPenalties); if (queries.isEmpty() || subjects.isEmpty()) { return Collections.<AlignmentPair>emptyList(); } List<NeedlemanWunschTask> tasks = Lists.newArrayListWithExpectedSize(queries.size() * subjects.size()); for (Sequence query : queries) { for (Sequence subject : subjects) { tasks.add(new NeedlemanWunschTask(query, subject, gapPenalties, getSubstitutionMatrix())); } } List<AlignmentPair> alignmentPairs = Lists.newArrayListWithExpectedSize(queries.size() * subjects.size()); try { List<Future<AlignmentPair>> futures = executorService.invokeAll(tasks); for (Future<AlignmentPair> future : futures) { alignmentPairs.add(future.get()); } } catch (ExecutionException | InterruptedException e) { // todo } return alignmentPairs; }
From source file:org.terasology.rendering.assetLoaders.md5.MD5AnimationLoader.java
private MeshAnimation createAnimation(AssetUri uri, MD5 md5) { MeshAnimation animation = new MeshAnimation(uri); String[] boneNames = new String[md5.numJoints]; int[] boneParents = new int[md5.numJoints]; for (int i = 0; i < md5.numJoints; ++i) { boneNames[i] = md5.joints[i].name; boneParents[i] = md5.joints[i].parent; }//ww w . j a v a 2 s .co m animation.setBones(boneNames, boneParents); animation.setTimePerFrame(1.0f / md5.frameRate); for (int frameIndex = 0; frameIndex < md5.numFrames; ++frameIndex) { MD5Frame frame = md5.frames[frameIndex]; List<Vector3f> positions = Lists.newArrayListWithExpectedSize(md5.numJoints); List<Vector3f> rawRotations = Lists.newArrayListWithExpectedSize(md5.numJoints); for (int i = 0; i < md5.numJoints; ++i) { positions.add(new Vector3f(md5.baseFramePosition[i])); rawRotations.add(new Vector3f(md5.baseFrameOrientation[i])); } for (int jointIndex = 0; jointIndex < md5.numJoints; ++jointIndex) { int compIndex = 0; if ((md5.joints[jointIndex].flags & POSITION_X_FLAG) != 0) { positions.get(jointIndex).x = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & POSITION_Y_FLAG) != 0) { positions.get(jointIndex).y = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & POSITION_Z_FLAG) != 0) { positions.get(jointIndex).z = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & ORIENTATION_X_FLAG) != 0) { rawRotations.get(jointIndex).x = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & ORIENTATION_Y_FLAG) != 0) { rawRotations.get(jointIndex).y = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & ORIENTATION_Z_FLAG) != 0) { rawRotations.get(jointIndex).z = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } } List<Quat4f> rotations = Lists.newArrayListWithCapacity(rawRotations.size()); for (Vector3f rot : rawRotations) { rotations.add(MD5ParserCommon.completeQuat4f(rot.x, rot.y, rot.z)); } // Rotate just the root bone to correct for coordinate system differences rotations.set(0, MD5ParserCommon.correctQuat4f(rotations.get(0))); animation.addFrame(new MeshAnimationFrame(positions, rotations)); } return animation; }
From source file:com.android.tools.idea.res.ModuleResourceRepository.java
/** * Creates a new resource repository for the given module, <b>not</b> including its dependent modules. * * @param facet the facet for the module * @return the resource repository/*from w w w . j a v a 2s. c o m*/ */ @NotNull public static LocalResourceRepository create(@NotNull final AndroidFacet facet) { boolean gradleProject = facet.requiresAndroidModel(); if (!gradleProject) { // Always just a single resource folder: simple VirtualFile primaryResourceDir = facet.getPrimaryResourceDir(); if (primaryResourceDir == null) { return new EmptyRepository(); } return ResourceFolderRegistry.get(facet, primaryResourceDir); } ResourceFolderManager folderManager = facet.getResourceFolderManager(); List<VirtualFile> resourceDirectories = folderManager.getFolders(); List<LocalResourceRepository> resources = Lists.newArrayListWithExpectedSize(resourceDirectories.size()); for (VirtualFile resourceDirectory : resourceDirectories) { ResourceFolderRepository repository = ResourceFolderRegistry.get(facet, resourceDirectory); resources.add(repository); } DynamicResourceValueRepository dynamicResources = DynamicResourceValueRepository.create(facet); resources.add(dynamicResources); // We create a ModuleResourceRepository even if resources.isEmpty(), because we may // dynamically add children to it later (in updateRoots) final ModuleResourceRepository repository = new ModuleResourceRepository(facet, resources); Disposer.register(repository, dynamicResources); return repository; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ConstructInvocation.java
public static GambitCreator.Invocable boundInvoke(Type targetType, final TypeWidget owner, final List<ConstructorGenerator> constructorGenerators, final BytecodeExpression... args) { if (null != constructorGenerators && !constructorGenerators.isEmpty()) { List<ConstructorGenerator> foundGenerators = Lists.newArrayList(); for (ConstructorGenerator generator : constructorGenerators) { List<TypeWidget> argumentTypes = generator.getArgumentTypes(); if (argumentTypes.size() != args.length) { continue; }//w w w . j av a2 s. c om boolean assignable = true; for (int i = 0; i < argumentTypes.size(); i++) { if (!argumentTypes.get(i).isAssignableFrom(args[i].getType())) { assignable = false; } if (!assignable) { break; } } if (assignable) { foundGenerators.add(generator); } } if (foundGenerators.size() == 1) { ConstructorGenerator foundConstructor = foundGenerators.get(0); List<TypeWidget> foundArguments = foundConstructor.getArgumentTypes(); GambitCreator.Invocable constructor = constructor(targetType, owner, foundArguments); List<BytecodeExpression> resultArgs = Lists.newArrayListWithExpectedSize(args.length); for (int i = 0; i < args.length; i++) { resultArgs.add(new BytecodeCastExpression(foundArguments.get(i), args[i])); } return constructor.prefix(resultArgs); } else if (foundGenerators.size() == 0) { throw new ProgramCompileException("No matching ConstructorGenerator"); } else { throw new ProgramCompileException("Found ambiguous constructors for " + args); } } else { throw new ProgramCompileException("No available ConstructorGenerator"); } }
From source file:com.arpnetworking.test.junitbenchmarks.JsonBenchmarkConsumer.java
/** * {@inheritDoc}//from w w w. j a v a 2 s .co m */ @Override public void close() { if (!_closed) { try { // Create the output path final Path outputDirectory = _path.getParent(); final String nameWithoutExtension = com.google.common.io.Files .getNameWithoutExtension(_path.toString()); ensurePathExists(); // Merge the results final List<AugmentedResult> augmentedResults = Lists.newArrayListWithExpectedSize( _resultsWithoutProfileData.size() + _resultsWithProfileData.size()); // Simply wrap the results without profile data augmentedResults.addAll( _resultsWithoutProfileData.stream().map(AugmentedResult::new).collect(Collectors.toList())); // For results with profile data extract the data and pair it with the result for (final Map.Entry<Integer, Result> entry : _resultsWithProfileData.entrySet()) { final int index = entry.getKey(); final Result result = entry.getValue(); final Optional<Path> profileDataFile = getProfileFile(); if (profileDataFile.isPresent()) { LOGGER.info( String.format("Filtering profile for %s.%s in %s at %d", result.getTestClassName(), result.getTestMethodName(), profileDataFile.get(), index)); final Path extractedProfileDataFile = outputDirectory .resolve(nameWithoutExtension + "." + result.getTestMethodName() + ".hprof"); new HProfFilter(profileDataFile.get(), Optional.of(extractedProfileDataFile), Optional.of(index)).run(); augmentedResults.add(new AugmentedResult(result, extractedProfileDataFile)); } else { LOGGER.warn("Profile data file lost between accept and close"); augmentedResults.add(new AugmentedResult(result)); } } // Output the test performance results LOGGER.info(String.format("Closing; file=%s", _path)); final FileOutputStream outputStream = new FileOutputStream(_path.toString(), _append); try { OBJECT_MAPPER.writeValue(outputStream, augmentedResults); outputStream.write("\n".getBytes(StandardCharsets.UTF_8)); } finally { IOUtils.closeQuietly(outputStream); } } catch (final IOException e) { LOGGER.error("Could not write json performance file", e); } _closed = true; } }
From source file:defrac.intellij.projectView.DefracViewPlatformNode.java
@NotNull @Override/*from w w w . j a v a 2 s.c om*/ public Collection<AbstractTreeNode> getChildren() { final Project project = getProject(); if (project == null) { return Lists.newArrayListWithCapacity(0); } final DefracProjectPlatform projectWithPlatform = getValue(); final ArrayList<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(2); if (projectWithPlatform == null || projectWithPlatform.isDisposed()) { setValue(null); return children; } final List<Module> sourceModules = Lists.newArrayList(); final List<Module> macroModules = Lists.newArrayList(); for (final Module module : projectWithPlatform.getModules()) { final DefracFacet facet = DefracFacet.getInstance(module); if (facet == null) { continue; } if (facet.isMacroLibrary()) { macroModules.add(module); } else { sourceModules.add(module); } } addModules(project, children, DefracProjectViewUtil.SOURCE, sourceModules); addModules(project, children, DefracProjectViewUtil.MACROS, macroModules); return children; }
From source file:com.android.ide.common.repository.ResourceVisibilityLookup.java
/** * Creates a {@link ResourceVisibilityLookup} for the set of libraries. * <p>/*from w ww . j av a2 s .com*/ * NOTE: The {@link Provider} class can be used to share/cache {@link ResourceVisibilityLookup} * instances, e.g. when you have library1 and library2 each referencing libraryBase, the {@link * Provider} will ensure that a the libraryBase data is shared. * * @param libraries the list of libraries * @param provider an optional manager instance for caching of individual libraries, if any * @return a corresponding {@link ResourceVisibilityLookup} */ @NonNull public static ResourceVisibilityLookup create(@NonNull List<AndroidLibrary> libraries, @Nullable Provider provider) { List<ResourceVisibilityLookup> list = Lists.newArrayListWithExpectedSize(libraries.size()); for (AndroidLibrary library : libraries) { ResourceVisibilityLookup v = provider != null ? provider.get(library) : create(library); if (!v.isEmpty()) { list.add(v); } } return new MultipleLibraryResourceVisibility(list); }
From source file:org.apache.phoenix.compile.TrackOrderPreservingExpressionCompiler.java
TrackOrderPreservingExpressionCompiler(StatementContext context, GroupBy groupBy, int expectedEntrySize, Ordering ordering, TupleProjector tupleProjector) { super(context, groupBy); PTable table = context.getResolver().getTables().get(0).getTable(); boolean isSalted = table.getBucketNum() != null; boolean isMultiTenant = context.getConnection().getTenantId() != null && table.isMultiTenant(); boolean isSharedViewIndex = table.getViewIndexId() != null; // TODO: util for this offset, as it's computed in numerous places positionOffset = (isSalted ? 1 : 0) + (isMultiTenant ? 1 : 0) + (isSharedViewIndex ? 1 : 0); entries = Lists.newArrayListWithExpectedSize(expectedEntrySize); this.ordering = ordering; this.tupleProjector = tupleProjector; }
From source file:org.terasology.rendering.md5.MD5AnimationLoader.java
private MeshAnimationData createAnimation(MD5 md5) { List<String> boneNames = Lists.newArrayListWithCapacity(md5.numJoints); TIntList boneParents = new TIntArrayList(md5.numJoints); for (int i = 0; i < md5.numJoints; ++i) { boneNames.add(md5.joints[i].name); boneParents.add(md5.joints[i].parent); }/* w w w . java 2 s . c o m*/ float timePerFrame = 1.0f / md5.frameRate; List<MeshAnimationFrame> frames = Lists.newArrayList(); for (int frameIndex = 0; frameIndex < md5.numFrames; ++frameIndex) { MD5Frame frame = md5.frames[frameIndex]; List<Vector3f> positions = Lists.newArrayListWithExpectedSize(md5.numJoints); List<Vector3f> rawRotations = Lists.newArrayListWithExpectedSize(md5.numJoints); for (int i = 0; i < md5.numJoints; ++i) { positions.add(new Vector3f(md5.baseFramePosition[i])); rawRotations.add(new Vector3f(md5.baseFrameOrientation[i])); } for (int jointIndex = 0; jointIndex < md5.numJoints; ++jointIndex) { int compIndex = 0; if ((md5.joints[jointIndex].flags & POSITION_X_FLAG) != 0) { positions.get(jointIndex).x = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & POSITION_Y_FLAG) != 0) { positions.get(jointIndex).y = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & POSITION_Z_FLAG) != 0) { positions.get(jointIndex).z = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & ORIENTATION_X_FLAG) != 0) { rawRotations.get(jointIndex).x = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & ORIENTATION_Y_FLAG) != 0) { rawRotations.get(jointIndex).y = frame.components[md5.joints[jointIndex].startIndex + compIndex]; compIndex++; } if ((md5.joints[jointIndex].flags & ORIENTATION_Z_FLAG) != 0) { rawRotations.get(jointIndex).z = frame.components[md5.joints[jointIndex].startIndex + compIndex]; } } List<Quat4f> rotations = Lists.newArrayListWithCapacity(rawRotations.size()); for (Vector3f rot : rawRotations) { rotations.add(MD5ParserCommon.completeQuat4f(rot.x, rot.y, rot.z)); } // Rotate just the root bone to correct for coordinate system differences rotations.set(0, MD5ParserCommon.correctQuat4f(rotations.get(0))); positions.set(0, MD5ParserCommon.correctOffset(positions.get(0))); frames.add(new MeshAnimationFrame(positions, rotations)); } return new MeshAnimationData(boneNames, boneParents, frames, timePerFrame); }