List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:com.qubole.presto.kinesis.KinesisTableDescriptionSupplier.java
private static List<Path> listFiles(Path dir) { if ((dir != null) && Files.isDirectory(dir)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { ImmutableList.Builder<Path> builder = ImmutableList.builder(); for (Path file : stream) { builder.add(file); }/* www . java 2 s . co m*/ return builder.build(); } catch (IOException | DirectoryIteratorException x) { log.warn(x, "Warning."); throw Throwables.propagate(x); } } return ImmutableList.of(); }
From source file:org.jmingo.parser.xml.dom.DocumentBuilderFactoryCreator.java
/** * Create list of {@link Source} objects. * * @param xsdSchemaPaths paths to some schemas * @return list of {@link Source}// w ww . j a v a 2s .c om */ private static List<Source> createSchemaSources(Set<String> xsdSchemaPaths) { if (CollectionUtils.isEmpty(xsdSchemaPaths)) { return ImmutableList.of(); } ImmutableList.Builder<Source> sourceBuilder = ImmutableList.<Source>builder(); for (String xsdSchemaPath : xsdSchemaPaths) { sourceBuilder.add(createSchemaSource(xsdSchemaPath)); } return sourceBuilder.build(); }
From source file:com.google.devtools.build.lib.query2.SkyQueryUtils.java
/** * Gets a path from {@code from} to {@code to}, walking the graph revealed by {@code getFwdDeps}. * * <p>In case the type {@link T} does not implement equality, {@code label} will be used to map * elements of type {@link T} to elements of type {@link L} which does implement equality. {@code * label} should be an injective function. For instance, if {@link T} is of type {@link Target} * then {@link L} could be of type {@link Label} and {@code label} could be {@link * Target::getLabel}./* w w w . j a va2s .co m*/ * * <p>Implemented with a breadth-first search. */ static <T, L> ImmutableList<T> getNodesOnPath(T from, T to, GetFwdDeps<T> getFwdDeps, Function<T, L> label) throws InterruptedException { // Tree of nodes visited so far. Map<L, L> nodeToParent = new HashMap<>(); Map<L, T> labelToTarget = new HashMap<>(); // Contains all nodes left to visit in a (LIFO) stack. Deque<T> toVisit = new ArrayDeque<>(); toVisit.add(from); nodeToParent.put(label.apply(from), null); labelToTarget.put(label.apply(from), from); while (!toVisit.isEmpty()) { T current = toVisit.removeFirst(); if (label.apply(to).equals(label.apply(current))) { List<L> labelPath = Digraph.getPathToTreeNode(nodeToParent, label.apply(to)); ImmutableList.Builder<T> targetPathBuilder = ImmutableList.builder(); for (L item : labelPath) { targetPathBuilder.add(Preconditions.checkNotNull(labelToTarget.get(item), item)); } return targetPathBuilder.build(); } for (T dep : getFwdDeps.getFwdDeps(ImmutableList.of(current))) { L depLabel = label.apply(dep); if (!nodeToParent.containsKey(depLabel)) { nodeToParent.put(depLabel, label.apply(current)); labelToTarget.put(depLabel, dep); toVisit.addFirst(dep); } } } // Note that the only current caller of this method checks first to see if there is a path // before calling this method. It is not clear what the return value should be here. return null; }
From source file:com.google.devtools.build.xcode.xcodegen.testing.PbxTypes.java
/** * Extracts the list of PBX references {@code phase} depends on through * {@link PBXFrameworksBuildPhase#getFiles()}. *//*www.ja va 2s. com*/ public static ImmutableList<PBXReference> pbxFileReferences(PBXFrameworksBuildPhase phase) { ImmutableList.Builder<PBXReference> phaseFileReferences = ImmutableList.builder(); for (PBXBuildFile buildFile : phase.getFiles()) { phaseFileReferences.add(buildFile.getFileRef()); } return phaseFileReferences.build(); }
From source file:org.apache.beam.runners.dataflow.worker.Filepatterns.java
/** * Expands the filepattern containing an {@code @N} wildcard. * * <p>Returns N filenames with the wildcard replaced with a string of the form {@code * 0000i-of-0000N}. For example, for "gs://bucket/file@2.ism", returns an iterable of two elements * "gs://bucket/file-00000-of-00002.ism" and "gs://bucket/file-00001-of-00002.ism". * * <p>The sequence number and N are formatted with the same number of digits (prepended by zeros). * with at least 5 digits. N must be smaller than 1 billion. * * <p>If the filepattern contains no wildcards, returns the filepattern unchanged. * * @throws IllegalArgumentException if more than one wildcard is detected. *//* ww w .j a va 2 s. c o m*/ public static Iterable<String> expandAtNFilepattern(String filepattern) { ImmutableList.Builder<String> builder = ImmutableList.builder(); Matcher match = AT_N_SPEC.matcher(filepattern); if (!match.find()) { builder.add(filepattern); } else { int numShards = Integer.parseInt(match.group("N")); String formatString = "-%0" + getShardWidth(numShards, filepattern) + "d-of-%05d"; for (int i = 0; i < numShards; ++i) { builder.add(AT_N_SPEC.matcher(filepattern).replaceAll(String.format(formatString, i, numShards))); } if (match.find()) { throw new IllegalArgumentException( "More than one @N wildcard found in filepattern: " + filepattern); } } return builder.build(); }
From source file:com.google.errorprone.analysis.ErrorProneTopLevelAnalysis.java
/** * Returns a {@code TopLevelAnalysis} using the specified checkers at their default maturity * level./*from ww w .ja v a 2 s . c o m*/ */ public static TopLevelAnalysis create(Iterable<? extends BugChecker> checkers) { ImmutableList.Builder<TopLevelAnalysis> analyses = ImmutableList.builder(); for (BugChecker checker : checkers) { analyses.add(create(checker, checker.maturity())); } return SumTopLevelAnalysis.create(analyses.build()); }
From source file:com.google.errorprone.analysis.ErrorProneTopLevelAnalysis.java
/** * Returns a {@code TopLevelAnalysis} using the specified checkers at MATURE maturity * level.// w w w . j a v a 2s . c o m */ public static TopLevelAnalysis createMature(Iterable<? extends BugChecker> checkers) { ImmutableList.Builder<TopLevelAnalysis> analyses = ImmutableList.builder(); for (BugChecker checker : checkers) { analyses.add(create(checker, MaturityLevel.MATURE)); } return SumTopLevelAnalysis.create(analyses.build()); }
From source file:com.torodb.torod.core.subdocument.values.TwelveBytesValue.java
public static TwelveBytesValue parse(String string) { int len = string.length(); ImmutableList.Builder builder = ImmutableList.builder(); for (int i = 0; i < len; i += 2) { builder.add((byte) (Character.digit(string.charAt(i), 16) * 16 + Character.digit(string.charAt(i + 1), 16))); }/*from w ww . java 2 s .co m*/ return new TwelveBytesValue(builder.build()); }
From source file:com.facebook.buck.jvm.java.PrebuiltJarDescription.java
@VisibleForTesting static BuildRule createGwtModule(BuildRuleParams params, SourcePathResolver resolver, Arg arg) { // Because a PrebuiltJar rarely requires any building whatsoever (it could if the source_jar // is a BuildTargetSourcePath), we make the PrebuiltJar a dependency of the GWT module. If this // becomes a performance issue in practice, then we will explore reducing the dependencies of // the GWT module. final SourcePath input; if (arg.gwtJar.isPresent()) { input = arg.gwtJar.get();// w ww . j av a2s . c o m } else if (arg.sourceJar.isPresent()) { input = arg.sourceJar.get(); } else { input = arg.binaryJar; } class ExistingOuputs extends AbstractBuildRuleWithResolver { @AddToRuleKey private final SourcePath source; private final Path output; protected ExistingOuputs(BuildRuleParams params, SourcePathResolver resolver, SourcePath source) { super(params, resolver); this.source = source; BuildTarget target = params.getBuildTarget(); this.output = BuildTargets.getGenPath(getProjectFilesystem(), target, String.format("%s/%%s-gwt.jar", target.getShortName())); } @Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { buildableContext.recordArtifact(getPathToOutput()); ImmutableList.Builder<Step> steps = ImmutableList.builder(); steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), output.getParent())); steps.add(CopyStep.forFile(getProjectFilesystem(), getResolver().getAbsolutePath(source), output)); return steps.build(); } @Override public Path getPathToOutput() { return output; } } return new ExistingOuputs(params, resolver, input); }
From source file:com.facebook.presto.operator.window.AggregateWindowFunction.java
private static List<Integer> createArgs(InternalAggregationFunction function) { ImmutableList.Builder<Integer> list = ImmutableList.builder(); for (int i = 0; i < function.getParameterTypes().size(); i++) { list.add(i); }/*from ww w.j a v a 2 s.co m*/ return list.build(); }