List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:com.facebook.stats.mx.StatsUtil.java
private static String serializeHistogram(QuantileDigest digest) { int buckets = 100; long min = digest.getMin(); long max = digest.getMax(); long bucketSize = (max - min + buckets) / buckets; ImmutableList.Builder<Long> boundaryBuilder = ImmutableList.builder(); for (int i = 1; i < buckets + 1; ++i) { boundaryBuilder.add(min + bucketSize * i); }//from w w w . j a v a 2 s . co m ImmutableList<Long> boundaries = boundaryBuilder.build(); List<QuantileDigest.Bucket> counts = digest.getHistogram(boundaries); StringBuilder builder = new StringBuilder(); // add bogus bucket (fb303 ui ignores the first one, for whatever reason) builder.append("-1:0:0,"); for (int i = 0; i < boundaries.size(); ++i) { long lowBoundary = min; if (i > 0) { lowBoundary = boundaries.get(i - 1); } builder.append(lowBoundary).append(':').append(Math.round(counts.get(i).getCount())).append(':') .append(Math.round(counts.get(i).getMean())).append(','); } // add a final bucket so that fb303 ui shows the max value builder.append(max); builder.append(":0:0"); return builder.toString(); }
From source file:com.noodlewiz.xjavab.ext.render.internal.ReplyUnpacker.java
public static QueryPictFormatsReply unpackQueryPictFormats(final ByteBuffer __xjb_buf) { __xjb_buf.position(4);/*from ww w . ja va 2 s . c om*/ final long length = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); __xjb_buf.position(1); com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 1); __xjb_buf.position(8); final long numFormats = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final long numScreens = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final long numDepths = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final long numVisuals = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final long numSubpixel = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 4); final com.google.common.collect.ImmutableList.Builder<Pictforminfo> __xjb_formatsBuilder = new com.google.common.collect.ImmutableList.Builder<Pictforminfo>(); for (int __xjb_i = 0; (__xjb_i < numFormats); __xjb_i++) { __xjb_formatsBuilder .add(com.noodlewiz.xjavab.ext.render.internal.Unpacker.unpackPictforminfo(__xjb_buf)); } final List<Pictforminfo> formats = __xjb_formatsBuilder.build(); final com.google.common.collect.ImmutableList.Builder<Pictscreen> __xjb_screensBuilder = new com.google.common.collect.ImmutableList.Builder<Pictscreen>(); for (int __xjb_i = 0; (__xjb_i < numScreens); __xjb_i++) { __xjb_screensBuilder.add(com.noodlewiz.xjavab.ext.render.internal.Unpacker.unpackPictscreen(__xjb_buf)); } final List<Pictscreen> screens = __xjb_screensBuilder.build(); final com.google.common.collect.ImmutableList.Builder<Long> __xjb_subpixelsBuilder = new com.google.common.collect.ImmutableList.Builder<Long>(); for (int __xjb_i = 0; (__xjb_i < numSubpixel); __xjb_i++) { __xjb_subpixelsBuilder.add(com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf)); } final List<Long> subpixels = __xjb_subpixelsBuilder.build(); return new QueryPictFormatsReply(numFormats, numScreens, numDepths, numVisuals, numSubpixel, formats, screens, subpixels); }
From source file:com.facebook.buck.rules.UberRDotJavaUtil.java
public static void createDummyRDotJavaFiles(ImmutableList<AndroidResourceRule> androidResourceDeps, BuildTarget buildTarget, ImmutableList.Builder<Step> commands) { // Clear out the folder for the .java files. String rDotJavaSrcFolder = getRDotJavaSrcFolder(buildTarget); commands.add(new MakeCleanDirectoryStep(rDotJavaSrcFolder)); // Generate the .java files and record where they will be written in javaSourceFilePaths. Set<String> javaSourceFilePaths = Sets.newHashSet(); if (androidResourceDeps.isEmpty()) { // In this case, the user is likely running a Robolectric test that does not happen to // depend on any resources. However, if Robolectric doesn't find an R.java file, it flips // out, so we have to create one, anyway. // TODO(mbolin): Stop hardcoding com.facebook. This should match the package in the // associated TestAndroidManifest.xml file. String rDotJavaPackage = "com.facebook"; String javaCode = MergeAndroidResourcesStep.generateJavaCodeForPackageWithoutResources(rDotJavaPackage); commands.add(new MakeCleanDirectoryStep(rDotJavaSrcFolder + "/com/facebook")); String rDotJavaFile = rDotJavaSrcFolder + "/com/facebook/R.java"; commands.add(new WriteFileStep(javaCode, rDotJavaFile)); javaSourceFilePaths.add(rDotJavaFile); } else {// w w w . j a v a 2 s . c o m Map<String, String> symbolsFileToRDotJavaPackage = Maps.newHashMap(); for (AndroidResourceRule res : androidResourceDeps) { String rDotJavaPackage = res.getRDotJavaPackage(); symbolsFileToRDotJavaPackage.put(res.getPathToTextSymbolsFile(), rDotJavaPackage); String rDotJavaFilePath = MergeAndroidResourcesStep.getOutputFilePath(rDotJavaSrcFolder, rDotJavaPackage); javaSourceFilePaths.add(rDotJavaFilePath); } commands.add(new MergeAndroidResourcesStep(symbolsFileToRDotJavaPackage, rDotJavaSrcFolder)); } // Clear out the directory where the .class files will be generated. String rDotJavaClassesDirectory = getRDotJavaBinFolder(buildTarget); commands.add(new MakeCleanDirectoryStep(rDotJavaClassesDirectory)); // Compile the .java files. JavacInMemoryStep javac = createJavacInMemoryCommandForRDotJavaFiles(javaSourceFilePaths, rDotJavaClassesDirectory); commands.add(javac); }
From source file:com.google.devtools.j2objc.gen.GeneratedType.java
public static GeneratedType fromTypeDeclaration(AbstractTypeDeclaration typeNode) { ITypeBinding typeBinding = typeNode.getTypeBinding(); CompilationUnit unit = TreeUtil.getCompilationUnit(typeNode); NameTable nameTable = unit.getNameTable(); ImmutableList.Builder<String> superTypes = ImmutableList.builder(); ITypeBinding superclass = typeBinding.getSuperclass(); if (superclass != null) { superTypes.add(nameTable.getFullName(superclass)); }/*from w ww.ja v a 2 s. co m*/ for (ITypeBinding superInterface : typeBinding.getInterfaces()) { superTypes.add(nameTable.getFullName(superInterface)); } HeaderImportCollector headerCollector = new HeaderImportCollector(HeaderImportCollector.Filter.PUBLIC_ONLY); headerCollector.collect(typeNode); HeaderImportCollector privateDeclarationCollector = new HeaderImportCollector( HeaderImportCollector.Filter.PRIVATE_ONLY); privateDeclarationCollector.collect(typeNode); ImplementationImportCollector importCollector = new ImplementationImportCollector(); importCollector.collect(typeNode); SourceBuilder builder = new SourceBuilder(Options.emitLineDirectives()); TypeDeclarationGenerator.generate(builder, typeNode); String publicDeclarationCode = builder.toString(); builder = new SourceBuilder(Options.emitLineDirectives()); TypePrivateDeclarationGenerator.generate(builder, typeNode); String privateDeclarationCode = builder.toString(); builder = new SourceBuilder(Options.emitLineDirectives()); TypeImplementationGenerator.generate(builder, typeNode); String implementationCode = builder.toString(); ImmutableSet.Builder<Import> implementationIncludes = ImmutableSet.builder(); implementationIncludes.addAll(privateDeclarationCollector.getSuperTypes()); implementationIncludes.addAll(importCollector.getImports()); return new GeneratedType(nameTable.getFullName(typeBinding), typeNode.hasPrivateDeclaration(), superTypes.build(), ImmutableSet.copyOf(headerCollector.getForwardDeclarations()), ImmutableSet.copyOf(headerCollector.getSuperTypes()), ImmutableSet.copyOf(privateDeclarationCollector.getForwardDeclarations()), implementationIncludes.build(), publicDeclarationCode, privateDeclarationCode, implementationCode); }
From source file:com.google.cloud.security.scanner.primitives.GCPResourcePolicyDiff.java
/** * Construct a GCPResourcePolicyDiff object from two GCPResourcePolicy objects. * * @param firstPolicy The first policy object. * @param secondPolicy The second policy object. * @return A GCPResourcePolicyDiff object that represents the difference between the two policies. *//*from ww w . jav a2 s . c om*/ public static GCPResourcePolicyDiff diff(GCPResourcePolicy firstPolicy, GCPResourcePolicy secondPolicy) { Set<PolicyBindingDelta> firstPolicyBindings = flattenBindings(firstPolicy); Set<PolicyBindingDelta> secondPolicyBindings = flattenBindings(secondPolicy); Set<PolicyBindingDelta> removedBindings = new HashSet<>(firstPolicyBindings); removedBindings.removeAll(secondPolicyBindings); Set<PolicyBindingDelta> addedBindings = new HashSet<>(secondPolicyBindings); addedBindings.removeAll(firstPolicyBindings); ImmutableList.Builder<PolicyBindingDelta> deltas = ImmutableList.builder(); for (PolicyBindingDelta delta : removedBindings) { deltas.add( new PolicyBindingDelta(delta.getRole(), delta.getMember(), PolicyBindingDelta.Action.REMOVED)); } for (PolicyBindingDelta delta : addedBindings) { deltas.add(new PolicyBindingDelta(delta.getRole(), delta.getMember(), PolicyBindingDelta.Action.ADDED)); } return new GCPResourcePolicyDiff(firstPolicy, secondPolicy, deltas.build()); }
From source file:com.facebook.presto.operator.scalar.annotations.ScalarFromAnnotationsParser.java
public static List<SqlScalarFunction> parseFunctionDefinition(Class<?> clazz) { ImmutableList.Builder<SqlScalarFunction> builder = ImmutableList.builder(); for (ScalarHeaderAndMethods scalar : findScalarsInFunctionDefinitionClass(clazz)) { builder.add(parseParametricScalar(scalar, findConstructors(clazz))); }/*from www . ja v a 2 s .c o m*/ return builder.build(); }
From source file:com.facebook.presto.tpcds.TpcdsMetadata.java
private static ConnectorTableMetadata getTableMetadata(String schemaName, Table tpcdsTable) { ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder(); for (Column column : tpcdsTable.getColumns()) { columns.add(new ColumnMetadata(column.getName(), getPrestoType(column.getType()))); }/*w w w . j a v a 2s. co m*/ SchemaTableName tableName = new SchemaTableName(schemaName, tpcdsTable.getName()); return new ConnectorTableMetadata(tableName, columns.build()); }
From source file:com.github.rinde.rinsim.examples.demo.factory.FactoryExample.java
static ImmutableList<ImmutableList<Point>> createPoints(Iterable<String> words) { final ImmutableList.Builder<ImmutableList<Point>> pointBuilder = ImmutableList.builder(); for (final String word : words) { pointBuilder.add(SwarmDemo.measureString(word, FONT_SIZE, SPACING, 2)); }//from ww w. ja v a 2s . c om return pointBuilder.build(); }
From source file:com.facebook.presto.sql.planner.LogicalPlanner.java
private static List<ColumnMetadata> getOutputTableColumns(RelationPlan plan) { ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder(); for (Field field : plan.getDescriptor().getVisibleFields()) { columns.add(new ColumnMetadata(field.getName().get(), field.getType(), false)); }/* w ww . j a v a 2 s .c o m*/ return columns.build(); }
From source file:com.facebook.buck.rust.RustCompileRule.java
static ImmutableList<String> processLinkerArgs(Iterable<String> linkerArgs) { ImmutableList.Builder<ImmutableList<String>> grouper = ImmutableList.builder(); ImmutableList.Builder<String> accum = ImmutableList.builder(); for (String arg : linkerArgs) { if (!arg.contains(" ")) { accum.add(arg); } else {//from w ww. j a va 2s. c o m grouper.add(accum.build()); accum = ImmutableList.builder(); grouper.add(ImmutableList.of(arg)); } } grouper.add(accum.build()); return grouper.build().stream().filter(g -> g.size() > 0).map(g -> { if (g.size() == 1) { return String.format("-Clink-arg=%s", g.get(0)); } else { return String.format("-Clink-args=%s", String.join(" ", g)); } }).collect(MoreCollectors.toImmutableList()); }