List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:org.kmworks.util.cp.CodepointSetUtil.java
public static List<Integer> codepointsFrom(CharSequence s) { ImmutableList.Builder<Integer> builder = new ImmutableList.Builder<>(); int i = 0;/* ww w. ja v a2 s . c o m*/ while (i < s.length()) { builder.add((int) s.charAt(i)); i += Character.charCount(i); } return builder.build(); }
From source file:com.google.devtools.moe.client.repositories.Revision.java
/** * Return the list of Revisions given by a RepositoryExpression like "internal(revision=3,4,5)". *//*from ww w . jav a2s . co m*/ public static List<Revision> fromRepositoryExpression(RepositoryExpression repoEx, ProjectContext context) { RepositoryType repo = context.getRepository(repoEx.getRepositoryName()); if (Strings.isNullOrEmpty(repoEx.getOption("revision"))) { throw new MoeProblem( "Repository expression must have a 'revision' option, e.g. internal(revision=3,4,5)."); } RevisionHistory rh = repo.revisionHistory(); ImmutableList.Builder<Revision> revBuilder = ImmutableList.builder(); for (String revId : repoEx.getOption("revision").split(",")) { revBuilder.add(rh.findHighestRevision(revId)); } return revBuilder.build(); }
From source file:com.facebook.buck.cli.AuditModulesCommand.java
private static ImmutableList<AuditModuleInformation> collectModuleInformation(BuckModuleManager moduleManager) { ImmutableList.Builder<AuditModuleInformation> modules = ImmutableList.builder(); for (String moduleId : moduleManager.getModuleIds()) { modules.add(new AuditModuleInformation(moduleId, moduleManager.getModuleHash(moduleId), moduleManager.getModuleDependencies(moduleId))); }/*from w ww . j ava 2 s. c o m*/ return modules.build(); }
From source file:org.sonar.plugins.jacoco.JacocoConfiguration.java
public static List<PropertyDefinition> getPropertyDefinitions(Version sonarQubeVersion) { String subCategory = "JaCoCo"; ImmutableList.Builder<PropertyDefinition> properties = ImmutableList.builder(); if (sonarQubeVersion.isGreaterThanOrEqual(SQ_6_2)) { properties.add(PropertyDefinition.builder(JacocoConfiguration.REPORT_PATHS_PROPERTY) .defaultValue(JacocoConfiguration.REPORT_PATHS_DEFAULT_VALUE) .category(JavaConstants.JAVA_CATEGORY).subCategory(subCategory).name("JaCoCo Reports") .description(/*from www . jav a 2s .c om*/ "Path to the JaCoCo report files containing coverage data by unit tests. The path may be absolute or relative to the project base directory.") .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE).build()); } else { properties.add(PropertyDefinition.builder(JacocoConfiguration.REPORT_PATH_PROPERTY) .defaultValue(JacocoConfiguration.REPORT_PATH_DEFAULT_VALUE) .category(JavaConstants.JAVA_CATEGORY).subCategory(subCategory).name("UT JaCoCo Report") .description( "Path to the JaCoCo report file containing coverage data by unit tests. The path may be absolute or relative to the project base directory.") .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE).build(), PropertyDefinition.builder(JacocoConfiguration.IT_REPORT_PATH_PROPERTY) .defaultValue(JacocoConfiguration.IT_REPORT_PATH_DEFAULT_VALUE) .category(JavaConstants.JAVA_CATEGORY).subCategory(subCategory).name("IT JaCoCo Report") .description( "Path to the JaCoCo report file containing coverage data by integration tests. The path may be absolute or relative to the project base directory.") .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE).build(), PropertyDefinition.builder(JacocoConfiguration.REPORT_MISSING_FORCE_ZERO) .defaultValue( Boolean.toString(JacocoConfiguration.REPORT_MISSING_FORCE_ZERO_DEFAULT_VALUE)) .name("Force zero coverage").category(JavaConstants.JAVA_CATEGORY) .subCategory(subCategory) .description("Force coverage to 0% if no JaCoCo reports are found during analysis.") .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE).type(PropertyType.BOOLEAN) .build()); } return properties.build(); }
From source file:org.apache.beam.sdk.io.gcp.bigquery.WriteTables.java
static void removeTemporaryFiles(Collection<String> files) throws IOException { ImmutableList.Builder<ResourceId> fileResources = ImmutableList.builder(); for (String file : files) { fileResources.add(FileSystems.matchNewResource(file, false/* isDirectory */)); }/*from w w w . jav a 2s . co m*/ FileSystems.delete(fileResources.build(), MoveOptions.StandardMoveOptions.IGNORE_MISSING_FILES); }
From source file:ec.tss.tsproviders.odbc.registry.JnaOdbcRegistry.java
static ImmutableList<String> readFileExtns(Object obj) { String input = toString(obj); if (input == null) { return ImmutableList.of(); }//w w w .j a v a 2s. co m ImmutableList.Builder<String> builder = ImmutableList.builder(); for (String o : EXTNS_SPLITTER.split(input)) { builder.add(Files.getFileExtension(o)); } return builder.build(); }
From source file:org.apache.arrow.vector.types.pojo.Schema.java
public static Schema convertSchema(org.apache.arrow.flatbuf.Schema schema) { ImmutableList.Builder<Field> childrenBuilder = ImmutableList.builder(); for (int i = 0; i < schema.fieldsLength(); i++) { childrenBuilder.add(convertField(schema.fields(i))); }/*from w ww . ja va 2 s . co m*/ List<Field> fields = childrenBuilder.build(); return new Schema(fields); }
From source file:com.google.javascript.refactoring.testing.RefasterJsTestUtils.java
/** * Performs refactoring using a RefasterJs template and asserts that result is as expected. * * @param refasterJsTemplate path of the file or resource containing the RefasterJs template to * apply/*from w ww . j a va 2 s . c o m*/ * @param testDataPathPrefix path prefix of the directory from which input and expected-output * file will be read * @param originalFile file name of the JavaScript source file to apply the refaster template to * @param additionalSourceFiles list of additional source files to provide to the compiler (e.g. * dependencies) * @param expectedFileChoices the expected result options of applying the specified template to * {@code originalFile} * @throws IOException */ public static void assertFileRefactoring(String refasterJsTemplate, String testDataPathPrefix, String originalFile, List<String> additionalSourceFiles, String... expectedFileChoices) throws IOException { RefasterJsScanner scanner = new RefasterJsScanner(); scanner.loadRefasterJsTemplate(refasterJsTemplate); final String originalFilePath = testDataPathPrefix + File.separator + originalFile; ImmutableList.Builder<String> expectedCodeBuilder = ImmutableList.builder(); for (String expectedFile : expectedFileChoices) { expectedCodeBuilder.add(slurpFile(testDataPathPrefix + File.separator + expectedFile)); } final ImmutableList<String> expectedCode = expectedCodeBuilder.build(); RefactoringDriver.Builder driverBuilder = new RefactoringDriver.Builder() .addExterns(CommandLineRunner.getBuiltinExterns(CompilerOptions.Environment.BROWSER)); for (String additionalSource : additionalSourceFiles) { driverBuilder.addInputsFromFile(testDataPathPrefix + File.separator + additionalSource); } RefactoringDriver driver = driverBuilder.addInputsFromFile(originalFilePath).build(); List<SuggestedFix> fixes = driver.drive(scanner); assertThat(driver.getCompiler().getErrors()).isEmpty(); assertThat(driver.getCompiler().getWarnings()).isEmpty(); ImmutableList<String> newCode = ApplySuggestedFixes .applyAllSuggestedFixChoicesToCode(fixes, ImmutableMap.of(originalFilePath, slurpFile(originalFilePath))) .stream().map(m -> m.get(originalFilePath)).collect(ImmutableList.toImmutableList()); assertThat(newCode).comparingElementsUsing(new IgnoringWhitespaceCorrespondence()) .containsExactlyElementsIn(expectedCode); }
From source file:com.spectralogic.ds3autogen.net.generators.typemodels.BaseTypeGenerator.java
/** * Converts a list of Ds3EnumConstants to a list of Enum Constants *///from ww w.jav a2 s. com protected static ImmutableList<EnumConstant> getEnumConstantsList( final ImmutableList<Ds3EnumConstant> ds3EnumConstants) { if (isEmpty(ds3EnumConstants)) { return ImmutableList.of(); } final ImmutableList.Builder<EnumConstant> builder = ImmutableList.builder(); for (final Ds3EnumConstant ds3EnumConstant : ds3EnumConstants) { builder.add(new EnumConstant(ds3EnumConstant.getName())); } return builder.build(); }
From source file:com.facebook.presto.sql.gen.VarArgsToArrayAdapterGenerator.java
public static MethodHandleAndConstructor generateVarArgsToArrayAdapter(Class<?> returnType, Class<?> javaType, int argsLength, MethodHandle function, MethodHandle userStateFactory) { requireNonNull(returnType, "returnType is null"); requireNonNull(javaType, "javaType is null"); requireNonNull(function, "function is null"); requireNonNull(userStateFactory, "userStateFactory is null"); MethodType methodType = function.type(); Class<?> javaArrayType = toArrayClass(javaType); checkArgument(methodType.returnType() == returnType, "returnType does not match"); checkArgument(methodType.parameterList().equals(ImmutableList.of(Object.class, javaArrayType)), "parameter types do not match"); CallSiteBinder callSiteBinder = new CallSiteBinder(); ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("VarArgsToListAdapter"), type(Object.class)); classDefinition.declareDefaultConstructor(a(PRIVATE)); // generate userState constructor MethodDefinition stateFactoryDefinition = classDefinition.declareMethod(a(PUBLIC, STATIC), "createState", type(VarArgsToArrayAdapterState.class)); stateFactoryDefinition.getBody().comment("create userState for current instance").append(newInstance( VarArgsToArrayAdapterState.class, loadConstant(callSiteBinder, userStateFactory, MethodHandle.class) .invoke("invokeExact", Object.class), newArray(type(javaArrayType), argsLength).cast(Object.class)).ret()); // generate adapter method ImmutableList.Builder<Parameter> parameterListBuilder = ImmutableList.builder(); parameterListBuilder.add(arg("userState", VarArgsToArrayAdapterState.class)); for (int i = 0; i < argsLength; i++) { parameterListBuilder.add(arg("input_" + i, javaType)); }/* ww w . j av a2s . com*/ ImmutableList<Parameter> parameterList = parameterListBuilder.build(); MethodDefinition methodDefinition = classDefinition.declareMethod(a(PUBLIC, STATIC), "varArgsToArray", type(returnType), parameterList); BytecodeBlock body = methodDefinition.getBody(); BytecodeExpression userState = parameterList.get(0).getField("userState", Object.class); BytecodeExpression args = parameterList.get(0).getField("args", Object.class).cast(javaArrayType); for (int i = 0; i < argsLength; i++) { body.append(args.setElement(i, parameterList.get(i + 1))); } body.append(loadConstant(callSiteBinder, function, MethodHandle.class) .invoke("invokeExact", returnType, userState, args).ret()); // define class Class<?> generatedClass = defineClass(classDefinition, Object.class, callSiteBinder.getBindings(), VarArgsToArrayAdapterGenerator.class.getClassLoader()); return new MethodHandleAndConstructor( Reflection.methodHandle(generatedClass, "varArgsToArray", ImmutableList.builder().add(VarArgsToArrayAdapterState.class) .addAll(nCopies(argsLength, javaType)).build().toArray(new Class<?>[argsLength])), Reflection.methodHandle(generatedClass, "createState")); }