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.fatboyindustrial.omnium.ImmutableCollectors.java

/**
 * Gets a collector that returns an {@link ImmutableList}.
 * @param <T> The type of element in the list.
 * @return The collector.//from  www .  j av a 2 s .  c o m
 */
public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> toImmutableList() {
    return Collector.of(ImmutableList::builder, (list, entry) -> list.add(entry),
            (builder1, builder2) -> builder1.addAll(builder2.build()), ImmutableList.Builder::build);
}

From source file:com.facebook.buck.features.filebundler.ZipFileExtractor.java

/**
 * Given a list of archive files, generates a list of steps to extract those files in a given
 * location./*from  w  w  w .j  ava2 s  .  c  o m*/
 *
 * @param destinationDir location for extracted files.
 * @param entriesToExclude entries that match this matcher will not be extracted.
 */
public static ImmutableList<Step> extractZipFiles(BuildTarget target, ProjectFilesystem filesystem,
        Path destinationDir, Iterable<SourcePath> toExtract, SourcePathResolver pathResolver,
        PatternsMatcher entriesToExclude) {

    ImmutableList.Builder<Step> steps = ImmutableList.builder();

    Map<Path, Path> relativeMap = createRelativeMap(target.getBasePath(), filesystem, pathResolver, toExtract);

    for (Map.Entry<Path, Path> pathEntry : relativeMap.entrySet()) {
        Path relativePath = pathEntry.getKey();
        Path absolutePath = Objects.requireNonNull(pathEntry.getValue());
        Path destination = destinationDir.resolve(relativePath);

        steps.add(new UnzipStep(filesystem, absolutePath, destination.getParent(), Optional.empty(),
                entriesToExclude));
    }
    return steps.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.
 *///from  w w w .  java  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:org.attribyte.api.http.NamedValues.java

/**
 * Copies values from a collection to an immutable list.
 * Empty or <code>null</code> values are ignored.
 * @param values The input values./* w  ww  . j  a v  a2 s.  com*/
 * @return The internal values.
 */
static final ImmutableList<String> copyValues(final Collection<String> values) {
    if (values == null) {
        return ImmutableList.of();
    } else {
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        for (final String value : values) {
            if (!Strings.isNullOrEmpty(value)) {
                builder.add(value);
            }
        }
        return builder.build();
    }
}

From source file:com.spectralogic.ds3autogen.Ds3SpecConverter.java

/**
 * Converts the contract names of all response codes, optional
 * params and required params to the SDK naming scheme, as defined
 * within the NameMapper/*  w  w  w  .j av a2  s . c om*/
 */
protected static ImmutableList<Ds3Request> convertRequests(final ImmutableList<Ds3Request> requests,
        final NameMapper nameMapper) {
    if (isEmpty(requests)) {
        return ImmutableList.of();
    }
    final ImmutableList.Builder<Ds3Request> builder = ImmutableList.builder();

    for (final Ds3Request request : requests) {
        final Ds3Request convertedRequest = new Ds3Request(
                toSdkName(request.getName(), request.getClassification(), nameMapper), request.getHttpVerb(),
                request.getClassification(), request.getBucketRequirement(), request.getObjectRequirement(),
                request.getAction(), request.getResource(), request.getResourceType(), request.getOperation(),
                request.includeIdInPath(), convertAllResponseCodes(request.getDs3ResponseCodes(), nameMapper),
                convertAllParams(request.getOptionalQueryParams(), nameMapper),
                convertAllParams(request.getRequiredQueryParams(), nameMapper));
        builder.add(convertedRequest);
    }

    return builder.build();
}

From source file:org.apache.aurora.scheduler.sla.SlaTestUtil.java

private static List<ITaskEvent> makeEvents(Map<Long, ScheduleStatus> events) {
    ImmutableList.Builder<ITaskEvent> taskEvents = ImmutableList.builder();
    for (Map.Entry<Long, ScheduleStatus> entry : events.entrySet()) {
        taskEvents.add(ITaskEvent.build(new TaskEvent(entry.getKey(), entry.getValue())));
    }/* w w w .  j  a v a 2s  .  c o  m*/

    return taskEvents.build();
}

From source file:org.sonar.plugins.dependencycheck.DependencyCheckPlugin.java

/**
 * Returns the Properties and Class files needed by Sonar {@inheritDoc}
 *///from  w  ww  .  jav  a  2 s.  c  om
public List<?> getExtensions() {
    String category = "Dependency Check";
    String subGlobal = "Global Dependencies";
    String subProject = "Project Dependencies";
    String subLicense = "Licenses";
    String subScope = "Scope";
    ImmutableList.Builder<Object> extensions = ImmutableList.builder();

    List<PropertyFieldDefinition> libraryField = new ArrayList<PropertyFieldDefinition>();
    List<PropertyFieldDefinition> licenseField = new ArrayList<PropertyFieldDefinition>();

    // Library
    libraryField.add(PropertyFieldDefinition.build(DependencyCheckMetrics.LIBRARY_KEY_PROPERTY).name("Name")
            .description("Name of the allowed libraries in the form \"groupID:artifactID\"").build());
    libraryField.add(PropertyFieldDefinition.build(DependencyCheckMetrics.LIBRARY_VERSION_PROPERTY)
            .name("Version Range")
            .description("Version of the allowed libraries in the Maven Syntax - see: "
                    + "http://maven.apache.org/enforcer/enforcer-rules/versionRanges.html "
                    + "for further information! " + "Leaving this empty will allow every version.")
            .build());
    libraryField
            .add(PropertyFieldDefinition.build(DependencyCheckMetrics.LIBRARY_LICENSE_PROPERTY).name("License")
                    .description(
                            "Enter the Name (either full name or shortage) of the License of the Dependency.")
                    .build());

    // Licenses
    licenseField.add(PropertyFieldDefinition.build(DependencyCheckMetrics.LICENSE_ID_PROPERTY).name("ID")
            .description("Shortage of the License title (i.e. GPL, LGPL)").build());
    licenseField.add(PropertyFieldDefinition.build(DependencyCheckMetrics.LICENSE_TITLE_PROPERTY).name("Title")
            .description("Title of the allowed license").build());
    licenseField.add(PropertyFieldDefinition.build(DependencyCheckMetrics.LICENSE_DESCRIPTION_PROPERTY)
            .name("Description").description("Description of the license").type(PropertyType.TEXT).build());
    licenseField.add(PropertyFieldDefinition.build(DependencyCheckMetrics.LICENSE_URL_PROPERTY).name("URL")
            .description("URL for further description of the License").build());
    licenseField.add(
            PropertyFieldDefinition.build(DependencyCheckMetrics.LICENSE_COMMERCIAL_PROPERTY).name("Commercial")
                    .description("Enter whether the License is commercial").type(PropertyType.BOOLEAN).build());
    licenseField.add(PropertyFieldDefinition.build(DependencyCheckMetrics.LICENSE_SOURCETYPE_PROPERTY)
            .name("Source Type").description("The type of allowed source code")
            .type(PropertyType.SINGLE_SELECT_LIST).options(SourceType.getSourceTypes()).build());

    extensions.add(PropertyDefinition.builder(DependencyCheckMetrics.LIBRARY_GLOBAL_PROPERTY).category(category)
            .subCategory(subGlobal).name("Library")
            .description("Insert information about the allowed Libraries").type(PropertyType.PROPERTY_SET)
            .fields(libraryField).build());

    extensions.add(PropertyDefinition.builder(DependencyCheckMetrics.LIBRARY_PROJECT_PROPERTY)
            .category(category).subCategory(subProject).name("Library")
            .description("Insert information about the allowed Libraries").type(PropertyType.PROPERTY_SET)
            .fields(libraryField).onQualifiers(Qualifiers.PROJECT).build());

    extensions.add(PropertyDefinition.builder(DependencyCheckMetrics.LICENSE_PROPERTY).category(category)
            .subCategory(subLicense).name("License")
            .description("Insert information about the allowed Licenses").type(PropertyType.PROPERTY_SET)
            .fields(licenseField).build());

    extensions.add(PropertyDefinition.builder(DependencyCheckMetrics.SCOPE_COMPILE_PROPERTY).category(category)
            .subCategory(subScope).name("Compile")
            .description("Whether dependencies of the scope compile should be checked.")
            .type(PropertyType.BOOLEAN).onQualifiers(Qualifiers.PROJECT).build());

    extensions.add(PropertyDefinition.builder(DependencyCheckMetrics.SCOPE_RUNTIME_PROPERTY).category(category)
            .subCategory(subScope).name("Runtime")
            .description("Whether dependencies of the scope runtime should be checked.")
            .type(PropertyType.BOOLEAN).onQualifiers(Qualifiers.PROJECT).build());

    extensions.add(PropertyDefinition.builder(DependencyCheckMetrics.SCOPE_TEST_PROPERTY).category(category)
            .subCategory(subScope).name("Test")
            .description("Whether dependencies of the scope test should be checked.").type(PropertyType.BOOLEAN)
            .onQualifiers(Qualifiers.PROJECT).build());

    extensions.add(PropertyDefinition.builder(DependencyCheckMetrics.SCOPE_PROVIDED_PROPERTY).category(category)
            .subCategory(subScope).name("Provided")
            .description("Whether dependencies of the scope provided should be checked.")
            .type(PropertyType.BOOLEAN).onQualifiers(Qualifiers.PROJECT).build());

    extensions.add(DependencyCheckRuleRepository.class);
    extensions.add(DependencyCheckMetrics.class);
    extensions.add(DependencyCheckDecorator.class);
    extensions.add(DependencyCheckWidget.class);

    return extensions.build();
}

From source file:com.facebook.presto.sql.gen.DefaultFunctionBinder.java

public static FunctionBinding bindConstantArguments(long bindingId, String name,
        ByteCodeNode getSessionByteCode, List<TypedByteCodeNode> arguments, MethodHandle methodHandle,
        boolean nullable) {
    Builder<TypedByteCodeNode> unboundArguments = ImmutableList.builder();

    int argIndex = 0;

    // bind session
    if (methodHandle.type().parameterCount() > 0 && methodHandle.type().parameterType(0) == Session.class) {
        unboundArguments.add(TypedByteCodeNode.typedByteCodeNode(getSessionByteCode, Session.class));
        argIndex++;//from   www  . j a va 2  s  .  c om
    }

    for (TypedByteCodeNode argument : arguments) {
        ByteCodeNode node = argument.getNode();
        if (node instanceof Constant) {
            Object value = ((Constant) node).getValue();
            if (argument.getType() == boolean.class) {
                checkArgument(value instanceof Integer, "boolean should be represented as an integer");
                value = (((Integer) value) != 0);
            }
            // bind constant argument
            methodHandle = MethodHandles.insertArguments(methodHandle, argIndex, value);
            // we bound an argument so don't increment the argIndex
        } else {
            unboundArguments.add(argument);
            argIndex++;
        }
    }

    CallSite callSite = new ConstantCallSite(methodHandle);
    return new FunctionBinding(bindingId, name, callSite, unboundArguments.build(), nullable);
}

From source file:nl.qbusict.cupboard.processor.internal.CupboardAnalysis.java

public CupboardDescriptor analyze(ASTType value) {

    ImmutableList.Builder<FieldColumn> columns = ImmutableList.builder();
    FieldColumn idColumn = null;//ww  w. j  a  v  a2  s .  co  m

    for (ASTType hierarchy = value; hierarchy != null; hierarchy = hierarchy.getSuperClass()) {
        for (ASTField field : hierarchy.getFields()) {
            String columnName = field.getName();
            if (field.isAnnotated(Column.class)) {
                columnName = field.getAnnotation(Column.class).value();
            }

            FieldColumn fieldColumn = new FieldColumn(hierarchy, field, columnName);
            if (columnName.equals("_id")) {
                idColumn = fieldColumn;
            }
            columns.add(fieldColumn);
        }
    }

    return new CupboardDescriptor(value, idColumn, columns.build());
}

From source file:com.google.errorprone.bugpatterns.testdata.CollectorShouldNotUseStateNegativeCases.java

public void test() {
    Collector.of(ImmutableList::builder, new BiConsumer<ImmutableList.Builder<Object>, Object>() {
        private static final String bob = "bob";

        @Override//ww w.j  av  a 2  s .  com
        public void accept(Builder<Object> objectBuilder, Object o) {
            if (bob.equals("bob")) {
                System.out.println("bob");
            } else {
                objectBuilder.add(o);
            }
        }
    }, (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build);
}