List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:com.google.api.tools.framework.importers.swagger.MultiSwaggerParser.java
public static List<SwaggerFile> convert(List<FileWrapper> swaggerFiles, String typeNamespace) throws SwaggerConversionException { Map<String, FileWrapper> savedFilePaths = SwaggerFileWriter.saveFilesOnDisk(swaggerFiles); Map<String, File> swaggerFilesMap = validateInputFiles(savedFilePaths); Service.Builder serviceBuilder = Service.newBuilder(); ImmutableList.Builder<SwaggerFile> swaggerObjects = ImmutableList.builder(); for (Entry<String, File> swaggerFile : swaggerFilesMap.entrySet()) { swaggerObjects.add( buildSwaggerFile(serviceBuilder, swaggerFile.getKey(), swaggerFile.getValue(), typeNamespace)); }/*from w ww. ja v a 2s. c o m*/ return swaggerObjects.build(); }
From source file:org.apache.tajo.schema.QualifiedIdentifier.java
/** * It takes interned strings. It assumes all parameters already stripped. It is used only for tests. * @param names interned strings/*from ww w .ja v a 2 s. co m*/ * @return QualifiedIdentifier */ @VisibleForTesting public static QualifiedIdentifier $(String... names) { final ImmutableList.Builder<Identifier> builder = ImmutableList.builder(); for (String n : names) { for (String split : n.split(StringUtils.escapeRegexp("" + DefaultPolicy().getIdentifierSeperator()))) { builder.add(Identifier._(split, IdentifierUtil.isShouldBeQuoted(split))); } } return new QualifiedIdentifier(builder.build()); }
From source file:org.tearsinrain.fasttuple.generate.Config.java
public static ImmutableList<Config> all(int size) { ImmutableList.Builder<Config> builder = ImmutableList.builder(); boolean[] all = { true, false }; for (boolean nullable : all) { for (boolean comparable : all) { for (boolean serializable : all) { builder.add(new Config(nullable, comparable, serializable, size)); }// www . j av a 2s. c o m } } return builder.build(); }
From source file:io.prestosql.operator.scalar.ArrayConstructor.java
private static Class<?> generateArrayConstructor(List<Class<?>> stackTypes, Type elementType) { checkCondition(stackTypes.size() <= 254, NOT_SUPPORTED, "Too many arguments for array constructor"); List<String> stackTypeNames = stackTypes.stream().map(Class::getSimpleName).collect(toImmutableList()); ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName(Joiner.on("").join(stackTypeNames) + "ArrayConstructor"), type(Object.class)); // Generate constructor definition.declareDefaultConstructor(a(PRIVATE)); // Generate arrayConstructor() ImmutableList.Builder<Parameter> parameters = ImmutableList.builder(); for (int i = 0; i < stackTypes.size(); i++) { Class<?> stackType = stackTypes.get(i); parameters.add(arg("arg" + i, stackType)); }//from w w w. ja v a2 s . c o m MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "arrayConstructor", type(Block.class), parameters.build()); Scope scope = method.getScope(); BytecodeBlock body = method.getBody(); Variable blockBuilderVariable = scope.declareVariable(BlockBuilder.class, "blockBuilder"); CallSiteBinder binder = new CallSiteBinder(); BytecodeExpression createBlockBuilder = blockBuilderVariable .set(constantType(binder, elementType).invoke("createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(stackTypes.size()))); body.append(createBlockBuilder); for (int i = 0; i < stackTypes.size(); i++) { Variable argument = scope.getVariable("arg" + i); IfStatement ifStatement = new IfStatement().condition(equal(argument, constantNull(stackTypes.get(i)))) .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType()))); body.append(ifStatement); } body.append(blockBuilderVariable.invoke("build", Block.class).ret()); return defineClass(definition, Object.class, binder.getBindings(), new DynamicClassLoader(ArrayConstructor.class.getClassLoader())); }
From source file:com.google.errorprone.scanner.ScannerSupplier.java
/** * Returns a {@link ScannerSupplier} with a specific list of {@link BugChecker} classes. *//*from w w w . j a v a 2s . c o m*/ public static ScannerSupplier fromBugCheckerClasses(Iterable<Class<? extends BugChecker>> checkers) { ImmutableList.Builder<BugCheckerInfo> builder = ImmutableList.builder(); for (Class<? extends BugChecker> checker : checkers) { builder.add(BugCheckerInfo.create(checker)); } return fromBugCheckerInfos(builder.build()); }
From source file:net.hydromatic.tpcds.TpcdsTable.java
private static <E extends TpcdsEntity> TpcdsTable<E> dummy(String name, final String prefix, Class<E> clazz) { ImmutableList.Builder<TpcdsColumn> columns = ImmutableList.builder(); for (final Field field : clazz.getFields()) { columns.add(new TpcdsColumn() { public String getString(Object o) { throw new UnsupportedOperationException(); }//from w w w .j a v a2s . c o m public double getDouble(Object o) { throw new UnsupportedOperationException(); } public long getLong(Object o) { throw new UnsupportedOperationException(); } public String getColumnName() { return prefix + "_" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, field.getName()); } public Class<?> getType() { return field.getType(); } }); } return new TpcdsTable<E>(name, prefix, columns.build()) { @Override public Iterable<E> createGenerator(double scaleFactor, int part, int partCount) { return ImmutableList.of(); } @Override public void builder(Dsgen dsgen) { } @Override public void loader1() { } @Override public void loader2() { } @Override public void validate(int nTable, long kRow, int[] permutation) { } }; }
From source file:com.netflix.metacat.common.type.RowType.java
/** * Create a new Row Type.//w ww . j a v a 2s. c o m * * @param types The types to create can not be empty * @param names The literals to use. Can be null but if not must be the same length as types. * @return a new RowType */ public static RowType createRowType(@Nonnull @NonNull final List<Type> types, @Nonnull @NonNull final List<String> names) { Preconditions.checkArgument(!types.isEmpty(), "types is empty"); final ImmutableList.Builder<RowField> builder = ImmutableList.builder(); Preconditions.checkArgument(types.size() == names.size(), "types and names must be matched in size"); for (int i = 0; i < types.size(); i++) { builder.add(new RowField(types.get(i), names.get(i))); } return new RowType(builder.build()); }
From source file:com.google.api.codegen.FlatteningConfig.java
/** * Creates an instance of FlatteningConfig based on FlatteningConfigProto, linking it up with the * provided method.//from w w w . j a va 2 s. c o m */ @Nullable public static FlatteningConfig createFlattening(DiagCollector diagCollector, FlatteningConfigProto flattening, Method method) { boolean missing = false; ImmutableList.Builder<ImmutableList<Field>> flatteningGroupsBuilder = ImmutableList.builder(); for (FlatteningGroupProto flatteningGroup : flattening.getGroupsList()) { ImmutableList.Builder<Field> parametersBuilder = ImmutableList.builder(); for (String parameter : flatteningGroup.getParametersList()) { Field parameterField = method.getInputMessage().lookupField(parameter); if (parameterField != null) { parametersBuilder.add(parameterField); } else { diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Field missing for flattening: method = %s, message type = %s, field = %s", method.getFullName(), method.getInputMessage().getFullName(), parameter)); missing = true; } } flatteningGroupsBuilder.add(parametersBuilder.build()); } if (missing) { return null; } return new FlatteningConfig(flatteningGroupsBuilder.build()); }
From source file:com.facebook.presto.operator.scalar.ArrayConstructor.java
private static Class<?> generateArrayConstructor(List<Class<?>> stackTypes, Type elementType) { List<String> stackTypeNames = stackTypes.stream().map(Class::getSimpleName).collect(toImmutableList()); ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), CompilerUtils.makeClassName(Joiner.on("").join(stackTypeNames) + "ArrayConstructor"), type(Object.class)); // Generate constructor definition.declareDefaultConstructor(a(PRIVATE)); // Generate arrayConstructor() ImmutableList.Builder<Parameter> parameters = ImmutableList.builder(); for (int i = 0; i < stackTypes.size(); i++) { Class<?> stackType = stackTypes.get(i); parameters.add(arg("arg" + i, stackType)); }// w ww .j a va2s. com MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "arrayConstructor", type(Block.class), parameters.build()); Scope scope = method.getScope(); ByteCodeBlock body = method.getBody(); Variable blockBuilderVariable = scope.declareVariable(BlockBuilder.class, "blockBuilder"); CallSiteBinder binder = new CallSiteBinder(); ByteCodeExpression createBlockBuilder = blockBuilderVariable .set(constantType(binder, elementType).invoke("createBlockBuilder", BlockBuilder.class, newInstance(BlockBuilderStatus.class), constantInt(stackTypes.size()))); body.append(createBlockBuilder); for (int i = 0; i < stackTypes.size(); i++) { if (elementType.getJavaType() == void.class) { body.append(blockBuilderVariable.invoke("appendNull", BlockBuilder.class)); } else { Variable argument = scope.getVariable("arg" + i); IfStatement ifStatement = new IfStatement() .condition(equal(argument, constantNull(stackTypes.get(i)))) .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType()))); body.append(ifStatement); } } body.append(blockBuilderVariable.invoke("build", Block.class).ret()); return defineClass(definition, Object.class, binder.getBindings(), new DynamicClassLoader(ArrayConstructor.class.getClassLoader())); }
From source file:org.sonar.plugins.stylecop.StyleCopSettingsWriter.java
private static List<String> ruleKeys(String ruleNamespace, List<String> ruleConfigKeys) { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (String ruleConfigKey : ruleConfigKeys) { if (ruleConfigKey.startsWith(ruleNamespace)) { String ruleKey = ruleConfigKey.substring(ruleNamespace.length() + 1); builder.add(ruleKey); }//w ww. j a va 2 s.c om } return builder.build(); }