Example usage for com.google.common.collect ImmutableList builder

List of usage examples for com.google.common.collect ImmutableList builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList builder.

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.infobip.jira.IssueKey.java

/**
 * Generates {@link IssueKey IssueKeys} from {@link Commit#getMessage()}  changesets message}.
 *
 * @param changeset containing message with Jira issue key
 *
 * @return all {@link IssueKey IssueKeys} that could be extracted from
 *///from w ww  .  j av a  2  s .  c  o m
public static Iterable<IssueKey> of(Commit changeset) {

    Matcher matcher = pattern.matcher(changeset.getMessage());

    ImmutableList.Builder<IssueKey> builder = ImmutableList.builder();

    while (matcher.find()) {
        builder.add(new IssueKey(new ProjectKey(matcher.group(1)), new IssueId(matcher.group(2))));
    }

    return builder.build();
}

From source file:com.google.devtools.build.xcode.xcodegen.SourceFile.java

/**
 * Returns information on all source files in a target. In particular, this includes:
 * <ul>/*  www.j  a v  a 2 s . c o  m*/
 *   <li>arc-compiled source files
 *   <li>non-arc-compiled source files
 *   <li>support files, such as BUILD and header files
 *   <li>Info.plist file
 * </ul>
 */
public static Iterable<SourceFile> allSourceFiles(FileSystem fileSystem, TargetControl control) {
    ImmutableList.Builder<SourceFile> result = new ImmutableList.Builder<>();
    for (Path plainSource : RelativePaths.fromStrings(fileSystem, control.getSourceFileList())) {
        result.add(new SourceFile(BuildType.BUILD, plainSource));
    }
    for (Path nonArcSource : RelativePaths.fromStrings(fileSystem, control.getNonArcSourceFileList())) {
        result.add(new SourceFile(BuildType.NON_ARC_BUILD, nonArcSource));
    }
    for (Path supportSource : RelativePaths.fromStrings(fileSystem, control.getSupportFileList())) {
        result.add(new SourceFile(BuildType.NO_BUILD, supportSource));
    }
    if (control.hasInfoplist()) {
        result.add(new SourceFile(BuildType.NO_BUILD,
                RelativePaths.fromString(fileSystem, control.getInfoplist())));
    }
    return result.build();
}

From source file:com.google.devtools.build.lib.skyframe.AbstractFileSymlinkExceptionUniquenessValue.java

private static ImmutableList<RootedPath> canonicalize(ImmutableList<RootedPath> cycle) {
    int minPos = 0;
    String minString = cycle.get(0).toString();
    for (int i = 1; i < cycle.size(); i++) {
        String candidateString = cycle.get(i).toString();
        if (candidateString.compareTo(minString) < 0) {
            minPos = i;// w  w w  .  ja v a2 s  .c  om
            minString = candidateString;
        }
    }
    ImmutableList.Builder<RootedPath> builder = ImmutableList.builder();
    for (int i = 0; i < cycle.size(); i++) {
        int pos = (minPos + i) % cycle.size();
        builder.add(cycle.get(pos));
    }
    return builder.build();
}

From source file:org.geogit.api.RevFeatureBuilder.java

/**
 * Constructs a new {@link RevFeature} from the provided {@link Feature}.
 * /*  w  ww  .  ja  v  a2s .c om*/
 * @param feature the feature to build from
 * @return the newly constructed RevFeature
 */
public RevFeature build(Feature feature) {
    if (feature == null) {
        throw new IllegalStateException("No feature set");
    }

    Collection<Property> props = feature.getProperties();

    ImmutableList.Builder<Optional<Object>> valuesBuilder = new ImmutableList.Builder<Optional<Object>>();

    for (Property prop : props) {
        valuesBuilder.add(Optional.fromNullable(prop.getValue()));
    }

    return RevFeature.build(valuesBuilder.build());
}

From source file:com.squareup.wire.schema.Extensions.java

static ImmutableList<ExtensionsElement> toElements(ImmutableList<Extensions> extensions) {
    ImmutableList.Builder<ExtensionsElement> elements = new ImmutableList.Builder<>();
    for (Extensions extension : extensions) {
        elements.add(ExtensionsElement.create(extension.location, extension.start, extension.end,
                extension.documentation));
    }/*from  www  . j  a  v  a  2s.c o m*/
    return elements.build();
}

From source file:com.freiheit.fuava.simplebatch.fsjobs.importer.FileMover.java

public Iterable<File> moveFiles(final Iterable<File> toMove, final String destination)
        throws FailedToMoveFileException {
    final ImmutableList.Builder<File> builder = ImmutableList.<File>builder();
    for (final File file : toMove) {
        builder.add(moveFile(file, destination));
    }//from ww w.  j a va2  s .  com
    return builder.build();
}

From source file:com.b2international.commons.http.AcceptHeader.java

private static <T> List<T> parse(StringReader input, Function<String, T> converterFunction) throws IOException {
    final ImmutableList.Builder<AcceptHeader<T>> resultBuilder = ImmutableList.builder();

    do {//from w  w w. j a  v a  2s.co  m
        String token = HttpParser.readToken(input);
        if (token == null) {
            HttpParser.skipUntil(input, 0, ',');
            continue;
        }

        if (token.length() == 0) {
            // No more data to read
            break;
        }

        // See if a quality has been provided
        double quality = 1;
        SkipResult lookForSemiColon = HttpParser.skipConstant(input, ";");
        if (lookForSemiColon == SkipResult.FOUND) {
            quality = HttpParser.readWeight(input, ',');
        }

        if (quality > 0) {
            resultBuilder.add(new AcceptHeader<T>(converterFunction.apply(token), quality));
        }
    } while (true);

    // Stable sort ensures that values with the same quality are not reordered
    final List<AcceptHeader<T>> sortedResults = Ordering.natural().reverse().sortedCopy(resultBuilder.build());

    return FluentIterable.from(sortedResults).transform(new Function<AcceptHeader<T>, T>() {
        @Override
        public T apply(AcceptHeader<T> input) {
            return input.getValue();
        }
    }).toList();
}

From source file:com.teradata.tpcds.distribution.CategoriesDistribution.java

private static CategoriesDistribution buildCategoriesDistribution() {
    ImmutableList.Builder<String> namesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Integer> hasSizesBuilder = ImmutableList.builder();
    WeightsBuilder weightsBuilder = new WeightsBuilder();

    Iterator<List<String>> iterator = getDistributionIterator(VALUES_AND_WEIGHTS_FILENAME);
    while (iterator.hasNext()) {
        List<String> fields = iterator.next();
        checkState(fields.size() == 2, "Expected line to contain 2 parts but it contains %d: %s", fields.size(),
                fields);/*from   ww  w . ja  v  a 2s.  c o m*/

        List<String> values = getListFromCommaSeparatedValues(fields.get(0));
        checkState(values.size() == 3, "Expected line to contain 3 values, but it contained %d, %s",
                values.size(), values);

        namesBuilder.add(values.get(0));
        // we don't add the class distribution names because they are unused
        hasSizesBuilder.add(parseInt(values.get(2)));

        List<String> weights = getListFromCommaSeparatedValues(fields.get(1));
        checkState(weights.size() == NUM_WEIGHT_FIELDS,
                "Expected line to contain %d weights, but it contained %d, %s", NUM_WEIGHT_FIELDS,
                weights.size(), values);
        weightsBuilder.computeAndAddNextWeight(parseInt(weights.get(0)));
    }

    return new CategoriesDistribution(namesBuilder.build(), hasSizesBuilder.build(), weightsBuilder.build());
}

From source file:org.apache.james.transport.util.MailAddressUtils.java

private static List<MailAddress> from(List<InternetAddress> internetAddresses) throws AddressException {
    ImmutableList.Builder<MailAddress> builder = ImmutableList.builder();
    for (InternetAddress internetAddress : internetAddresses) {
        builder.add(new MailAddress(internetAddress));
    }/*  w w  w . ja v a 2s . c o  m*/
    return builder.build();
}

From source file:org.apache.calcite.util.CompositeMap.java

private static <E> ImmutableList<E> list(E e, E[] es) {
    ImmutableList.Builder<E> builder = ImmutableList.builder();
    builder.add(e);//from ww  w.  j  a  va  2  s . c o m
    for (E map : es) {
        builder.add(map);
    }
    return builder.build();
}