List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:com.facebook.buck.rules.args.FileListableLinkerInputArg.java
public static ImmutableList<Arg> from(ImmutableList<SourcePathArg> values) { ImmutableList.Builder<Arg> converted = ImmutableList.builder(); for (SourcePathArg arg : values) { converted.add(withSourcePathArg(arg)); }//from w w w . j a va 2 s . c om return converted.build(); }
From source file:com.spotify.helios.testing.CapturingAppender.java
private CapturingAppender(final ImmutableList.Builder<ILoggingEvent> eventsBuilder) { this.eventsBuilder = eventsBuilder; }
From source file:org.ratpackframework.guice.internal.GuiceUtil.java
public static <T> ImmutableList<T> ofType(Injector injector, TypeLiteral<T> type) { final ImmutableList.Builder<T> listBuilder = ImmutableList.builder(); eachOfType(injector, type, new Action<T>() { public void execute(T thing) { listBuilder.add(thing);/* w w w .j av a2 s .com*/ } }); return listBuilder.build(); }
From source file:com.facebook.buck.plugin.intellij.commands.TargetsCommand.java
public static ImmutableList<BuckTarget> getTargets(BuckRunner buckRunner) { try {/*from w w w .jav a 2 s .co m*/ int exitCode = buckRunner.execute("targets", "--json"); if (exitCode != 0) { throw new RuntimeException(buckRunner.getStderr()); } // Parse output ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getJsonFactory(); JsonParser parser = factory.createJsonParser(buckRunner.getStdout()); JsonNode jsonNode = mapper.readTree(parser); if (!jsonNode.isArray()) { throw new IllegalStateException(); } ImmutableList.Builder<BuckTarget> builder = ImmutableList.builder(); for (JsonNode target : jsonNode) { if (!target.isObject()) { throw new IllegalStateException(); } String basePath = target.get("buck.base_path").asText(); String name = target.get("name").asText(); String type = target.get("type").asText(); builder.add(new BuckTarget(type, name, basePath)); } return builder.build(); } catch (IOException e) { LOG.error(e); } catch (RuntimeException e) { LOG.error(e); } return ImmutableList.of(); }
From source file:com.google.debugging.sourcemap.SourceMapObjectParser.java
public static SourceMapObject parse(String contents) throws SourceMapParseException { SourceMapObject.Builder builder = SourceMapObject.builder(); try {//from w w w .j a va 2 s .co m JsonObject sourceMapRoot = new Gson().fromJson(contents, JsonObject.class); builder.setVersion(sourceMapRoot.get("version").getAsInt()); builder.setFile(getStringOrNull(sourceMapRoot, "file")); builder.setLineCount(sourceMapRoot.has("lineCount") ? sourceMapRoot.get("lineCount").getAsInt() : -1); builder.setMappings(getStringOrNull(sourceMapRoot, "mappings")); builder.setSourceRoot(getStringOrNull(sourceMapRoot, "sourceRoot")); if (sourceMapRoot.has("sections")) { ImmutableList.Builder<SourceMapSection> listBuilder = ImmutableList.builder(); for (JsonElement each : sourceMapRoot.get("sections").getAsJsonArray()) { listBuilder.add(buildSection(each.getAsJsonObject())); } builder.setSections(listBuilder.build()); } builder.setSources(getJavaStringArray(sourceMapRoot.get("sources"))); builder.setSourcesContent(getJavaStringArray(sourceMapRoot.get("sourcesContent"))); builder.setNames(getJavaStringArray(sourceMapRoot.get("names"))); Map<String, Object> extensions = new LinkedHashMap<>(); for (Map.Entry<String, JsonElement> entry : sourceMapRoot.entrySet()) { if (entry.getKey().startsWith("x_")) { extensions.put(entry.getKey(), entry.getValue()); } } builder.setExtensions(Collections.unmodifiableMap(extensions)); } catch (JsonParseException ex) { throw new SourceMapParseException("JSON parse exception: " + ex); } return builder.build(); }
From source file:org.smartdeveloperhub.vocabulary.util.Serializations.java
public static List<Path> generate(final Module module, final Path where) throws IOException { final SerializationManager manager = SerializationManager.create(module, where); final Builder<Path> builder = ImmutableList.builder(); collectModuleSerializations(builder, manager, module); return builder.build(); }
From source file:com.google.template.soy.conformance.ValidatedConformanceConfig.java
/** * Creates a validated configuration object. * * @throws IllegalArgumentException if there is an error in the config object. *//*from www. jav a 2 s . c o m*/ public static ValidatedConformanceConfig create(ConformanceConfig config) { ImmutableList.Builder<RuleWithWhitelists> rulesBuilder = new ImmutableList.Builder<>(); for (Requirement requirement : config.getRequirementList()) { Preconditions.checkArgument(!requirement.getErrorMessage().isEmpty(), "requirement missing error message"); Preconditions.checkArgument( requirement.getRequirementTypeCase() != RequirementTypeCase.REQUIREMENTTYPE_NOT_SET, "requirement missing type"); Rule<? extends Node> rule = forRequirement(requirement); ImmutableList<String> whitelists = ImmutableList.copyOf(requirement.getWhitelistList()); ImmutableList<String> onlyApplyToPaths = ImmutableList.copyOf(requirement.getOnlyApplyToList()); rulesBuilder.add(RuleWithWhitelists.create(rule, whitelists, onlyApplyToPaths)); } return new ValidatedConformanceConfig(rulesBuilder.build()); }
From source file:com.facebook.buck.jvm.java.JavaPaths.java
/** * Processes a list of java source files, extracting and SRC_ZIP or SRC_JAR to the working * directory and returns a list of all the resulting .java files. *//* www . j a v a2 s. co m*/ static ImmutableList<Path> extractArchivesAndGetPaths(ProjectFilesystem projectFilesystem, ProjectFilesystemFactory projectFilesystemFactory, ImmutableSet<Path> javaSourceFilePaths, Path workingDirectory) throws InterruptedException, IOException { // Add sources file or sources list to command ImmutableList.Builder<Path> sources = ImmutableList.builder(); for (Path path : javaSourceFilePaths) { String pathString = path.toString(); if (pathString.endsWith(".java")) { sources.add(path); } else if (pathString.endsWith(SRC_ZIP) || pathString.endsWith(SRC_JAR)) { // For a Zip of .java files, create a JavaFileObject for each .java entry. ImmutableList<Path> zipPaths = ArchiveFormat.ZIP.getUnarchiver().extractArchive( projectFilesystemFactory, projectFilesystem.resolve(path), projectFilesystem.resolve(workingDirectory), ExistingFileMode.OVERWRITE); sources.addAll(zipPaths.stream().filter(input -> input.toString().endsWith(".java")).iterator()); } } return sources.build(); }
From source file:io.prestosql.execution.buffer.PageSplitterUtil.java
private static List<Page> splitPage(Page page, long maxPageSizeInBytes, long previousPageSize) { checkArgument(page.getPositionCount() > 0, "page is empty"); checkArgument(maxPageSizeInBytes > 0, "maxPageSizeInBytes must be > 0"); // for Pages with certain types of Blocks (e.g., RLE blocks) the size in bytes may remain constant // through the recursive calls, which causes the recursion to only terminate when page.getPositionCount() == 1 // and create potentially a large number of Page's of size 1. So we check here that // if the size of the page doesn't improve from the previous call we terminate the recursion. if (page.getSizeInBytes() == previousPageSize || page.getSizeInBytes() <= maxPageSizeInBytes || page.getPositionCount() == 1) { return ImmutableList.of(page); }//from ww w . j a v a 2 s. c o m ImmutableList.Builder<Page> outputPages = ImmutableList.builder(); long previousSize = page.getSizeInBytes(); int positionCount = page.getPositionCount(); int half = positionCount / 2; Page leftHalf = page.getRegion(0, half); outputPages.addAll(splitPage(leftHalf, maxPageSizeInBytes, previousSize)); Page rightHalf = page.getRegion(half, positionCount - half); outputPages.addAll(splitPage(rightHalf, maxPageSizeInBytes, previousSize)); return outputPages.build(); }
From source file:com.netflix.servo.annotations.AnnotationUtils.java
/** Return the list of fields/methods annotated with {@link Monitor}. */ public static List<AnnotatedAttribute> getMonitoredAttributes(Object obj) { List<AccessibleObject> fields = getAnnotatedFields(Monitor.class, obj, Integer.MAX_VALUE); ImmutableList.Builder<AnnotatedAttribute> attrs = ImmutableList.builder(); for (AccessibleObject field : fields) { Monitor m = field.getAnnotation(Monitor.class); attrs.add(new AnnotatedAttribute(obj, m, field)); }//from www . ja v a 2s .c o m return attrs.build(); }