Example usage for com.google.common.collect ImmutableList.Builder add

List of usage examples for com.google.common.collect ImmutableList.Builder add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:io.prestosql.cli.TableNameCompleter.java

private static List<String> filterResults(List<String> values, String prefix) {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (String value : values) {
        if (value.startsWith(prefix)) {
            builder.add(value);
        }//from ww w.j  a  v a  2  s  .  co m
    }
    return builder.build();
}

From source file:de.se_rwth.langeditor.util.ResourceLocator.java

public static ImmutableList<Path> assembleModelPath(IProject project) {
    ImmutableList.Builder<Path> builder = ImmutableList.builder();
    for (IClasspathEntry classpathEntry : getModelPathEntries(JavaCore.create(project))) {
        builder.add(classpathEntry.getPath().toFile().toPath());
    }/*from  w  ww  .  j a v  a  2 s  .  c  o  m*/
    return builder.build();
}

From source file:io.prestosql.metadata.InternalTable.java

public static Builder builder(List<ColumnMetadata> columns) {
    ImmutableList.Builder<String> names = ImmutableList.builder();
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    for (ColumnMetadata column : columns) {
        names.add(column.getName());
        types.add(column.getType());/* ww w  . j  ava2 s  .c om*/
    }
    return new Builder(names.build(), types.build());
}

From source file:paperparcel.AdapterRegistry.java

private static ImmutableList<TypeKey> asList(TypeKey... keys) {
    ImmutableList.Builder<TypeKey> builder = ImmutableList.builder();
    for (TypeKey key : keys) {
        builder.add(key);
    }//from   w  w  w.ja  va  2 s  .  c o  m
    return builder.build();
}

From source file:com.google.devtools.build.lib.rules.objc.CompiledResourceFile.java

/**
 * Given a sequence of artifacts corresponding to {@code .strings} files, returns a sequence of
 * the same length of instances of this class. The value returned by {@link #getBundled()} of each
 * instance will be the plist file in binary form.
 *///w  ww . j  a  v  a2 s. c  o m
public static Iterable<CompiledResourceFile> fromStringsFiles(IntermediateArtifacts intermediateArtifacts,
        Iterable<Artifact> strings) {
    ImmutableList.Builder<CompiledResourceFile> result = new ImmutableList.Builder<>();
    for (Artifact originalFile : strings) {
        Artifact binaryFile = intermediateArtifacts.convertedStringsFile(originalFile);
        result.add(new CompiledResourceFile(originalFile,
                new BundleableFile(binaryFile, BundleableFile.bundlePath(originalFile.getExecPath()))));
    }
    return result.build();
}

From source file:org.sonar.java.checks.UtilityClassWithPublicConstructorCheck.java

private static List<MethodTree> getExplicitConstructors(ClassTree classTree) {
    ImmutableList.Builder<MethodTree> builder = ImmutableList.builder();
    for (Tree member : classTree.members()) {
        if (isConstructor(member)) {
            builder.add((MethodTree) member);
        }//from   w  ww.ja v  a  2  s. co  m
    }
    return builder.build();
}

From source file:org.eclipse.buildship.ui.util.gradle.GradleUtils.java

/**
 * Filters away those tests that are a child of a test from the given list of tests.
 *
 * @param testDescriptors the tests to filter
 * @return the filtered tests where no test has as a parent a test that is also part of the result
 *///  w ww .j av  a 2 s.  c  om
public static List<TestOperationDescriptor> filterChildren(List<TestOperationDescriptor> testDescriptors) {
    ImmutableList.Builder<TestOperationDescriptor> withoutChildren = ImmutableList.builder();
    for (TestOperationDescriptor testDescriptor : testDescriptors) {
        if (!isParentSelected(testDescriptor, testDescriptors)) {
            withoutChildren.add(testDescriptor);
        }
    }
    return withoutChildren.build();
}

From source file:com.facebook.buck.json.BuildFilePythonResultDeserializer.java

private static ImmutableList<Map<String, Object>> deserializeObjectList(JsonParser jp) throws IOException {
    JsonToken token = jp.nextToken();//  w  ww  .j a  v a 2  s. c o m
    if (token != JsonToken.START_ARRAY) {
        throw new JsonParseException(jp, "Missing expected START_ARRAY, got: " + token);
    }
    ImmutableList.Builder<Map<String, Object>> result = ImmutableList.builder();
    while ((token = jp.nextToken()) == JsonToken.START_OBJECT) {
        result.add(deserializeObject(jp));
    }
    if (token != JsonToken.END_ARRAY) {
        throw new JsonParseException(jp, "Missing expected END_ARRAY");
    }
    return result.build();
}

From source file:com.facebook.buck.jvm.java.DirectToJarOutputSettingsSerializer.java

public static ImmutableMap<String, Object> serialize(DirectToJarOutputSettings settings) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();

    builder.put(OUTPUT_PATH, settings.getDirectToJarOutputPath().toString());

    ImmutableList.Builder<ImmutableMap<String, Object>> serializedPatterns = ImmutableList.builder();
    for (Pattern pattern : settings.getClassesToRemoveFromJar()) {
        serializedPatterns.add(ImmutableMap.<String, Object>of(CLASSES_TO_REMOVE_PATTERN, pattern.pattern(),
                CLASSES_TO_REMOVE_PATTERN_FLAGS, pattern.flags()));
    }//from  w  w w .  ja v  a2  s. co  m
    builder.put(CLASSES_TO_REMOVE, serializedPatterns.build());

    ImmutableList.Builder<String> serializedEntries = ImmutableList.builder();
    for (Path entry : settings.getEntriesToJar()) {
        serializedEntries.add(entry.toString());
    }
    builder.put(ENTRIES, serializedEntries.build());

    if (settings.getMainClass().isPresent()) {
        builder.put(MAIN_CLASS, settings.getMainClass().get());
    }

    if (settings.getManifestFile().isPresent()) {
        builder.put(MANIFEST_FILE, settings.getManifestFile().get().toString());
    }

    return builder.build();
}

From source file:org.quackbot.hooks.loaders.JavaHookLoader.java

public static ImmutableList<Command> loadCommands(CommandManager commandManager, Object command) {
    checkNotNull(commandManager, "Must specify command manager");
    checkNotNull(command, "Must specify command object");

    //Find any command annotations
    ImmutableList.Builder<Command> addedCommands = ImmutableList.builder();
    for (Method curMethod : command.getClass().getMethods()) {
        JavaCommand commandAnnotation = curMethod.getAnnotation(JavaCommand.class);
        if (commandAnnotation == null)
            continue;

        //Parse arguments first
        ImmutableList.Builder<JavaMethodArgument> arguments = ImmutableList.builder();
        for (JavaArgument curArgument : commandAnnotation.arguments())
            arguments.add(new JavaMethodArgument(curArgument.name(), curArgument.argumentHelp(),
                    curArgument.required()));

        //Build and add command to hookManager
        String minimumLevel = commandAnnotation.minimumLevel();
        if (commandManager.isValidAdminLevel(minimumLevel))
            throw new RuntimeException("Unknown level " + minimumLevel);
        JavaMethodCommand methodCommand = new JavaMethodCommand(commandAnnotation.name(),
                commandAnnotation.help(), minimumLevel, arguments.build(), command, curMethod);
        commandManager.addCommand(methodCommand);
        addedCommands.add(methodCommand);
    }/*from   w  w w.  j a  v  a  2  s  . c o  m*/
    return addedCommands.build();
}