List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:com.facebook.presto.operator.PartitionGenerator.java
static PartitionGenerator createHashPartitionGenerator(Optional<Integer> hashChannel, List<Integer> partitioningChannels, List<Type> types) { if (hashChannel.isPresent()) { return new PrecomputedHashGenerator(hashChannel.get()); }/*from w ww . j a va 2s. c o m*/ ImmutableList.Builder<Type> hashTypes = ImmutableList.builder(); int[] hashChannels = new int[partitioningChannels.size()]; for (int i = 0; i < partitioningChannels.size(); i++) { int channel = partitioningChannels.get(i); hashTypes.add(types.get(channel)); hashChannels[i] = channel; } return new InterpretedHashGenerator(hashTypes.build(), hashChannels); }
From source file:com.facebook.presto.sql.gen.VarArgsToMapAdapterGenerator.java
/** * Generate byte code that/* w ww .j a v a2 s . com*/ * <p><ul> * <li>takes a specified number of variables as arguments (types of the arguments are provided in {@code javaTypes}) * <li>put the variables in a map (keys of the map are provided in {@code names}) * <li>invoke the provided {@code function} with the map * <li>return with the result of the function call (type must match {@code returnType}) * </ul></p> */ public static MethodHandle generateVarArgsToMapAdapter(Class<?> returnType, List<Class<?>> javaTypes, List<String> names, Function<Map<String, Object>, Object> function) { CallSiteBinder callSiteBinder = new CallSiteBinder(); ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("VarArgsToMapAdapter"), type(Object.class)); ImmutableList.Builder<Parameter> parameterListBuilder = ImmutableList.builder(); for (int i = 0; i < javaTypes.size(); i++) { Class<?> javaType = javaTypes.get(i); parameterListBuilder.add(arg("input_" + i, javaType)); } ImmutableList<Parameter> parameterList = parameterListBuilder.build(); MethodDefinition methodDefinition = classDefinition.declareMethod(a(PUBLIC, STATIC), "varArgsToMap", type(returnType), parameterList); BytecodeBlock body = methodDefinition.getBody(); // ImmutableMap.Builder can not be used here because it doesn't allow nulls. Variable map = methodDefinition.getScope().declareVariable("map", methodDefinition.getBody(), invokeStatic( Maps.class, "newHashMapWithExpectedSize", HashMap.class, constantInt(javaTypes.size()))); for (int i = 0; i < javaTypes.size(); i++) { body.append(map.invoke("put", Object.class, constantString(names.get(i)).cast(Object.class), parameterList.get(i).cast(Object.class))); } body.append(loadConstant(callSiteBinder, function, Function.class) .invoke("apply", Object.class, map.cast(Object.class)).cast(returnType).ret()); Class<?> generatedClass = defineClass(classDefinition, Object.class, callSiteBinder.getBindings(), new DynamicClassLoader(VarArgsToMapAdapterGenerator.class.getClassLoader())); return Reflection.methodHandle(generatedClass, "varArgsToMap", javaTypes.toArray(new Class<?>[javaTypes.size()])); }
From source file:org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.java
private static ImmutableList<ImplementationSnapshot> collectActionImplementations( Collection<ContextAwareTaskAction> taskActions, ClassLoaderHierarchyHasher classLoaderHierarchyHasher) { if (taskActions.isEmpty()) { return ImmutableList.of(); }//from w w w . ja v a 2s.c o m ImmutableList.Builder<ImplementationSnapshot> actionImplementations = ImmutableList.builder(); for (ContextAwareTaskAction taskAction : taskActions) { actionImplementations.add(taskAction.getActionImplementation(classLoaderHierarchyHasher)); } return actionImplementations.build(); }
From source file:org.sonar.java.model.expression.NewClassTreeImpl.java
private static void addIfNotNull(ImmutableList.Builder<Tree> builder, Tree... trees) { for (Tree tree : trees) { if (tree != null) { builder.add(tree); }// ww w . ja v a2 s . c om } }
From source file:com.spectralogic.ds3autogen.net.generators.parsers.typeset.BaseTypeParserSetGenerator.java
/** * Retrieves the list of enum type names from within a Ds3Types list *//*from ww w .j a v a2 s . co m*/ protected static ImmutableList<String> toEnumList(final ImmutableMap<String, Ds3Type> typeMap) { if (isEmpty(typeMap)) { return ImmutableList.of(); } final ImmutableList.Builder<String> builder = ImmutableList.builder(); for (final Ds3Type ds3Type : typeMap.values().asList()) { if (isEnum(ds3Type) && !isChecksumType(ds3Type)) { builder.add(removePath(ds3Type.getName())); } } return builder.build(); }
From source file:com.spectralogic.ds3autogen.net.generators.requestmodels.BaseRequestGenerator.java
/** * Splits a constructor in two if the original constructor contains a parameter of type Guid *//*from ww w . j a v a 2 s . c o m*/ protected static ImmutableList<RequestConstructor> splitGuidConstructor(final RequestConstructor constructor) { final ImmutableList.Builder<RequestConstructor> builder = ImmutableList.builder(); builder.add(constructor); if (!containsType(constructor.getConstructorArgs(), "UUID")) { return builder.build(); } builder.add(convertGuidToStringConstructor(constructor)); return builder.build(); }
From source file:com.facebook.buck.json.BuildFilePythonResultDeserializer.java
private static List<Object> deserializeList(JsonParser jp) throws IOException { ImmutableList.Builder<Object> builder = ImmutableList.builder(); JsonToken token;/*from www.j av a 2 s . c om*/ while ((token = jp.nextToken()) != JsonToken.END_ARRAY) { builder.add(deserializeRecursive(jp, token)); } if (token != JsonToken.END_ARRAY) { throw new JsonParseException(jp, "Missing expected END_ARRAY"); } return builder.build(); }
From source file:com.google.devtools.build.lib.rules.objc.BundleableFile.java
/** * Returns bundle files for each given strings file. These are used to merge the strings files to * the final application bundle.//from ww w .ja v a 2 s . c o m */ public static Iterable<BundleFile> toBundleFiles(Iterable<BundleableFile> files) { ImmutableList.Builder<BundleFile> result = new ImmutableList.Builder<>(); for (BundleableFile file : files) { result.add(BundleFile.newBuilder().setBundlePath(file.bundlePath) .setSourceFile(file.bundled.getExecPathString()) .setExternalFileAttribute(file.zipExternalFileAttribute).build()); } return result.build(); }
From source file:com.facebook.presto.client.FailureInfo.java
private static FailureException toException(FailureInfo failureInfo) { if (failureInfo == null) { return null; }//w w w.ja va 2 s .com FailureException failure = new FailureException(failureInfo.getType(), failureInfo.getMessage(), toException(failureInfo.getCause())); for (FailureInfo suppressed : failureInfo.getSuppressed()) { failure.addSuppressed(toException(suppressed)); } ImmutableList.Builder<StackTraceElement> stackTraceBuilder = ImmutableList.builder(); for (String stack : failureInfo.getStack()) { stackTraceBuilder.add(toStackTraceElement(stack)); } ImmutableList<StackTraceElement> stackTrace = stackTraceBuilder.build(); failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); return failure; }
From source file:com.android.utils.StringHelper.java
/** * Returns a list of Strings containing the objects passed in argument. * * If the objects are strings, they are directly added to the list. * If the objects are collections of strings, the strings are added. * For other objects, the result of their toString() is added. * @param objects the objects to add/*from w w w . j a v a2 s . c o m*/ * @return the list of objects. */ @NonNull public static List<String> toStrings(@NonNull Object... objects) { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (Object path : objects) { if (path instanceof String) { builder.add((String) path); } else if (path instanceof Collection) { Collection pathCollection = (Collection) path; for (Object item : pathCollection) { if (item instanceof String) { builder.add((String) item); } else { builder.add(path.toString()); } } } else { builder.add(path.toString()); } } return builder.build(); }