List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:org.trancecode.asciidoc.Archives.java
public static Iterable<File> unzip(final File archive, final File targetDirectory) { // TODO preconditions try {/*www . ja v a2 s . c om*/ final ImmutableList.Builder<File> extractedFiles = ImmutableList.builder(); final ZipFile zipFile = new ZipFile(archive); for (final Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) { final ZipEntry entry = e.nextElement(); extractedFiles.add(unzipEntry(zipFile, entry, targetDirectory)); } return extractedFiles.build(); } catch (final IOException e) { throw new IllegalStateException(String.format("cannot unzip %s to %s", archive, targetDirectory), e); } }
From source file:com.facebook.buck.features.ocaml.OcamlDescriptionEnhancer.java
public static ImmutableList<Arg> toStringWithMacrosArgs(BuildTarget target, CellPathResolver cellPathResolver, ActionGraphBuilder graphBuilder, Iterable<StringWithMacros> flags) { ImmutableList.Builder<Arg> args = ImmutableList.builder(); StringWithMacrosConverter macrosConverter = StringWithMacrosConverter.of(target, cellPathResolver, ImmutableList.of(new LocationMacroExpander(), new ExecutableMacroExpander())); for (StringWithMacros flag : flags) { args.add(macrosConverter.convert(flag, graphBuilder)); }/* ww w . j a va 2 s .c om*/ return args.build(); }
From source file:com.google.template.soy.jssrc.dsl.ObjectLiteral.java
static ObjectLiteral create(ImmutableList<? extends Expression> keys, ImmutableList<? extends Expression> values) { Preconditions.checkArgument(keys.size() == values.size(), "Mismatch between keys and values."); ImmutableList.Builder<Statement> initialStatements = ImmutableList.builder(); for (Expression key : keys) { initialStatements.addAll(key.initialStatements()); }//from w w w .java 2 s. c o m for (Expression value : values) { initialStatements.addAll(value.initialStatements()); } return new AutoValue_ObjectLiteral(initialStatements.build(), keys, values); }
From source file:org.caleydo.view.crossword.api.ui.layout.GraphFunctions.java
/** * return the children of this parent {@link IGraphVertex} * * @param parent// w w w.j a v a2 s .co m * @return */ public static final ImmutableCollection<IGraphVertex> getChildren(IGraphVertex parent) { ImmutableList.Builder<IGraphVertex> children = ImmutableList.builder(); for (IGraphEdge edge : parent.getEdges()) { if (edge.getType() == EEdgeType.PARENT_CHILD && edge.getSource() == parent) children.add(edge.getTarget()); } return children.build(); }
From source file:fr.inria.eventcloud.runners.EachPublishSubscribeAlgorithm.java
private static List<Runner> extractAndCreateRunners(Class<?> klass) throws InitializationError { Builder<Runner> runners = new ImmutableList.Builder<Runner>(); for (PublishSubscribeAlgorithm algo : PublishSubscribeAlgorithm.values()) { runners.add(new PublishSubscribeAlgorithmRunner(klass, algo)); }//from w w w. j av a 2 s . c o m return runners.build(); }
From source file:com.google.template.soy.jssrc.dsl.Concatenation.java
static Concatenation create(Iterable<? extends Expression> parts) { ImmutableList.Builder<Statement> initialStatements = ImmutableList.builder(); ImmutableList.Builder<Expression> partsBuilder = ImmutableList.builder(); for (Expression part : parts) { initialStatements.addAll(part.initialStatements()); if (part instanceof Concatenation) { partsBuilder.addAll(((Concatenation) part).parts()); } else if (part instanceof BinaryOperation) { BinaryOperation binaryOp = (BinaryOperation) part; if (binaryOp.operator().equals(Operator.PLUS.getTokenString())) { partsBuilder.add(binaryOp.arg1()); partsBuilder.add(binaryOp.arg2()); } else { partsBuilder.add(part);/* www. ja v a 2 s . com*/ } } else { partsBuilder.add(part); } } return new AutoValue_Concatenation(initialStatements.build(), partsBuilder.build()); }
From source file:com.facebook.buck.apple.GroupedSources.java
private static void addSourcePathsToBuilder(ImmutableList.Builder<SourcePath> sourcePathsBuilder, GroupedSource groupedSource) {//www. j a va 2 s. com switch (groupedSource.getType()) { case SOURCE_PATH: sourcePathsBuilder.add(groupedSource.getSourcePath()); break; case SOURCE_GROUP: for (GroupedSource sourceGroupEntry : groupedSource.getSourceGroup()) { addSourcePathsToBuilder(sourcePathsBuilder, sourceGroupEntry); } break; default: throw new IllegalStateException("Unhandled type: " + groupedSource.getType()); } }
From source file:be.i8c.codequality.sonar.plugins.sag.webmethods.flow.check.CheckList.java
public static List<Class> getChecks() { Builder<Class> builder = new ImmutableList.Builder<Class>(); builder.addAll(getNodeChecks());/* ww w . ja v a 2 s. co m*/ builder.addAll(getTopLevelChecks()); builder.addAll(getOtherChecks()); if (logger.isDebugEnabled()) { logger.debug("getChecks(): classes=" + toString(builder.build())); } return builder.build(); }
From source file:org.thelq.pircbotx.keepalive.JenkinsKeepAlive.java
public static void create() { Preconditions.checkState(!created, "Already created"); created = true;// w ww. ja v a 2 s .c o m ImmutableList.Builder<String> jenkinsBotsBuilder = ImmutableList.builder(); for (int i = 1;; i++) { String value = ""; if (value == null) break; jenkinsBotsBuilder.add(value); } ImmutableList<String> jenkinsBots = jenkinsBotsBuilder.build(); if (jenkinsBots.size() == 0) throw new RuntimeException("No jenkins bots setup!"); log.info("Created jenkins keep alive for " + jenkinsBots.toString()); KeepAlive.getExecutor().scheduleAtFixedRate(new JenkinsRunner(jenkinsBots), 0, 15, TimeUnit.MINUTES); }
From source file:org.commoncrawl.util.HDFSUtils.java
public static List<String> textFileToList(FileSystem fs, Path path) throws IOException { ImmutableList.Builder<String> builder = new ImmutableList.Builder<String>(); BufferedReader reader = new BufferedReader(new InputStreamReader(fs.open(path), Charset.forName("UTF-8"))); try {// w ww .j a v a2s.c om String line; while ((line = reader.readLine()) != null) { if (line.length() != 0 && !line.startsWith("#")) builder.add(line); } } finally { reader.close(); } return builder.build(); }